-
-
Notifications
You must be signed in to change notification settings - Fork 19
321 lines (274 loc) · 8.68 KB
/
test-and-publish.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
---
name: Test / Publish / Release
concurrency:
group: test-${{ github.head_ref }}
cancel-in-progress: true
on:
push:
branches:
- main
paths:
- VERSION
pull_request:
branches:
- main
workflow_dispatch:
jobs:
finalize:
name: Finalize
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Get the version
id: get_version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT
- name: Update version references
run: make update-version-refs
- name: Ensure CHANGELOG exists for version
run: |
if [ ! -f CHANGELOG/v${{ steps.get_version.outputs.VERSION }}.md ]; then
echo "CHANGELOG/v${{ steps.get_version.outputs.VERSION }}.md does not exist"
exit 1
fi
- name: Check for changes
id: changes
run: |
set -xuo pipefail # we intentionally do not use -e here, as rc=1 means we have changes
git diff
echo "CHANGED=$(git ls-files -m | wc -l | xargs)" >> $GITHUB_OUTPUT
- name: Commit changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git diff --exit-code || git commit -m "Finalize v${{ steps.get_version.outputs.VERSION }}" -a
if: steps.changes.outputs.CHANGED > 0
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.OVERRIDE_TOKEN }}
branch: ${{ github.head_ref }}
if: steps.changes.outputs.CHANGED > 0
- name: Get current SHA
run: git rev-parse HEAD > /tmp/sha
- name: Store SHA as artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
test-iam-floyd:
name: Test iam-floyd
needs: finalize
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Fetch latest SHA
uses: actions/download-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
- name: Store latest SHA as output
id: get_sha
run: echo "SHA=$(cat /tmp/sha/sha)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ steps.get_sha.outputs.SHA }}
- name: Test npm package
run: make install test-typescript
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Update package version
run: |
npm version "$(cat VERSION)" --allow-same-version --no-git-tag-version
grep version package.json
- name: Dry run npm publish
run: make publish
test-cdk-iam-floyd:
name: Test cdk-iam-floyd
needs: finalize
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Fetch latest SHA
uses: actions/download-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
- name: Store latest SHA as output
id: get_sha
run: echo "SHA=$(cat /tmp/sha/sha)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ steps.get_sha.outputs.SHA }}
- name: Build CDK variant
run: |
make install
make cdk
cat package.json
- name: Test npm package
run: |
make package
make test-typescript-cdk
make cdk-test
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Update package version
run: |
npm version "$(cat VERSION)" --allow-same-version --no-git-tag-version
grep version package.json
- name: Dry run npm publish
run: make publish
release:
name: Release
if: |
github.ref == 'refs/heads/main' && (
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
)
needs:
- test-iam-floyd
- test-cdk-iam-floyd
runs-on: ubuntu-latest
steps:
- name: Fetch latest SHA
uses: actions/download-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
- name: Store latest SHA as output
id: get_sha
run: echo "SHA=$(cat /tmp/sha/sha)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ steps.get_sha.outputs.SHA }}
- name: Get the version
id: get_version
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_OUTPUT
- name: Create tag
run: |
git config --local user.email "${{ secrets.RELEASE_MAIL }}"
git config --local user.name "udondan"
git tag -a "v${{ steps.get_version.outputs.VERSION }}" -m "Creates tag v${{ steps.get_version.outputs.VERSION }}"
git push "https://udondan:${{ secrets.OVERRIDE_TOKEN }}@github.com/${{ github.repository }}.git" --tags
touch CHANGELOG/v${{ steps.get_version.outputs.VERSION }}.md
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.OVERRIDE_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.VERSION }}
release_name: v${{ steps.get_version.outputs.VERSION }}
body_path: CHANGELOG/v${{ steps.get_version.outputs.VERSION }}.md
publish-iam-floyd:
name: Publish iam-floyd
if: |
github.ref == 'refs/heads/main' && (
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
)
needs: release
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Fetch latest SHA
uses: actions/download-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
- name: Store latest SHA as output
id: get_sha
run: echo "SHA=$(cat /tmp/sha/sha)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ steps.get_sha.outputs.SHA }}
- name: Update package version
run: |
npm version "$(cat VERSION)" --allow-same-version --no-git-tag-version
grep version package.json
- name: Publish to npm
run: make install build publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-cdk-iam-floyd:
name: Publish cdk-iam-floyd
if: |
github.ref == 'refs/heads/main' && (
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
)
needs: release
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Fetch latest SHA
uses: actions/download-artifact@v4
with:
name: ${{ github.run_id }}
path: /tmp/sha
- name: Store latest SHA as output
id: get_sha
run: echo "SHA=$(cat /tmp/sha/sha)" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ steps.get_sha.outputs.SHA }}
- name: Update package version
run: |
npm version "$(cat VERSION)" --allow-same-version --no-git-tag-version
grep version package.json
- name: Build CDK variant
run: |
make install
make cdk
cat package.json
- name: Publish to npm
run: make build publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
success:
name: Test succeeded
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs:
- test-iam-floyd
- test-cdk-iam-floyd
steps:
- name: Report success
run: echo 'Success'