Skip to content

Commit 65190ca

Browse files
chore: refactor CICD
1 parent de41ecd commit 65190ca

File tree

5 files changed

+120
-436
lines changed

5 files changed

+120
-436
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: 28 additions & 78 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: boolean
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
@@ -59,9 +37,20 @@ jobs:
5937
- name: Install dependencies
6038
run: npm ci
6139
- uses: actions/download-artifact@v4
40+
if: ${{ github.event.inputs.mode == 'build' }}
6241
with:
6342
name: dist
6443
path: dist
44+
- name: Install lambda-live-debugger globally
45+
if: ${{ github.event.inputs.mode == 'global' }}
46+
run: |
47+
npm i lambda-live-debugger -g
48+
working-directory: test
49+
- name: Install lambda-live-debugger locally
50+
if: ${{ github.event.inputs.mode != 'local' }}
51+
run: |
52+
npm i lambda-live-debugger
53+
working-directory: test
6554
- name: Configure AWS Credentials
6655
uses: aws-actions/configure-aws-credentials@v4
6756
with:
@@ -81,8 +70,6 @@ jobs:
8170
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts
8271

8372
test-sls-basic:
84-
needs:
85-
- build
8673
runs-on: ubuntu-latest
8774
concurrency:
8875
group: test-sls-basic
@@ -96,6 +83,7 @@ jobs:
9683
- name: Install dependencies
9784
run: npm ci
9885
- uses: actions/download-artifact@v4
86+
if: ${{ github.event.inputs.mode == 'build' }}
9987
with:
10088
name: dist
10189
path: dist
@@ -118,8 +106,6 @@ jobs:
118106
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts
119107

120108
test-sls-esbuild-cjs:
121-
needs:
122-
- build
123109
runs-on: ubuntu-latest
124110
concurrency:
125111
group: test-sls-esbuild-cjs
@@ -133,6 +119,7 @@ jobs:
133119
- name: Install dependencies
134120
run: npm ci
135121
- uses: actions/download-artifact@v4
122+
if: ${{ github.event.inputs.mode == 'build' }}
136123
with:
137124
name: dist
138125
path: dist
@@ -155,8 +142,6 @@ jobs:
155142
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts
156143

157144
test-sls-esbuild-esm:
158-
needs:
159-
- build
160145
runs-on: ubuntu-latest
161146
concurrency:
162147
group: test-sls-esbuild-esm
@@ -170,6 +155,7 @@ jobs:
170155
- name: Install dependencies
171156
run: npm ci
172157
- uses: actions/download-artifact@v4
158+
if: ${{ github.event.inputs.mode == 'build' }}
173159
with:
174160
name: dist
175161
path: dist
@@ -192,8 +178,6 @@ jobs:
192178
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts
193179

194180
test-sam-basic:
195-
needs:
196-
- build
197181
runs-on: ubuntu-latest
198182
concurrency:
199183
group: test-sam-basic
@@ -211,6 +195,7 @@ jobs:
211195
- name: Install dependencies
212196
run: npm ci
213197
- uses: actions/download-artifact@v4
198+
if: ${{ github.event.inputs.mode == 'build' }}
214199
with:
215200
name: dist
216201
path: dist
@@ -233,8 +218,6 @@ jobs:
233218
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts
234219

235220
test-terraform-basic:
236-
needs:
237-
- build
238221
runs-on: ubuntu-latest
239222
concurrency:
240223
group: test-terraform-basic
@@ -248,6 +231,7 @@ jobs:
248231
- name: Install dependencies
249232
run: npm ci
250233
- uses: actions/download-artifact@v4
234+
if: ${{ github.event.inputs.mode == 'build' }}
251235
with:
252236
name: dist
253237
path: dist
@@ -275,37 +259,3 @@ jobs:
275259
run: npx vitest --retry 1 test/terraform-basic.test.ts
276260
- name: Test - observable mode
277261
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)