-
Notifications
You must be signed in to change notification settings - Fork 2
267 lines (229 loc) · 8.9 KB
/
cicd.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
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
name: CI/CD
on:
workflow_dispatch:
push:
branches:
- "**"
- "!dependabot/**"
pull_request:
branches:
- "**"
permissions:
contents: read
jobs:
changed-files:
name: Detect Changed Files
runs-on: ubuntu-latest
outputs:
run-ci: ${{ github.event_name == 'workflow_dispatch' || steps.ci-files-changed.outputs.paths_any_modified == 'true' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
github.com:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Maybe one day GitHub will handle this for us using path filters, but for now we need to skip all of the steps that would normally run for non-code changes ourselves.
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
- name: CI Files Changed
id: ci-files-changed
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
with:
files_yaml: |
paths:
- "**"
- "!*.md"
- "!.github/**"
- ".github/workflows/*.yml"
- "!.github/workflows/cd.yml"
ci:
name: CI
runs-on: ubuntu-22.04
needs: changed-files
if: ${{ needs.changed-files.outputs.run-ci == 'true' }}
strategy:
matrix:
docker-context: ["rootless", "default"]
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
disable-sudo: ${{ matrix.docker-context != 'rootless' }}
egress-policy: block
allowed-endpoints: >
auth.docker.io:443
coveralls.io:443
dl-cdn.alpinelinux.org:443
download.docker.com:443
get.docker.com:443
github.com:443
objects.githubusercontent.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
registry.npmjs.org:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Rootless Docker
if: ${{ matrix.docker-context == 'rootless' }}
uses: ScribeMD/rootless-docker@6bd157a512c2fafa4e0243a8aa87d964eb890886 # 0.2.2
- name: Validate Docker Compose Files
run: |
docker compose --file compose.yml config --quiet
docker compose --file compose.watch-build-server.yml config --quiet
- name: Docker Cache
id: docker-cache
uses: ScribeMD/docker-cache@fb28c93772363301b8d0a6072ce850224b73f74e # 0.5.0
with:
key: docker-${{ runner.os }}-${{ hashFiles('./images/node/Dockerfile') }}
- name: NPM Cache
id: npm-cache
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: "~/.npm"
key: npm-${{ runner.os }}-${{ hashFiles('./package-lock.json') }}
- name: Build and Verify
run: |
chmod +x "./npm" "./user-mirror"
./npm -- run clean-verify
- name: Upload Code Coverage
if: ${{ matrix.docker-context == 'rootless' }}
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
- name: Upload Artifacts
if: ${{ matrix.docker-context == 'rootless' }}
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: artifacts
path: build/release/
if-no-files-found: error
release-gate:
name: Release Gate
runs-on: ubuntu-latest
needs: ci
outputs:
verification: ${{ steps.verify.outputs.VERIFY_STATUS }}
if: ${{ github.ref == 'refs/heads/mainline' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: lts/*
- name: Download CI Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: artifacts
path: artifacts
- name: Verify the CI Artifacts
id: verify
run: echo "VERIFY_STATUS=$(node scripts/verifyDeploy.js artifacts/script.user.js artifacts/script.meta.js >/dev/null 2>&1 && echo success || echo failure)" >> "$GITHUB_OUTPUT"
sign:
needs: release-gate
name: Sign
runs-on: ubuntu-22.04
environment: signature
if: ${{ needs.release-gate.outputs.verification == 'success' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: block
allowed-endpoints: >
auth.docker.io:443
dl-cdn.alpinelinux.org:443
download.docker.com:443
get.docker.com:443
github.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Rootless Docker
uses: ScribeMD/rootless-docker@6bd157a512c2fafa4e0243a8aa87d964eb890886 # 0.2.2
- name: Docker Cache
id: docker-cache
uses: ScribeMD/docker-cache@fb28c93772363301b8d0a6072ce850224b73f74e # 0.5.0
with:
key: docker-${{ runner.os }}-${{ hashFiles('./images/node/Dockerfile') }}
- name: Download CI Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: artifacts
path: build/release/
- name: Sign Artifacts
run: |
mkdir -p ~/.minisign
echo '${{ secrets.MINISIGN_PRIVATE_BASE64 }}' | base64 -d > ~/.minisign/minisign.key
chmod +x "./npm" "./user-mirror"
MINISIGN_KEY_PATH='~/.minisign/minisign.key' ./npm -- run sign
rm ~/.minisign/minisign.key
- name: Verify Signatures
run: |
chmod +x "./npm" "./user-mirror"
./npm -- run sign:verify
- name: Upload Signed Artifacts
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: signed-artifacts
path: build/release/
if-no-files-found: error
deploy:
needs: sign
name: Deploy
runs-on: ubuntu-latest
environment: elevated-workflow
permissions:
contents: write # Needed to create a release https://docs.github.com/en/rest/releases/releases#create-a-release
concurrency:
group: deployment
cancel-in-progress: true
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:22
uploads.github.com:443
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ssh-key: ${{ secrets.ELEVATED_WORKFLOW_DEPLOY_KEY }}
- name: Download Signed Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: signed-artifacts
path: artifacts
- name: Extract artifact script version
run: echo "SCRIPT_VERSION=$(grep -oP '// @version \K(.+)' artifacts/script.meta.js)" >> $GITHUB_ENV
- name: Create Release Tag
run: |
git tag "release-$SCRIPT_VERSION";
git push origin tag "release-$SCRIPT_VERSION";
- name: Create release
uses: ncipollo/release-action@cdcc88a9acf3ca41c16c37bb7d21b9ad48560d87 # v1.15.0
with:
artifactErrorsFailBuild: true
artifacts: "artifacts/script.meta.js,artifacts/script.user.js,artifacts/script.user.js.minisig"
body: "Verify artifacts: `minisign -HV -P 'RWQzlcfYwjz4IPiyyUgFiCkqFuQoOfolfw4AWUwCSRBRYNDuaEqqa6h/' -m script.user.js` ([public key](https://raw.githubusercontent.com/AJGranowski/reddit-expanded-community-filter-userscript/mainline/minisign.pub))"
draft: false
generateReleaseNotes: true
makeLatest: true
name: Release ${{ env.SCRIPT_VERSION }}
tag: release-${{ env.SCRIPT_VERSION }}
updateOnlyUnreleased: true