Skip to content

Commit 4d19051

Browse files
chore: refactor CICD
1 parent 83cf1ce commit 4d19051

File tree

6 files changed

+228
-442
lines changed

6 files changed

+228
-442
lines changed

.github/workflows/common-build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Common CI build
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
id-token: write
8+
contents: write
9+
10+
env:
11+
node_version: 20
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
concurrency:
17+
group: build
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Use Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ env.node_version }}
24+
registry-url: "https://registry.npmjs.org"
25+
- name: Install dependencies
26+
run: npm ci
27+
- name: Typecheck
28+
run: npm run typecheck
29+
- name: Build
30+
run: npm run build
31+
- name: Configure AWS Credentials
32+
uses: aws-actions/configure-aws-credentials@v4
33+
with:
34+
aws-region: eu-west-1
35+
role-to-assume: ${{ secrets.AWS_ROLE }}
36+
role-session-name: GitHubActions
37+
- name: Bootstrap CDK
38+
# so I do not have to do it manually when CDK is updated
39+
run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1
40+
- uses: actions/upload-artifact@v4
41+
with:
42+
name: dist
43+
path: dist
44+
retention-days: 1

.github/workflows/common.yml renamed to .github/workflows/common-test.yml

Lines changed: 95 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,31 @@
1-
name: Common CI
1+
name: Common CI tests
2+
3+
run-name: "Test: mode=${{ inputs.mode }}, testMonorepo=${{ inputs.testMonorepo }}"
24

35
on:
46
workflow_call:
7+
inputs:
8+
mode:
9+
description: "'build' (just builded code, used while publishing) or 'global' (real NPM installed globally) or 'local' (real NPM installed locally)"
10+
type: string
11+
required: true
12+
testMonorepo:
13+
description: "Test monorepo by specifying folder in config"
14+
type: string
15+
required: true
516

617
permissions:
718
id-token: write
819
contents: write
920

1021
env:
1122
DISABLE_PARALLEL_DEPLOY: false
23+
REAL_NPM: ${{ inputs.mode == 'global' || inputs.mode == 'local' }}
24+
TEST_MONOREPO: ${{ github.event.inputs.testMonorepo }}
1225
node_version: 20
1326

1427
jobs:
15-
build:
16-
runs-on: ubuntu-latest
17-
concurrency:
18-
group: build
19-
steps:
20-
- uses: actions/checkout@v4
21-
- name: Use Node.js
22-
uses: actions/setup-node@v4
23-
with:
24-
node-version: ${{ env.node_version }}
25-
registry-url: "https://registry.npmjs.org"
26-
- name: Install dependencies
27-
run: npm ci
28-
- name: Typecheck
29-
run: npm run typecheck
30-
- name: Build
31-
run: npm run build
32-
- name: Configure AWS Credentials
33-
uses: aws-actions/configure-aws-credentials@v4
34-
with:
35-
aws-region: eu-west-1
36-
role-to-assume: ${{ secrets.AWS_ROLE }}
37-
role-session-name: GitHubActions
38-
- name: Bootstrap CDK
39-
# so I do not have to do it manually when CDK is updated
40-
run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1
41-
- uses: actions/upload-artifact@v4
42-
with:
43-
name: dist
44-
path: dist
45-
4628
test-cdk-basic:
47-
needs:
48-
- build
4929
runs-on: ubuntu-latest
5030
concurrency:
5131
group: test-cdk-basic
@@ -58,10 +38,22 @@ jobs:
5838
registry-url: "https://registry.npmjs.org"
5939
- name: Install dependencies
6040
run: npm ci
61-
- uses: actions/download-artifact@v4
41+
- name: Download build artifact
42+
uses: actions/download-artifact@v4
43+
if: ${{ inputs.mode == 'build' }}
6244
with:
6345
name: dist
6446
path: dist
47+
- name: Install lambda-live-debugger globally
48+
if: ${{ inputs.mode == 'global' }}
49+
run: |
50+
npm i lambda-live-debugger -g
51+
working-directory: test
52+
- name: Install lambda-live-debugger locally
53+
if: ${{ inputs.mode == 'local' }}
54+
run: |
55+
npm i lambda-live-debugger
56+
working-directory: test
6557
- name: Configure AWS Credentials
6658
uses: aws-actions/configure-aws-credentials@v4
6759
with:
@@ -81,8 +73,6 @@ jobs:
8173
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts
8274

8375
test-sls-basic:
84-
needs:
85-
- build
8676
runs-on: ubuntu-latest
8777
concurrency:
8878
group: test-sls-basic
@@ -95,10 +85,23 @@ jobs:
9585
registry-url: "https://registry.npmjs.org"
9686
- name: Install dependencies
9787
run: npm ci
98-
- uses: actions/download-artifact@v4
88+
- name: Download build artifact
89+
uses: actions/download-artifact@v4
90+
if: ${{ inputs.mode == 'build' }}
9991
with:
10092
name: dist
10193
path: dist
94+
- name: Install lambda-live-debugger globally
95+
if: ${{ inputs.mode == 'global' }}
96+
run: |
97+
npm i lambda-live-debugger -g
98+
99+
working-directory: test
100+
- name: Install lambda-live-debugger locally
101+
if: ${{ inputs.mode == 'local' }}
102+
run: |
103+
npm i lambda-live-debugger
104+
working-directory: test
102105
- name: Configure AWS Credentials
103106
uses: aws-actions/configure-aws-credentials@v4
104107
with:
@@ -118,8 +121,6 @@ jobs:
118121
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts
119122

120123
test-sls-esbuild-cjs:
121-
needs:
122-
- build
123124
runs-on: ubuntu-latest
124125
concurrency:
125126
group: test-sls-esbuild-cjs
@@ -132,10 +133,23 @@ jobs:
132133
registry-url: "https://registry.npmjs.org"
133134
- name: Install dependencies
134135
run: npm ci
135-
- uses: actions/download-artifact@v4
136+
- name: Download build artifact
137+
uses: actions/download-artifact@v4
138+
if: ${{ inputs.mode == 'build' }}
136139
with:
137140
name: dist
138141
path: dist
142+
- name: Install lambda-live-debugger globally
143+
if: ${{ inputs.mode == 'global' }}
144+
run: |
145+
npm i lambda-live-debugger -g
146+
147+
working-directory: test
148+
- name: Install lambda-live-debugger locally
149+
if: ${{ inputs.mode == 'local' }}
150+
run: |
151+
npm i lambda-live-debugger
152+
working-directory: test
139153
- name: Configure AWS Credentials
140154
uses: aws-actions/configure-aws-credentials@v4
141155
with:
@@ -155,8 +169,6 @@ jobs:
155169
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts
156170

157171
test-sls-esbuild-esm:
158-
needs:
159-
- build
160172
runs-on: ubuntu-latest
161173
concurrency:
162174
group: test-sls-esbuild-esm
@@ -169,10 +181,23 @@ jobs:
169181
registry-url: "https://registry.npmjs.org"
170182
- name: Install dependencies
171183
run: npm ci
172-
- uses: actions/download-artifact@v4
184+
- name: Download build artifact
185+
uses: actions/download-artifact@v4
186+
if: ${{ inputs.mode == 'build' }}
173187
with:
174188
name: dist
175189
path: dist
190+
- name: Install lambda-live-debugger globally
191+
if: ${{ inputs.mode == 'global' }}
192+
run: |
193+
npm i lambda-live-debugger -g
194+
195+
working-directory: test
196+
- name: Install lambda-live-debugger locally
197+
if: ${{ inputs.mode == 'local' }}
198+
run: |
199+
npm i lambda-live-debugger
200+
working-directory: test
176201
- name: Configure AWS Credentials
177202
uses: aws-actions/configure-aws-credentials@v4
178203
with:
@@ -192,8 +217,6 @@ jobs:
192217
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts
193218

194219
test-sam-basic:
195-
needs:
196-
- build
197220
runs-on: ubuntu-latest
198221
concurrency:
199222
group: test-sam-basic
@@ -210,10 +233,22 @@ jobs:
210233
registry-url: "https://registry.npmjs.org"
211234
- name: Install dependencies
212235
run: npm ci
213-
- uses: actions/download-artifact@v4
236+
- name: Download build artifact
237+
uses: actions/download-artifact@v4
238+
if: ${{ inputs.mode == 'build' }}
214239
with:
215240
name: dist
216241
path: dist
242+
- name: Install lambda-live-debugger globally
243+
if: ${{ inputs.mode == 'global' }}
244+
run: |
245+
npm i lambda-live-debugger -g
246+
working-directory: test
247+
- name: Install lambda-live-debugger locally
248+
if: ${{ inputs.mode == 'local' }}
249+
run: |
250+
npm i lambda-live-debugger
251+
working-directory: test
217252
- name: Configure AWS Credentials
218253
uses: aws-actions/configure-aws-credentials@v4
219254
with:
@@ -233,8 +268,6 @@ jobs:
233268
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts
234269

235270
test-terraform-basic:
236-
needs:
237-
- build
238271
runs-on: ubuntu-latest
239272
concurrency:
240273
group: test-terraform-basic
@@ -247,10 +280,22 @@ jobs:
247280
registry-url: "https://registry.npmjs.org"
248281
- name: Install dependencies
249282
run: npm ci
250-
- uses: actions/download-artifact@v4
283+
- name: Download build artifact
284+
uses: actions/download-artifact@v4
285+
if: ${{ inputs.mode == 'build' }}
251286
with:
252287
name: dist
253288
path: dist
289+
- name: Install lambda-live-debugger globally
290+
if: ${{ inputs.mode == 'global' }}
291+
run: |
292+
npm i lambda-live-debugger -g
293+
working-directory: test
294+
- name: Install lambda-live-debugger locally
295+
if: ${{ inputs.mode == 'local' }}
296+
run: |
297+
npm i lambda-live-debugger
298+
working-directory: test
254299
- name: Configure AWS Credentials
255300
uses: aws-actions/configure-aws-credentials@v4
256301
with:
@@ -275,37 +320,3 @@ jobs:
275320
run: npx vitest --retry 1 test/terraform-basic.test.ts
276321
- name: Test - observable mode
277322
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts
278-
279-
publish:
280-
needs:
281-
- test-cdk-basic
282-
- test-sls-basic
283-
- test-sls-esbuild-cjs
284-
- test-sls-esbuild-esm
285-
- test-sam-basic
286-
- test-terraform-basic
287-
if: github.event_name == 'workflow_dispatch'
288-
runs-on: ubuntu-latest
289-
concurrency:
290-
group: publish
291-
steps:
292-
- uses: actions/checkout@v4
293-
- name: Use Node.js
294-
uses: actions/setup-node@v4
295-
with:
296-
node-version: ${{ env.node_version }}
297-
registry-url: "https://registry.npmjs.org"
298-
- name: Install dependencies
299-
run: npm ci
300-
- uses: actions/download-artifact@v4
301-
with:
302-
name: dist
303-
path: dist
304-
- name: Semantic Release
305-
run: |
306-
npm whoami
307-
npx semantic-release
308-
env:
309-
GITHUB_TOKEN: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
310-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
311-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@ permissions:
77
id-token: write
88
contents: write
99

10+
env:
11+
node_version: 20
12+
1013
jobs:
11-
build-and-test:
12-
uses: ./.github/workflows/common.yml
14+
build:
15+
uses: ./.github/workflows/common-build.yml
16+
secrets: inherit
17+
18+
test:
19+
uses: ./.github/workflows/common-test.yml
1320
secrets: inherit
21+
needs: build
22+
with:
23+
mode: build
24+
testMonorepo: false
1425

1526
publish:
16-
needs: build-and-test
27+
needs: test
1728
if: github.event_name == 'workflow_dispatch'
1829
runs-on: ubuntu-latest
1930
concurrency:
@@ -23,7 +34,7 @@ jobs:
2334
- name: Use Node.js
2435
uses: actions/setup-node@v4
2536
with:
26-
node-version: "20"
37+
node-version: ${{ env.node_version }}
2738
registry-url: "https://registry.npmjs.org"
2839
- name: Install dependencies
2940
run: npm ci

0 commit comments

Comments
 (0)