From b2e961d621338979857a5d2810ea0d078a3e4f45 Mon Sep 17 00:00:00 2001 From: Rajesh Rajendran Date: Mon, 12 May 2025 15:49:19 +0200 Subject: [PATCH] ci(actions): Auto update tag for patch build (#3386) Signed-off-by: rjshrjndrn --- .github/workflows/update-tag.yaml | 45 +++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/update-tag.yaml b/.github/workflows/update-tag.yaml index 7016d7019..c733fa7aa 100644 --- a/.github/workflows/update-tag.yaml +++ b/.github/workflows/update-tag.yaml @@ -1,35 +1,58 @@ on: workflow_dispatch: - description: "This workflow will build for patches for latest tag, and will Always use commit from main branch." inputs: services: description: "This action will update the latest tag with current main branch HEAD. Should I proceed ? true/false" required: true default: "false" + push: + branches: + - main -name: Force Push tag with main branch HEAD +name: Release tag update --force jobs: deploy: name: Build Patch from main runs-on: ubuntu-latest - env: - DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }} - DEPOT_PROJECT_ID: ${{ secrets.DEPOT_PROJECT_ID }} + if: ${{ github.event_name == 'push' || github.event.inputs.services == 'true' }} steps: - name: Checkout uses: actions/checkout@v2 + + - name: Get latest release tag using GitHub API + id: get-latest-tag + run: | + LATEST_TAG=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases/latest" \ + | jq -r .tag_name) + + GIT_LATEST_TAG=$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1) + # Fallback to git command if API doesn't return a tag + if [ "$LATEST_TAG" == "null" ] || [ -z "$LATEST_TAG" ]; then + echo "Not found latest tag" + exit 100 + fi + if [ "$GIT_LATEST_TAG" == "null" ] || [ -z "$GIT_LATEST_TAG" ]; then + echo "Not found git latest tag" + exit 100 + fi + if [ "$GIT_LATEST_TAG" != "$LATEST_TAG" ]; then + echo "Latest tag in git repo doesn't match latest tag in GitHub. Exiting." + exit 100 + fi + + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV + echo "Latest tag: $LATEST_TAG" + - name: Set Remote with GITHUB_TOKEN run: | git config --unset http.https://github.com/.extraheader git remote set-url origin https://x-access-token:${{ secrets.ACTIONS_COMMMIT_TOKEN }}@github.com/${{ github.repository }}.git + - name: Push main branch to tag run: | git fetch --tags git checkout main - git push origin HEAD:refs/tags/$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1) --force - # - name: Debug Job - # if: ${{ failure() }} - # uses: mxschmitt/action-tmate@v3 - # with: - # limit-access-to-actor: true + echo "Updating tag ${{ env.LATEST_TAG }} to point to latest commit on main" + git push origin HEAD:refs/tags/${{ env.LATEST_TAG }} --force