Skip to content

Commit 064fd13

Browse files
chore: refactor CICD
1 parent 5ca1a8d commit 064fd13

File tree

6 files changed

+224
-442
lines changed

6 files changed

+224
-442
lines changed

.github/workflows/common-build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

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

Lines changed: 93 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,29 @@
1-
name: Common CI
1+
name: Common CI tests
22

33
on:
44
workflow_call:
5+
inputs:
6+
mode:
7+
description: "'build' (just builded code, used while publishing) or 'global' (real NPM installed globally) or 'local' (real NPM installed locally)"
8+
type: string
9+
required: true
10+
testMonorepo:
11+
description: "Test monorepo by specifying folder in config"
12+
type: string
13+
default: false
514

615
permissions:
716
id-token: write
817
contents: write
918

1019
env:
1120
DISABLE_PARALLEL_DEPLOY: false
21+
REAL_NPM: ${{ github.event.inputs.mode == 'global' || github.event.inputs.mode == 'local' }}
22+
TEST_MONOREPO: ${{ github.event.inputs.testMonorepo }}
1223
node_version: 20
1324

1425
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-
4626
test-cdk-basic:
47-
needs:
48-
- build
4927
runs-on: ubuntu-latest
5028
concurrency:
5129
group: test-cdk-basic
@@ -58,10 +36,22 @@ jobs:
5836
registry-url: "https://registry.npmjs.org"
5937
- name: Install dependencies
6038
run: npm ci
61-
- uses: actions/download-artifact@v4
39+
- name: Download build artifact
40+
uses: actions/download-artifact@v4
41+
if: ${{ github.event.inputs.mode == 'build' }}
6242
with:
6343
name: dist
6444
path: dist
45+
- name: Install lambda-live-debugger globally
46+
if: ${{ github.event.inputs.mode == 'global' }}
47+
run: |
48+
npm i lambda-live-debugger -g
49+
working-directory: test
50+
- name: Install lambda-live-debugger locally
51+
if: ${{ github.event.inputs.mode == 'local' }}
52+
run: |
53+
npm i lambda-live-debugger
54+
working-directory: test
6555
- name: Configure AWS Credentials
6656
uses: aws-actions/configure-aws-credentials@v4
6757
with:
@@ -81,8 +71,6 @@ jobs:
8171
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts
8272

8373
test-sls-basic:
84-
needs:
85-
- build
8674
runs-on: ubuntu-latest
8775
concurrency:
8876
group: test-sls-basic
@@ -95,10 +83,23 @@ jobs:
9583
registry-url: "https://registry.npmjs.org"
9684
- name: Install dependencies
9785
run: npm ci
98-
- uses: actions/download-artifact@v4
86+
- name: Download build artifact
87+
uses: actions/download-artifact@v4
88+
if: ${{ github.event.inputs.mode == 'build' }}
9989
with:
10090
name: dist
10191
path: dist
92+
- name: Install lambda-live-debugger globally
93+
if: ${{ github.event.inputs.mode == 'global' }}
94+
run: |
95+
npm i lambda-live-debugger -g
96+
97+
working-directory: test
98+
- name: Install lambda-live-debugger locally
99+
if: ${{ github.event.inputs.mode == 'local' }}
100+
run: |
101+
npm i lambda-live-debugger
102+
working-directory: test
102103
- name: Configure AWS Credentials
103104
uses: aws-actions/configure-aws-credentials@v4
104105
with:
@@ -118,8 +119,6 @@ jobs:
118119
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts
119120

120121
test-sls-esbuild-cjs:
121-
needs:
122-
- build
123122
runs-on: ubuntu-latest
124123
concurrency:
125124
group: test-sls-esbuild-cjs
@@ -132,10 +131,23 @@ jobs:
132131
registry-url: "https://registry.npmjs.org"
133132
- name: Install dependencies
134133
run: npm ci
135-
- uses: actions/download-artifact@v4
134+
- name: Download build artifact
135+
uses: actions/download-artifact@v4
136+
if: ${{ github.event.inputs.mode == 'build' }}
136137
with:
137138
name: dist
138139
path: dist
140+
- name: Install lambda-live-debugger globally
141+
if: ${{ github.event.inputs.mode == 'global' }}
142+
run: |
143+
npm i lambda-live-debugger -g
144+
145+
working-directory: test
146+
- name: Install lambda-live-debugger locally
147+
if: ${{ github.event.inputs.mode == 'local' }}
148+
run: |
149+
npm i lambda-live-debugger
150+
working-directory: test
139151
- name: Configure AWS Credentials
140152
uses: aws-actions/configure-aws-credentials@v4
141153
with:
@@ -155,8 +167,6 @@ jobs:
155167
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts
156168

157169
test-sls-esbuild-esm:
158-
needs:
159-
- build
160170
runs-on: ubuntu-latest
161171
concurrency:
162172
group: test-sls-esbuild-esm
@@ -169,10 +179,23 @@ jobs:
169179
registry-url: "https://registry.npmjs.org"
170180
- name: Install dependencies
171181
run: npm ci
172-
- uses: actions/download-artifact@v4
182+
- name: Download build artifact
183+
uses: actions/download-artifact@v4
184+
if: ${{ github.event.inputs.mode == 'build' }}
173185
with:
174186
name: dist
175187
path: dist
188+
- name: Install lambda-live-debugger globally
189+
if: ${{ github.event.inputs.mode == 'global' }}
190+
run: |
191+
npm i lambda-live-debugger -g
192+
193+
working-directory: test
194+
- name: Install lambda-live-debugger locally
195+
if: ${{ github.event.inputs.mode == 'local' }}
196+
run: |
197+
npm i lambda-live-debugger
198+
working-directory: test
176199
- name: Configure AWS Credentials
177200
uses: aws-actions/configure-aws-credentials@v4
178201
with:
@@ -192,8 +215,6 @@ jobs:
192215
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts
193216

194217
test-sam-basic:
195-
needs:
196-
- build
197218
runs-on: ubuntu-latest
198219
concurrency:
199220
group: test-sam-basic
@@ -210,10 +231,22 @@ jobs:
210231
registry-url: "https://registry.npmjs.org"
211232
- name: Install dependencies
212233
run: npm ci
213-
- uses: actions/download-artifact@v4
234+
- name: Download build artifact
235+
uses: actions/download-artifact@v4
236+
if: ${{ github.event.inputs.mode == 'build' }}
214237
with:
215238
name: dist
216239
path: dist
240+
- name: Install lambda-live-debugger globally
241+
if: ${{ github.event.inputs.mode == 'global' }}
242+
run: |
243+
npm i lambda-live-debugger -g
244+
working-directory: test
245+
- name: Install lambda-live-debugger locally
246+
if: ${{ github.event.inputs.mode == 'local' }}
247+
run: |
248+
npm i lambda-live-debugger
249+
working-directory: test
217250
- name: Configure AWS Credentials
218251
uses: aws-actions/configure-aws-credentials@v4
219252
with:
@@ -233,8 +266,6 @@ jobs:
233266
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts
234267

235268
test-terraform-basic:
236-
needs:
237-
- build
238269
runs-on: ubuntu-latest
239270
concurrency:
240271
group: test-terraform-basic
@@ -247,10 +278,22 @@ jobs:
247278
registry-url: "https://registry.npmjs.org"
248279
- name: Install dependencies
249280
run: npm ci
250-
- uses: actions/download-artifact@v4
281+
- name: Download build artifact
282+
uses: actions/download-artifact@v4
283+
if: ${{ github.event.inputs.mode == 'build' }}
251284
with:
252285
name: dist
253286
path: dist
287+
- name: Install lambda-live-debugger globally
288+
if: ${{ github.event.inputs.mode == 'global' }}
289+
run: |
290+
npm i lambda-live-debugger -g
291+
working-directory: test
292+
- name: Install lambda-live-debugger locally
293+
if: ${{ github.event.inputs.mode == 'local' }}
294+
run: |
295+
npm i lambda-live-debugger
296+
working-directory: test
254297
- name: Configure AWS Credentials
255298
uses: aws-actions/configure-aws-credentials@v4
256299
with:
@@ -275,37 +318,3 @@ jobs:
275318
run: npx vitest --retry 1 test/terraform-basic.test.ts
276319
- name: Test - observable mode
277320
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ 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
1424

1525
publish:
16-
needs: build-and-test
26+
needs: test
1727
if: github.event_name == 'workflow_dispatch'
1828
runs-on: ubuntu-latest
1929
concurrency:
@@ -23,7 +33,7 @@ jobs:
2333
- name: Use Node.js
2434
uses: actions/setup-node@v4
2535
with:
26-
node-version: "20"
36+
node-version: ${{ env.node_version }}
2737
registry-url: "https://registry.npmjs.org"
2838
- name: Install dependencies
2939
run: npm ci

0 commit comments

Comments
 (0)