API CI by Whiskey-Taste #51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD pipeline (API) | |
| run-name: > | |
| ${{ github.event_name == 'pull_request' && format('API CI by {0}', github.actor) || | |
| github.event_name == 'push' && format('API CI/CD (push) by {0}', github.actor) || | |
| github.event_name == 'workflow_dispatch' && 'API pipeline (manual)' }} | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| mode: | |
| description: "Choose pipeline mode" | |
| type: choice | |
| options: [ci, cicd] | |
| default: cicd | |
| required: true | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref || github.run_id }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| id-token: write # for AWS OIDC | |
| env: | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| # 例如:123456789012.dkr.ecr.ap-southeast-2.amazonaws.com/dispatchai-api | |
| ECR_API_REPO: ${{ secrets.BACKEND_API_ECR_URI }} | |
| IMAGE_UAT: uat-latest | |
| IMAGE_TAG: uat-${{ github.run_number }} # 或者 sha-${{ github.sha }} | |
| jobs: | |
| ci_api: | |
| runs-on: ubuntu-latest | |
| # PR、push main、手动(ci/cicd)都跑 CI | |
| if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || inputs.mode == 'ci' || inputs.mode == 'cicd' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| cache-dependency-path: | | |
| pnpm-lock.yaml | |
| **/pnpm-lock.yaml | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Type check | |
| run: pnpm run type-check | |
| - name: Lint | |
| run: pnpm run lint | |
| # (可选)缓存 mongodb-memory-server 的二进制,加速 CI | |
| - name: Cache MongoMemoryServer binary | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/mongodb-binaries | |
| key: mms-${{ runner.os }}-v1 | |
| - name: Test (mongodb-memory-server) | |
| env: | |
| CI: true | |
| NODE_ENV: test | |
| USE_IN_MEMORY_DB: true | |
| MONGOMS_DOWNLOAD_DIR: ~/.cache/mongodb-binaries | |
| run: pnpm test:ci |