-
Notifications
You must be signed in to change notification settings - Fork 3
165 lines (164 loc) · 6.16 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: CI
on:
push:
pull_request:
release:
types: [published]
workflow_dispatch:
schedule:
- cron: "23 2 12 * *"
jobs:
prepare:
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
create_release: ${{ steps.check_release.outputs.CREATE_RELEASE }}
steps:
- name: Get build version
id: get_version
run: |
echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
echo "Version: ${GITHUB_REF##*/}"
# Releases created via the GitHub webGUI will also create and push a tag.
# Both events will trigger this workflow, so we cancel the run for tags and allow it for releases.
- name: Check if workflow is running for a tagged release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
id: check_release
run: |
URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.VERSION }}"
StatusCode=$(curl -o -I -L -s -w "%{http_code}" -X GET -G $URL)
if [ "$StatusCode" == 200 ]; then
echo "GitHub release already exists: stopping this workflow.\nSee parallel `Release` workflow."
echo "CREATE_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "Tag pushed without release: building and creating a new GitHub release."
echo "CREATE_RELEASE=true" >> $GITHUB_OUTPUT
fi
provision-environment:
needs: [prepare]
# Run workflow proper for: github releases, tag pushes without github release and regular pushes (not tag)
if: github.event_name == 'release' || needs.prepare.outputs.create_release == 'true' || !contains(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: '2'
- name: Install npm dependencies
id: npm_install
run: |
echo 'Installing npm dependencies ...'
rm -fr node-modules
npm ci
- name: 'Tar workspace'
run: tar -cvf workspace.tar .
- uses: actions/upload-artifact@v3
with:
name: workspace
path: workspace.tar
retention-days: 1
lintJS:
needs: [provision-environment]
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v3
with:
name: workspace
- name: 'Untar workspace'
run: tar -xf workspace.tar
- name: Lint Javascript
id: lint_js
run: gulp lintjs
lintSCSS:
needs: [provision-environment]
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v3
with:
name: workspace
path: .
- name: 'Untar workspace'
run: tar -xf workspace.tar
- name: Lint SCSS
id: lint_js
run: gulp lintscss
build:
needs: [prepare, lintJS, lintSCSS]
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v3
with:
name: workspace
- name: 'Untar workspace'
run: tar -xf workspace.tar
- name: Build
run: sh -x ./build.sh ci
env:
THEME_VERSION: ${{ needs.prepare.outputs.version }}
- name: Upload build package
uses: actions/upload-artifact@v3
with:
name: drupal-theme-build-package
path: dist/clarin_bootstrap-${{ needs.prepare.outputs.version }}.tar.gz
publish:
needs: [prepare, build]
if: github.event_name != 'pull_request'
runs-on: ubuntu-22.04
steps:
- name: Get latest commit sha and message
uses: actions/checkout@v3
with:
fetch-depth: '1'
- name: Get build package from build job
uses: actions/download-artifact@v3
with:
name: drupal-theme-build-package
- name: 'Untar build package'
run: tar -xf clarin_bootstrap-${{ needs.prepare.outputs.version }}.tar.gz
- name: Publish to distribution repository
uses: s0/[email protected]
env:
REPO: [email protected]:clarin-eric/clarin-drupal-bootstrap-theme-dist.git
BRANCH: ${{ needs.prepare.outputs.version }}.x
FOLDER: clarin_bootstrap
SSH_PRIVATE_KEY: ${{ secrets.SSH_DEPLOY_DIST_KEY }}
MESSAGE: "Updated from https://github.com/clarin-eric/clarin-drupal-bootstrap-theme/commit/{sha}\nLast commit message:\n{msg}"
SKIP_EMPTY_COMMITS: true
release:
needs: [prepare, publish]
# Run job for github releases and tag pushes (without github release)
if: github.event_name == 'release' || needs.prepare.outputs.create_release == 'true'
runs-on: ubuntu-22.04
steps:
- name: Download build package from build job
uses: actions/download-artifact@v3
with:
name: drupal-theme-build-package
# For github releases -> upload release package to existing release
# For tag pushes without github release -> create a github release with release package
- name: Create prelease for this tag
if: needs.prepare.outputs.create_release == 'true'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.prepare.outputs.version }}
release_name: Release ${{ needs.prepare.outputs.version }}
draft: true
prerelease: true
- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Pseudo-ternary expression: get "upload_url" from the release created above, or from github "release" event when release is pre-created
upload_url: ${{ needs.prepare.outputs.create_release == 'true' && steps.create_release.outputs.upload_url || github.event.release.upload_url }}
asset_path: ./clarin_bootstrap-${{ needs.prepare.outputs.version }}.tar.gz
asset_name: clarin_bootstrap-${{ needs.prepare.outputs.version }}.tar.gz
asset_content_type: application/tar+gzip
- uses: eregon/publish-release@v1
if: needs.prepare.outputs.create_release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}