diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ba59ece..962596d 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -8,6 +8,10 @@ on: branches: - '*' +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }} + cancel-in-progress: true + permissions: contents: read id-token: write @@ -18,57 +22,119 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - name: Set up nodejs - uses: actions/setup-node@v2 + - name: Setup Node.js + uses: actions/setup-node@v3 with: node-version: '16.16.0' cache: 'npm' - - name: npm CI + - name: npm ci run: npm ci - - name: npm ts tests + - name: npm test-ts-decls run: npm run test-ts-decls - - name: npm Check + - name: npm check run: npm run check - - name: npm Test + - name: npm test run: npm run test - - name: npm Build + - name: npm build run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") BUILD_COMMIT=${{ github.sha }} npm run build - - name: Configure AWS credentials (development) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} - uses: aws-actions/configure-aws-credentials@v1 + - name: Store assets + if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') }} + uses: actions/upload-artifact@v3 + with: + name: assets + path: umd/ + retention-days: 1 + + upload-stage: + name: Upload assets + runs-on: ubuntu-latest + needs: build + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} + strategy: + matrix: + environment: + - stage + - stage-eu + include: + - environment: stage + account_id: "079419646996" + bucket: split-public-stage + - environment: stage-eu + account_id: "901851837056" + bucket: split-public-stage-eu-west-1 + + steps: + - name: Download assets + uses: actions/download-artifact@v3 with: - role-to-assume: arn:aws:iam::079419646996:role/public-assets + name: assets + path: umd + + - name: Display structure of assets + run: ls -R + working-directory: umd + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1-node16 + with: + role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role aws-region: us-east-1 - - name: Upload to S3 (development) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} + - name: Upload to S3 run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS env: - BUCKET: split-public-stage + BUCKET: ${{ matrix.bucket }} SOURCE_DIR: ./umd DEST_DIR: sdk ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public - - name: Configure AWS credentials (main) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - uses: aws-actions/configure-aws-credentials@v1 + upload-prod: + name: Upload assets + runs-on: ubuntu-latest + needs: build + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + strategy: + matrix: + environment: + - prod + - prod-eu + include: + - environment: prod + account_id: "825951051969" + bucket: split-public + - environment: prod-eu + account_id: "842946900133" + bucket: split-public-eu-west-1 + + steps: + - name: Download assets + uses: actions/download-artifact@v3 + with: + name: assets + path: umd + + - name: Display structure of assets + run: ls -R + working-directory: umd + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1-node16 with: - role-to-assume: arn:aws:iam::825951051969:role/public-assets + role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role aws-region: us-east-1 - - name: Upload to S3 (main) - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + - name: Upload to S3 run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS env: - BUCKET: split-public + BUCKET: ${{ matrix.bucket }} SOURCE_DIR: ./umd DEST_DIR: sdk ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public