|
| 1 | +name: Build |
| 2 | + |
| 3 | +permissions: |
| 4 | + id-token: write |
| 5 | + contents: write |
| 6 | + issues: read |
| 7 | + |
| 8 | +on: [push] |
| 9 | + |
| 10 | +env: |
| 11 | + CI_BUILD_NUM: ${{ github.run_id }} |
| 12 | + CI_BRANCH: ${{ github.ref_name }} |
| 13 | + HLX_AWS_REGION: ${{ secrets.AWS_REGION }} |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Check out |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + persist-credentials: 'false' |
| 22 | + - name: Setup Node & NPM |
| 23 | + uses: ./.github/actions/setup-node-npm |
| 24 | + |
| 25 | + - name: Lint, Test, Coverage Upload |
| 26 | + uses: ./.github/actions/lint-test-coverage |
| 27 | + with: |
| 28 | + upload_coverage: "true" |
| 29 | + codecov_token: ${{ secrets.CODECOV_TOKEN }} |
| 30 | + |
| 31 | + - name: Semantic Release (Dry Run) |
| 32 | + if: github.ref != 'refs/heads/main' |
| 33 | + run: npm run semantic-release-dry |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.ADOBE_BOT_GITHUB_TOKEN }} |
| 36 | + NPM_TOKEN: ${{ secrets.ADOBE_BOT_NPM_TOKEN }} |
| 37 | + |
| 38 | + - name: Print npm debug log if build fails |
| 39 | + if: failure() |
| 40 | + run: | |
| 41 | + if [ -f /home/runner/.npm/_logs/*.log ]; then |
| 42 | + echo "==== NPM DEBUG LOG ====" |
| 43 | + find /home/runner/.npm/_logs -name '*.log' -exec cat {} \; |
| 44 | + echo "==== END NPM DEBUG LOG ====" |
| 45 | + else |
| 46 | + echo "No npm debug log found." |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Clean npm cache |
| 50 | + run: npm cache clean --force |
| 51 | + |
| 52 | + - name: Create empty cache directory |
| 53 | + run: mkdir -p /tmp/empty-cache |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: npm ci --cache /tmp/empty-cache |
| 57 | + |
| 58 | + semantic-release: |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: build |
| 61 | + if: github.ref == 'refs/heads/main' |
| 62 | + steps: |
| 63 | + - name: Check out |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + persist-credentials: 'false' |
| 67 | + |
| 68 | + - name: Configure Environment |
| 69 | + run: echo -e "LOG_LEVEL=info\n" > .env |
| 70 | + |
| 71 | + - name: Setup Node & NPM |
| 72 | + uses: ./.github/actions/setup-node-npm |
| 73 | + |
| 74 | + - name: Configure AWS |
| 75 | + uses: ./.github/actions/configure-aws |
| 76 | + with: |
| 77 | + aws_role_to_assume: 'arn:aws:iam::${{secrets.AWS_ACCOUNT_ID_PROD}}:role/spacecat-role-github-actions' |
| 78 | + |
| 79 | + - name: Semantic Release |
| 80 | + run: npm run semantic-release |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.ADOBE_BOT_GITHUB_TOKEN }} |
| 83 | + NPM_TOKEN: ${{ secrets.ADOBE_BOT_NPM_TOKEN }} |
| 84 | + AWS_REGION: us-east-1 |
| 85 | + AWS_ACCOUNT_ID: ${{secrets.AWS_ACCOUNT_ID_PROD}} |
| 86 | + |
| 87 | + deploy-stage: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: build |
| 90 | + if: github.ref == 'refs/heads/main' |
| 91 | + steps: |
| 92 | + - name: Check out |
| 93 | + uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + persist-credentials: 'false' |
| 96 | + |
| 97 | + - name: Setup Node & NPM |
| 98 | + uses: ./.github/actions/setup-node-npm |
| 99 | + |
| 100 | + - name: Configure AWS for STAGE |
| 101 | + uses: ./.github/actions/configure-aws |
| 102 | + with: |
| 103 | + aws_role_to_assume: 'arn:aws:iam::${{secrets.AWS_ACCOUNT_ID_STAGE}}:role/spacecat-role-github-actions' |
| 104 | + |
| 105 | + - name: Branch Deployment |
| 106 | + run: npm run deploy-stage |
| 107 | + env: |
| 108 | + AWS_REGION: us-east-1 |
| 109 | + AWS_ACCOUNT_ID: ${{secrets.AWS_ACCOUNT_ID_STAGE}} |
| 110 | + |
| 111 | + |
| 112 | + branch-deploy: |
| 113 | + runs-on: ubuntu-latest |
| 114 | + needs: build |
| 115 | + if: github.ref != 'refs/heads/main' |
| 116 | + steps: |
| 117 | + - name: Check out |
| 118 | + uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + persist-credentials: 'false' |
| 121 | + |
| 122 | + - name: Setup Node & NPM |
| 123 | + uses: ./.github/actions/setup-node-npm |
| 124 | + |
| 125 | + - name: Configure AWS |
| 126 | + uses: ./.github/actions/configure-aws |
| 127 | + with: |
| 128 | + aws_role_to_assume: 'arn:aws:iam::${{secrets.AWS_ACCOUNT_ID_DEV}}:role/spacecat-role-github-actions' |
| 129 | + |
| 130 | + - name: Branch Deployment |
| 131 | + run: npm run deploy-dev |
| 132 | + env: |
| 133 | + AWS_REGION: us-east-1 |
| 134 | + AWS_ACCOUNT_ID: ${{secrets.AWS_ACCOUNT_ID_DEV}} |
| 135 | + |
| 136 | + - name: Post-Deployment Integration Test |
| 137 | + run: npm run test-postdeploy |
0 commit comments