-
-
Notifications
You must be signed in to change notification settings - Fork 0
272 lines (257 loc) · 9.11 KB
/
Copy pathworkflow.yml
File metadata and controls
272 lines (257 loc) · 9.11 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Build, test, analyze and publish
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
paths-ignore:
- '**/*.md'
- '**/*.png'
workflow_dispatch:
jobs:
# Run linter to ensure new code respect coding rules
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 15
- name: Setup metrics
run: npm ci
- name: Check contributions requirements
run: npm test -- ci.test.js --noStackTrace
- name: Run linter
run: npm run linter
# Build docker image from branch and run tests
build:
name: Build and test
runs-on: ubuntu-latest
needs: [ lint ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Dprint
run: |
curl -fsSL https://dprint.dev/install.sh | sh
echo "$HOME/.dprint/bin" >> $GITHUB_PATH
- name: Format code
run: npm run fmt
- name: Build lowlighter/metrics:${{ github.head_ref || 'master' }}
run: docker build -t lowlighter/metrics:$(echo ${{ github.head_ref || 'master' }} | sed 's/\//-/g') .
- name: Run tests
run: docker run --workdir=/metrics --entrypoint="" lowlighter/metrics:$(echo ${{ github.head_ref || 'master' }} | sed 's/\//-/g') npm test -- metrics.test.js
# Run CodeQL on branch
analyze:
name: Analyze code
runs-on: ubuntu-latest
needs: [ lint ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup CodeQL
uses: github/codeql-action/init@v1
with:
languages: javascript
config-file: ./.github/config/codeql.yml
- name: Analyze code
uses: github/codeql-action/analyze@v1
# Format code
format:
name: Format code
runs-on: ubuntu-latest
needs: [ build, analyze ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Dprint
run: |
curl -fsSL https://dprint.dev/install.sh | sh
echo "$HOME/.dprint/bin" >> $GITHUB_PATH
- name: Checkout master
run: git checkout master
- name: Format code
run: npm run fmt
- name: Publish formatted code
run: |
set +e
git status
git add --update
git commit -m "Auto-format code"
git push
set -e
# Update plugins and template indexes, along with README.md
update-indexes:
name: Publish rebuilt metrics indexes
runs-on: ubuntu-latest
needs: [ build, analyze, format ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 15
- name: Setup metrics
run: npm ci
- name: Publish rebuild metrics indexes
run: npm run index -- publish
# Rebase main branch on master
update-main:
name: Rebase main on master
runs-on: ubuntu-latest
needs: [ update-indexes ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 15
- name: Checkout main
run: git checkout main
- name: Rebase main on master
run: git merge master
- name: Push main
run: git push origin main
# Build docker image from master and publish it to GitHub registry
docker-master:
name: Publish master to GitHub registry
runs-on: ubuntu-latest
needs: [ update-indexes ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to GitHub registry
run: echo ${{ github.token }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build docker image
run: docker build -t ghcr.io/lowlighter/metrics:master .
- name: Publish to GitHub registry
run: docker push ghcr.io/lowlighter/metrics:master
- name: Tag docker image (beta) and publish to GitHub registry
run: |
set +e
METRICS_VERSION=$(cat package.json | grep -Po '(?<="version": ")\d+[.]\d+(?=[.]0-beta")')
METRICS_VERSION_BETA="$METRICS_VERSION-beta"
set -e
echo "Beta version: v$METRICS_VERSION_BETA"
docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:$(echo "v$METRICS_VERSION_BETA")
docker push ghcr.io/lowlighter/metrics:$(echo "v$METRICS_VERSION_BETA")
# Test lowlighter/metrics@master
action-master-test:
name: Test lowlighter/metrics@master
runs-on: ubuntu-latest
needs: [ docker-master ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Run tests
uses: lowlighter/metrics@master
with:
token: MOCKED_TOKEN
plugins_errors_fatal: yes
dryrun: yes
use_mocked_data: yes
verify: yes
use_prebuilt_image: no
# Build docker image from master and publish it to GitHub registry with release tag
docker-release:
name: Publish release to GitHub registry
runs-on: ubuntu-latest
needs: [ action-master-test ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to GitHub registry
run: echo ${{ github.token }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Pull docker image (master)
run: docker pull ghcr.io/lowlighter/metrics:master
- name: Tag docker image (release)
run: docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:$(echo '${{ github.event.head_commit.message }}' | grep -Po 'v\d+[.]\d+')
- name: Publish release to GitHub registry
run: docker push ghcr.io/lowlighter/metrics:$(echo '${{ github.event.head_commit.message }}' | grep -Po 'v\d+[.]\d+')
- name: Tag docker image (latest)
run: docker tag ghcr.io/lowlighter/metrics:master ghcr.io/lowlighter/metrics:latest
- name: Publish latest to GitHub registry
run: docker push ghcr.io/lowlighter/metrics:latest
# Rebase latest branch on master
update-latest:
name: Rebase latest on master
runs-on: ubuntu-latest
needs: [ docker-release ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 15
- name: Setup metrics
run: npm ci
- name: Checkout latest
run: git checkout latest
- name: Rebase latest on master
run: git merge master
- name: Push latest
run: git push origin latest
# Test lowlighter/metrics@latest
action-latest-test:
name: Test lowlighter/metrics@latest
runs-on: ubuntu-latest
needs: [ update-latest ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
steps:
- name: Run tests
uses: lowlighter/metrics@latest
with:
token: MOCKED_TOKEN
plugins_errors_fatal: yes
dryrun: yes
use_mocked_data: yes
verify: yes
# Publish GitHub release
publish-release:
name: Publish release
runs-on: ubuntu-latest
needs: [ action-latest-test ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 15
- name: Setup metrics
run: npm ci
- name: Publish release
run: node .github/release.mjs
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
# Deploy to metrics.lecoq.io
deploy-master:
name: Deploy lowlighter/metrics@master
runs-on: ubuntu-latest
needs: [ action-master-test ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[deploy]')
steps:
- name: Deploy web instance
run: "curl -H 'Content-Type: application/json' --data '${{ secrets.WEB_DEPLOY_TOKEN }}' -X POST https://deploy.metrics.lecoq.io"