From 179e6dcdc0ba3ec2db1942e4030e2160c821d419 Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Sat, 9 Dec 2023 12:47:34 +0900 Subject: [PATCH] deploy infrastructure: name PR releases using a timestamp To make it clear to users when the PR contents has changed. --- .github/workflows/build-container.yml | 29 ++++++++++++++++++------- .github/workflows/cleanup-container.yml | 4 ++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 7062812693f0..87ef3109971e 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -38,8 +38,10 @@ jobs: shell: bash run: | if [ "$GITHUB_HEAD_REF" ]; then + type="pr" tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}" elif [[ "$GITHUB_REF" == refs/tags/* ]]; then + type="tag" tag="${GITHUB_REF#refs/tags/}" else echo "Not a pull request or release tag" >&2 @@ -47,7 +49,8 @@ jobs: fi # Replace / with . in container tag names tag="${tag//\//.}" - echo "CONTAINER_NAME=${tag}" >> $GITHUB_ENV + echo "VERSION_TYPE=${type}" >> $GITHUB_ENV + echo "VERSION_NAME=${tag}" >> $GITHUB_ENV id: extract_name - name: Login to Amazon ECR id: login-ecr @@ -77,15 +80,25 @@ jobs: digest="$(docker inspect --format='{{index .RepoDigests 0}}' $REGISTRY/$ECR_REPOSITORY:$REVISION_TAG)" digest="${digest##*@}" api_version="$(cat lambda/api_version.txt)" + timestamp="$(date -u +"%Y%m%d.%H%M%S")" + + if [ "$VERSION_TYPE" = "pr" ]; then + release_name="$VERSION_NAME.$timestamp" + else + release_name="$VERSION_NAME" + fi + jq -n '$ARGS.named' \ - --arg name "$CONTAINER_NAME" \ - --arg revision "$REVISION_TAG" \ - --arg branch "$GITHUB_REF" \ - --arg digest "$digest" \ - --arg api_version "$api_version" \ - > "/tmp/$CONTAINER_NAME.json" + --arg name "$release_name" \ + --arg version_name "$VERSION_NAME" \ + --arg revision "$REVISION_TAG" \ + --arg release_time "$timestamp" \ + --arg branch "$GITHUB_REF" \ + --arg digest "$digest" \ + --arg api_version "$api_version" \ + > "/tmp/$VERSION_NAME.json" - name: Upload image metadata file to versions bucket - run: aws s3 cp "/tmp/$CONTAINER_NAME.json" "s3://$VERSIONS_BUCKET/images/$CONTAINER_NAME.json" + run: aws s3 cp "/tmp/VERSION_NAME.json" "s3://$VERSIONS_BUCKET/images/VERSION_NAME.json" - name: Notify the build pipeline that the compile containers have updated run: >- aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION diff --git a/.github/workflows/cleanup-container.yml b/.github/workflows/cleanup-container.yml index 627f93f034f3..0af80562cca1 100644 --- a/.github/workflows/cleanup-container.yml +++ b/.github/workflows/cleanup-container.yml @@ -26,7 +26,7 @@ jobs: tag="pr${PR_NUMBER}.${GITHUB_HEAD_REF}" # Replace / with . in container tag names tag="${tag//\//.}" - echo "CONTAINER_NAME=${tag}" >> $GITHUB_ENV + echo "VERSION_NAME=${tag}" >> $GITHUB_ENV id: extract_name - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 @@ -34,7 +34,7 @@ jobs: role-to-assume: arn:aws:iam::431227615537:role/GithubCompilerLambdaBuilder aws-region: us-east-1 - name: Delete the image metadata file from the versions s3 bucket - run: aws s3 rm s3://$VERSIONS_BUCKET/images/$CONTAINER_NAME.json + run: aws s3 rm s3://$VERSIONS_BUCKET/images/$VERSION_NAME.json - name: Notify the build pipeline that the compile containers have updated run: >- aws lambda invoke --function-name $UPDATE_COMPILER_VERSIONS_FUNCTION