Browse Source

CLDC-4236: use correct sha ref for review apps

pull/3226/head^2
Nat Dean-Lewis 1 week ago
parent
commit
36918740f4
  1. 15
      .github/workflows/aws_deploy.yml
  2. 16
      .github/workflows/review_pipeline.yml

15
.github/workflows/aws_deploy.yml

@ -22,6 +22,10 @@ on:
release_tag: release_tag:
required: false required: false
type: string type: string
ref:
required: false
type: string
default: ""
concurrency: concurrency:
group: deploy-${{ inputs.environment }}${{ inputs.concurrency_tag }} group: deploy-${{ inputs.environment }}${{ inputs.concurrency_tag }}
@ -42,6 +46,8 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.sha }}
- name: Configure AWS credentials - name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4 uses: aws-actions/configure-aws-credentials@v4
@ -53,16 +59,19 @@ jobs:
id: ecr-login id: ecr-login
uses: aws-actions/amazon-ecr-login@v2 uses: aws-actions/amazon-ecr-login@v2
- name: Resolve commit SHA
run: echo "commit_sha=${{ inputs.ref || github.sha }}" >> $GITHUB_ENV
- name: Check if image with tag already exists - name: Check if image with tag already exists
run: | run: |
echo "image-exists=$(if aws ecr describe-images --repository-name=$repository --image-ids imageTag=${{ github.sha }} > /dev/null 2>&1; then echo true; else echo false; fi)" >> $GITHUB_ENV echo "image-exists=$(if aws ecr describe-images --repository-name=$repository --image-ids imageTag=${{ env.commit_sha }} > /dev/null 2>&1; then echo true; else echo false; fi)" >> $GITHUB_ENV
- name: Build, tag, and push docker image to ECR if there is no image, failing for releases - name: Build, tag, and push docker image to ECR if there is no image, failing for releases
id: build-image id: build-image
if: ${{ env.image-exists == 'false' }} if: ${{ env.image-exists == 'false' }}
env: env:
registry: ${{ steps.ecr-login.outputs.registry }} registry: ${{ steps.ecr-login.outputs.registry }}
commit_tag: ${{ github.sha }} commit_tag: ${{ env.commit_sha }}
run: | run: |
if [[ ${{ inputs.environment }} == 'production' ]]; then if [[ ${{ inputs.environment }} == 'production' ]]; then
echo "Error: Deployment to production environment is not allowed as there is no docker image (i.e. the AWS deploy on staging was unsuccessful for this commit)." echo "Error: Deployment to production environment is not allowed as there is no docker image (i.e. the AWS deploy on staging was unsuccessful for this commit)."
@ -100,7 +109,7 @@ jobs:
id: update-image-tags id: update-image-tags
env: env:
registry: ${{ steps.ecr-login.outputs.registry }} registry: ${{ steps.ecr-login.outputs.registry }}
commit_tag: ${{ github.sha }} commit_tag: ${{ inputs.ref || github.sha }}
readable_tag: ${{ inputs.environment }}-${{ env.additional-tag }} readable_tag: ${{ inputs.environment }}-${{ env.additional-tag }}
run: | run: |
manifest=$(aws ecr batch-get-image --repository-name $repository --image-ids imageTag=$commit_tag --output text --query images[].imageManifest) manifest=$(aws ecr batch-get-image --repository-name $repository --image-ids imageTag=$commit_tag --output text --query images[].imageManifest)

16
.github/workflows/review_pipeline.yml

@ -19,17 +19,26 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
pr_number: ${{ steps.get_pr_details.outputs.pr_number }} pr_number: ${{ steps.get_pr_details.outputs.pr_number }}
pr_head_sha: ${{ steps.get_pr_details.outputs.pr_head_sha }}
steps: steps:
- name: Get PR number - name: Get PR number and HEAD SHA
id: get_pr_details id: get_pr_details
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
let prNumber;
if (context.eventName === 'workflow_dispatch') { if (context.eventName === 'workflow_dispatch') {
core.setOutput('pr_number', '${{ inputs.pr_number }}'); prNumber = '${{ inputs.pr_number }}';
} else { } else {
core.setOutput('pr_number', context.issue.number.toString()); prNumber = context.issue.number.toString();
} }
core.setOutput('pr_number', prNumber);
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: parseInt(prNumber),
});
core.setOutput('pr_head_sha', pr.head.sha);
infra: infra:
name: Deploy review app infrastructure name: Deploy review app infrastructure
@ -51,6 +60,7 @@ jobs:
aws_task_prefix: core-review-${{ needs.get_pr_details.outputs.pr_number }} aws_task_prefix: core-review-${{ needs.get_pr_details.outputs.pr_number }}
concurrency_tag: ${{ needs.get_pr_details.outputs.pr_number }} concurrency_tag: ${{ needs.get_pr_details.outputs.pr_number }}
environment: review environment: review
ref: ${{ needs.get_pr_details.outputs.pr_head_sha }}
permissions: permissions:
id-token: write id-token: write

Loading…
Cancel
Save