From f7832f39366f8ae8c8e9f1a125bb1359fd286a76 Mon Sep 17 00:00:00 2001 From: sharansalian Date: Fri, 10 May 2024 11:07:22 +0530 Subject: [PATCH] Update workflow --- .github/workflows/on_merge_main.yml | 51 ++++++++++------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/.github/workflows/on_merge_main.yml b/.github/workflows/on_merge_main.yml index b803c80..fc9ebd9 100644 --- a/.github/workflows/on_merge_main.yml +++ b/.github/workflows/on_merge_main.yml @@ -1,40 +1,25 @@ -name: Create Tag on Merge - +name: "Tag on Pull Request merge" on: - push: + # Should trigger only when a Pull Request is Closed + # (the action will not create the Tag if the Pull Request is discarded - closed without merge) + pull_request: + types: + - closed branches: - main jobs: - create-tag: + TagOnPR: + name: Tag on Pull Request merge runs-on: ubuntu-latest - + # This 'if' condition is important for ensuring the workflow only runs for merged PRs + # (avoid running when a PR is discarded - closed without merging) + if: github.event.pull_request.merged == true steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Get latest tag (if available) - id: get-tag - run: | - if latest_tag=$(git describe --tags --abbrev=0 2>/dev/null); then - echo "::set-output name=tag::$latest_tag" - else - echo "::set-output name=tag::" - fi - - - name: Create Tag - if: steps.get-tag.outputs.tag != '' - run: | - tag_version=$(echo "${{ steps.get-tag.outputs.tag }}" | grep -oP '\d+\.\d+\.\d+') - IFS='.' read -r major minor patch <<< "$tag_version" - new_minor=$((minor + 1)) - new_tag_version="$major.$new_minor.$patch" - git tag -a "$new_tag_version" -m "Automated tag creation on branch merge" - git push origin "$new_tag_version" - - - name: Clean up - if: steps.get-tag.outputs.tag != '' - run: | - git fetch --tags - git tag -d "$new_tag_version" - git push origin ":refs/tags/$new_tag_version" + - name: Tag on PR merge + id: tag-on-pr-merge + uses: David-Lor/action-tag-on-pr-merge@main + with: + push-tag: true + - name: Print fetched tag + run: echo "${{ steps.tag-on-pr-merge.outputs.tag }}" \ No newline at end of file