|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + - closed |
| 10 | + |
| 11 | +env: |
| 12 | + TARGET_ENV: ${{ github.base_ref == 'main' && 'prd' || github.base_ref == 'staging' && 'stg' || 'dev' }} |
| 13 | + DEV_AWS_ACCOUNT_ID: ${{ vars.DEV_AWS_ACCOUNT_ID }} |
| 14 | + STG_AWS_ACCOUNT_ID: ${{ vars.STG_AWS_ACCOUNT_ID }} |
| 15 | + PRD_AWS_ACCOUNT_ID: ${{ vars.PRD_AWS_ACCOUNT_ID }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + Integration: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 10 |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Setup Node.js 20 |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 20 |
| 29 | + cache: npm |
| 30 | + |
| 31 | + - name: Cache Dependency |
| 32 | + uses: actions/cache@v4 |
| 33 | + id: cache_dependency |
| 34 | + env: |
| 35 | + cache-name: cache-dependency |
| 36 | + with: |
| 37 | + path: "**/node_modules" |
| 38 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }} |
| 39 | + |
| 40 | + - name: Install Dependency |
| 41 | + if: ${{ steps.cache_dependency.outputs.cache-hit != 'true' }} |
| 42 | + run: npm ci --no-audit --progress=false --silent |
| 43 | + |
| 44 | + - name: Check Format |
| 45 | + run: | |
| 46 | + npm run check:format |
| 47 | +
|
| 48 | + - name: Check Lint |
| 49 | + run: | |
| 50 | + npm run check:lint |
| 51 | +
|
| 52 | + - name: Check Type |
| 53 | + run: npm run check:type |
| 54 | + |
| 55 | + - name: Check Cspell |
| 56 | + run: npm run check:cspell |
| 57 | + |
| 58 | + - name: Cdk Snapshot Test |
| 59 | + run: npm run test-snapshot -- run |
| 60 | + |
| 61 | + - name: Unit Test |
| 62 | + run: npm run test-unit -- run |
| 63 | + |
| 64 | + # TODO: CD を Environments を使った実装に置き換え予定 |
| 65 | + # @see https://github.com/classmethod-internal/icasu-cdk-serverless-api-sample/issues/342 |
| 66 | + |
| 67 | + Deploy: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + timeout-minutes: 30 |
| 70 | + if: github.event.pull_request.merged == true |
| 71 | + needs: Integration |
| 72 | + permissions: |
| 73 | + id-token: write |
| 74 | + contents: read |
| 75 | + steps: |
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Setup Node.js 20 |
| 80 | + uses: actions/setup-node@v4 |
| 81 | + with: |
| 82 | + node-version: 20 |
| 83 | + cache: npm |
| 84 | + |
| 85 | + - name: Restore Cache Dependency |
| 86 | + uses: actions/cache/restore@v4 |
| 87 | + id: cache_dependency |
| 88 | + env: |
| 89 | + cache-name: cache-dependency |
| 90 | + with: |
| 91 | + path: "**/node_modules" |
| 92 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }} |
| 93 | + |
| 94 | + - name: Assume Role |
| 95 | + uses: aws-actions/configure-aws-credentials@v4 |
| 96 | + with: |
| 97 | + aws-region: "ap-northeast-1" |
| 98 | + 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 }} |
| 99 | + |
| 100 | + - name: Deploy |
| 101 | + run: | |
| 102 | + npm run deploy:${{ env.TARGET_ENV }} |
0 commit comments