Merge pull request #762 from NYPL/SCC-5058/loading-heading #306
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
| # Run tests and deploy to research-catalog-qa, research-catalog-train, or research-catalog-production based on branch | |
| name: Test and deploy | |
| on: | |
| push: | |
| branches: | |
| - qa | |
| - production | |
| - train | |
| permissions: | |
| id-token: write | |
| contents: read | |
| env: | |
| AWS_DEFAULT_REGION: us-east-1 | |
| LOCAL_TAG_NAME: research-catalog:${{ github.ref_name }}-${{ github.run_number }} | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [20.x] | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: npm install | |
| run: npm ci | |
| - name: Unit tests | |
| run: npm test | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole | |
| aws-region: us-east-1 | |
| - name: Log in to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Set environment-specific variables | |
| run: | | |
| echo "APP_ENV=${GITHUB_REF_NAME}" >> $GITHUB_ENV | |
| echo "ECR_TAG=${GITHUB_REF_NAME}-latest" >> $GITHUB_ENV | |
| echo "PREVIOUS_TAG=${GITHUB_REF_NAME}-previous" >> $GITHUB_ENV | |
| echo "CLUSTER=research-catalog-${GITHUB_REF_NAME}" >> $GITHUB_ENV | |
| echo "SERVICE=research-catalog-${GITHUB_REF_NAME}" >> $GITHUB_ENV | |
| echo "ECR_URL=946183545209.dkr.ecr.us-east-1.amazonaws.com/research-catalog:${GITHUB_REF_NAME}-latest" >> $GITHUB_ENV | |
| - name: Build and push Docker image to Amazon ECR | |
| run: | | |
| docker build --build-arg NEXT_PUBLIC_APP_ENV=${APP_ENV} --tag $LOCAL_TAG_NAME . | |
| docker tag $LOCAL_TAG_NAME $ECR_URL | |
| # Back up previous latest image | |
| MANIFEST=$(aws ecr batch-get-image --repository-name research-catalog --image-ids imageTag="${ECR_TAG}" --output json | jq --raw-output --join-output '.images[0].imageManifest') | |
| aws ecr batch-delete-image --repository-name research-catalog --image-ids imageTag="${PREVIOUS_TAG}" || true | |
| aws ecr put-image --repository-name research-catalog --image-tag "${PREVIOUS_TAG}" --image-manifest "$MANIFEST" || true | |
| # Push new image | |
| docker push $ECR_URL | |
| - name: Update ECS service | |
| run: | | |
| aws ecs update-service --cluster $CLUSTER --service $SERVICE --force-new-deployment |