From 0d221914c08816cad51033274dd51a897d7e4900 Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Thu, 17 Apr 2025 14:07:00 +0200 Subject: [PATCH] feat: add building old patch from custom branch Option to input tag and branch to avoid local git gymnstics Ensures the workflow fails appropriately when git pull --rebase fails instead of silently continuing execution. This prevents downstream build errors and makes troubleshooting easier when the rebase fails. Signed-off-by: rjshrjndrn --- .github/workflows/patch-build-old.yaml | 28 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/patch-build-old.yaml b/.github/workflows/patch-build-old.yaml index 719f2bfdb..c6da83c0e 100644 --- a/.github/workflows/patch-build-old.yaml +++ b/.github/workflows/patch-build-old.yaml @@ -7,8 +7,12 @@ on: description: 'Comma separated names of services to build(in small letters).' required: true default: 'chalice,frontend' + branch: + description: 'branch to build patches from.' + required: true + type: string tag: - description: 'Tag to build patches from.' + description: 'Tag to update using the branch.' required: true type: string @@ -26,7 +30,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 4 - ref: ${{ github.event.inputs.tag }} + ref: ${{ github.event.inputs.branch }} - name: Set Remote with GITHUB_TOKEN run: | @@ -36,11 +40,14 @@ jobs: - name: Create backup tag with timestamp run: | set -e # Exit immediately if a command exits with a non-zero status + TIMESTAMP=$(date +%Y%m%d%H%M%S) BACKUP_TAG="${{ github.event.inputs.tag }}-backup-${TIMESTAMP}" echo "BACKUP_TAG=${BACKUP_TAG}" >> $GITHUB_ENV echo "INPUT_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV - git tag $BACKUP_TAG || { echo "Failed to create backup tag"; exit 1; } + echo "INPUT_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + + git tag $BACKUP_TAG $INPUT_TAG || { echo "Failed to create backup tag"; exit 1; } git push origin $BACKUP_TAG || { echo "Failed to push backup tag"; exit 1; } echo "Created backup tag: $BACKUP_TAG" @@ -51,6 +58,14 @@ jobs: NEW_TIMESTAMP=$((OLDEST_COMMIT_TIMESTAMP + 1)) echo "NEW_TIMESTAMP=$NEW_TIMESTAMP" >> $GITHUB_ENV + echo "HEAD_COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: rebasing tag + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git fetch origin --tags -f + git rebase $INPUT_TAG || { echo "Failed to pull and rebase from branch $INPUT_BRANCH with tag $INPUT_TAG"; exit 1; } - name: Setup yq uses: mikefarah/yq@master @@ -70,10 +85,6 @@ jobs: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.RELEASE_OSS_REGISTRY }} - uses: depot/setup-action@v1 - - name: Get HEAD Commit ID - run: echo "HEAD_COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_ENV - - name: Define Branch Name - run: echo "BRANCH_NAME=patch/main/${HEAD_COMMIT_ID}" >> $GITHUB_ENV - name: Build id: build-image @@ -85,9 +96,6 @@ jobs: MSAAS_REPO_FOLDER: /tmp/msaas run: | set -exo pipefail - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git checkout -b $BRANCH_NAME working_dir=$(pwd) function image_version(){ local service=$1