From ad405e4d0222397966f4cc367ecac10967680f75 Mon Sep 17 00:00:00 2001 From: Sarbagya Dhaubanjar Date: Wed, 23 Apr 2025 20:51:31 +0545 Subject: [PATCH] Refactor GitHub Actions workflows to use semver-tag for versioning and streamline tag generation --- .github/workflows/dev.yml | 33 ++++++++++++-------------------- .github/workflows/main.yml | 32 ++++++++++++------------------- .github/workflows/pr-version.yml | 29 ++++++++++++++++------------ 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index b5ce0eb..1a8f329 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -20,43 +20,34 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Perform semantic version - uses: paulhatch/semantic-version@v5.4.0 - id: versioning + - name: Generate Next Tag + uses: AcmeSoftwareLLC/semver-tag@v1 + id: semver with: - tag_prefix: v - major_pattern: "(MAJOR)" - minor_pattern: "(MINOR)" - version_format: "${major}.${minor}.${patch}-rc" - bump_each_commit: false - search_commit_body: true - namespace: rc + token: ${{ secrets.GITHUB_TOKEN }} + level: patch - name: Bump version and push tag - id: tag_version + id: tag_action uses: mathieudutour/github-tag-action@v6.2 with: - custom_tag: ${{ steps.versioning.outputs.version_tag }} - tag_prefix: "" + custom_tag: ${{ steps.semver.outputs.next_tag }} github_token: ${{ secrets.GITHUB_TOKEN }} - name: Build Changelog id: changelog uses: mikepenz/release-changelog-builder-action@v5 with: - fromTag: v${{ steps.versioning.outputs.previous_version }} - toTag: ${{ steps.tag_version.outputs.new_tag }} + fromTag: v${{ steps.semver.outputs.prev_tag }} + toTag: ${{ steps.tag_action.outputs.new_tag }} fetchReviewers: true - - name: Create production release + - name: Create dev release uses: ncipollo/release-action@v1 id: release with: - tag: ${{ steps.tag_version.outputs.new_tag }} - name: ${{ steps.versioning.outputs.version_tag }} + tag: ${{ steps.tag_action.outputs.new_tag }} + name: ${{ steps.tag_action.outputs.new_tag }} body: ${{ steps.changelog.outputs.changelog }} - commit: ${{ steps.versioning.outputs.current_commit }} prerelease: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4bd7800..1b14835 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,41 +20,33 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Perform semantic version - uses: paulhatch/semantic-version@v5.4.0 - id: versioning + - name: Generate Next Tag + uses: AcmeSoftwareLLC/semver-tag@v1 + id: semver with: - tag_prefix: v - major_pattern: "(MAJOR)" - minor_pattern: "(MINOR)" - version_format: "${major}.${minor}.${patch}" - bump_each_commit: false - search_commit_body: true + token: ${{ secrets.GITHUB_TOKEN }} + level: minor - name: Bump version and push tag - id: tag_version + id: tag_action uses: mathieudutour/github-tag-action@v6.2 with: - custom_tag: ${{ steps.versioning.outputs.version_tag }} - tag_prefix: "" + custom_tag: ${{ steps.semver.outputs.next_tag }} github_token: ${{ secrets.GITHUB_TOKEN }} - name: Build Changelog id: changelog uses: mikepenz/release-changelog-builder-action@v5 with: - fromTag: v${{ steps.versioning.outputs.previous_version }} - toTag: ${{ steps.tag_version.outputs.new_tag }} + fromTag: v${{ steps.semver.outputs.prev_tag }} + toTag: ${{ steps.tag_action.outputs.new_tag }} fetchReviewers: true - - name: Create production release + - name: Create main release uses: ncipollo/release-action@v1 id: release with: - tag: ${{ steps.tag_version.outputs.new_tag }} - name: ${{ steps.versioning.outputs.version_tag }} + tag: ${{ steps.tag_action.outputs.new_tag }} + name: ${{ steps.tag_action.outputs.new_tag }} body: ${{ steps.changelog.outputs.changelog }} - commit: ${{ steps.versioning.outputs.current_commit }} diff --git a/.github/workflows/pr-version.yml b/.github/workflows/pr-version.yml index acd7c4e..404f8f8 100644 --- a/.github/workflows/pr-version.yml +++ b/.github/workflows/pr-version.yml @@ -21,22 +21,27 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Perform semantic version - uses: paulhatch/semantic-version@v5.4.0 - id: versioning + - name: Determine Increment Level + id: increment + run: | + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "level=minor" >> $GITHUB_OUTPUT + elif [[ "${{ github.event.pull_request.base.ref }}" == "develop" ]]; then + echo "level=patch" >> $GITHUB_OUTPUT + else + echo "level=patch" >> $GITHUB_OUTPUT + fi + + - name: Generate Next Tag + uses: AcmeSoftwareLLC/semver-tag@v1 + id: semver with: - tag_prefix: "v" - major_pattern: "(MAJOR)" - minor_pattern: "(MINOR)" - version_format: "${major}.${minor}.${patch}-rc${increment}" - bump_each_commit: false - search_commit_body: true + token: ${{ secrets.GITHUB_TOKEN }} + level: ${{ steps.increment.outputs.level }} - name: Comment PR uses: thollander/actions-comment-pull-request@v3 with: message: | - :rocket: The next version will be **${{ steps.versioning.outputs.version_tag }}** ! :rocket: + :rocket: The next version will be **${{ steps.semver.outputs.next_tag }}** ! :rocket: