From 8adb9a56611f00cc7e036790c4e36367f6b6b870 Mon Sep 17 00:00:00 2001 From: rjshrjndrn Date: Mon, 12 May 2025 15:45:28 +0200 Subject: [PATCH] ci(actions): Auto update tag for patch build Signed-off-by: rjshrjndrn --- .github/workflows/update-tag.yaml | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/update-tag.yaml b/.github/workflows/update-tag.yaml index 7016d7019..ec683c5a7 100644 --- a/.github/workflows/update-tag.yaml +++ b/.github/workflows/update-tag.yaml @@ -1,35 +1,49 @@ 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) + + # 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 + + 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