Skip to content

Commit

Permalink
chore: refactor CICD
Browse files Browse the repository at this point in the history
  • Loading branch information
ServerlessLife committed Aug 3, 2024
1 parent 5ca1a8d commit f1c2e42
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 442 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/common-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Common CI build

on:
workflow_call:

permissions:
id-token: write
contents: write

env:
node_version: 20

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: build
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Typecheck
run: npm run typecheck
- name: Build
run: npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubActions
- name: Bootstrap CDK
# so I do not have to do it manually when CDK is updated
run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist
177 changes: 93 additions & 84 deletions .github/workflows/common.yml → .github/workflows/common-test.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
name: Common CI
name: Common CI tests

on:
workflow_call:
inputs:
mode:
description: "'build' (just builded code, used while publishing) or 'global' (real NPM installed globally) or 'local' (real NPM installed locally)"
type: string
required: true
testMonorepo:
description: "Test monorepo by specifying folder in config"
type: string
default: false

permissions:
id-token: write
contents: write

env:
DISABLE_PARALLEL_DEPLOY: false
REAL_NPM: ${{ github.event.inputs.mode == 'global' || github.event.inputs.mode == 'local' }}
TEST_MONOREPO: ${{ github.event.inputs.testMonorepo }}
node_version: 20

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: build
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Typecheck
run: npm run typecheck
- name: Build
run: npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubActions
- name: Bootstrap CDK
# so I do not have to do it manually when CDK is updated
run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist

test-cdk-basic:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-cdk-basic
Expand All @@ -58,10 +36,22 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -81,8 +71,6 @@ jobs:
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts

test-sls-basic:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-sls-basic
Expand All @@ -95,10 +83,23 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
npm i serverless@3.38.0 -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -118,8 +119,6 @@ jobs:
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts

test-sls-esbuild-cjs:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-sls-esbuild-cjs
Expand All @@ -132,10 +131,23 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
npm i serverless@3.38.0 -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -155,8 +167,6 @@ jobs:
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts

test-sls-esbuild-esm:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-sls-esbuild-esm
Expand All @@ -169,10 +179,23 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
npm i serverless@3.38.0 -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -192,8 +215,6 @@ jobs:
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts

test-sam-basic:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-sam-basic
Expand All @@ -210,10 +231,22 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -233,8 +266,6 @@ jobs:
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts

test-terraform-basic:
needs:
- build
runs-on: ubuntu-latest
concurrency:
group: test-terraform-basic
Expand All @@ -247,10 +278,22 @@ jobs:
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ github.event.inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ github.event.inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ github.event.inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -275,37 +318,3 @@ jobs:
run: npx vitest --retry 1 test/terraform-basic.test.ts
- name: Test - observable mode
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts

publish:
needs:
- test-cdk-basic
- test-sls-basic
- test-sls-esbuild-cjs
- test-sls-esbuild-esm
- test-sam-basic
- test-terraform-basic
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
concurrency:
group: publish
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Semantic Release
run: |
npm whoami
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 14 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ permissions:
id-token: write
contents: write

env:
node_version: 20

jobs:
build-and-test:
uses: ./.github/workflows/common.yml
build:
uses: ./.github/workflows/common-build.yml
secrets: inherit

test:
uses: ./.github/workflows/common-test.yml
secrets: inherit
needs: build
with:
mode: build

publish:
needs: build-and-test
needs: test
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
concurrency:
Expand All @@ -23,7 +33,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: ${{ env.node_version }}
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
Expand Down
Loading

0 comments on commit f1c2e42

Please sign in to comment.