-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (84 loc) · 2.7 KB
/
cicd.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
name: CI/CD
on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
env:
TARGET_ENV: ${{ github.base_ref == 'main' && 'prd' || github.base_ref == 'staging' && 'stg' || 'dev' }}
DEV_AWS_ACCOUNT_ID: ${{ vars.DEV_AWS_ACCOUNT_ID }}
STG_AWS_ACCOUNT_ID: ${{ vars.STG_AWS_ACCOUNT_ID }}
PRD_AWS_ACCOUNT_ID: ${{ vars.PRD_AWS_ACCOUNT_ID }}
jobs:
Integration:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Cache Dependency
uses: actions/cache@v4
id: cache_dependency
env:
cache-name: cache-dependency
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Install Dependency
if: ${{ steps.cache_dependency.outputs.cache-hit != 'true' }}
run: npm ci --no-audit --progress=false --silent
- name: Check Format
run: |
npm run check:format
- name: Check Lint
run: |
npm run check:lint
- name: Check Type
run: npm run check:type
- name: Check Cspell
run: npm run check:cspell
- name: Cdk Snapshot Test
run: npm run test-snapshot -- run
- name: Unit Test
run: npm run test-unit -- run
# TODO: CD を Environments を使った実装に置き換え予定
# @see https://github.com/classmethod-internal/icasu-cdk-serverless-api-sample/issues/342
Deploy:
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event.pull_request.merged == true
needs: Integration
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Restore Cache Dependency
uses: actions/cache/restore@v4
id: cache_dependency
env:
cache-name: cache-dependency
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Assume Role
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: "ap-northeast-1"
role-to-assume: ${{ env.TARGET_ENV == 'prd' && vars.PRD_AWS_OIDC_ROLE_ARN || env.TARGET_ENV == 'stg' && vars.STG_AWS_OIDC_ROLE_ARN || vars.DEV_AWS_OIDC_ROLE_ARN }}
- name: Deploy
run: |
npm run deploy:${{ env.TARGET_ENV }}