From 772797206dac4a0684f0ce4035ed56af82f6279a Mon Sep 17 00:00:00 2001 From: deggja Date: Sun, 26 May 2024 11:33:49 +0200 Subject: [PATCH] chore: update version bumping script and release workflow Signed-off-by: deggja --- .github/scripts/bump_version.sh | 22 +++++++++++++++------- .github/workflows/release.yml | 8 ++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/scripts/bump_version.sh b/.github/scripts/bump_version.sh index 3d2302d..4a88d5f 100755 --- a/.github/scripts/bump_version.sh +++ b/.github/scripts/bump_version.sh @@ -14,6 +14,8 @@ if [ ! -z "$latest_tag" ]; then IFS='.' read -r major minor patch <<< "${latest_tag}" fi +new_tag="$major.$minor.$patch" + # Analyze commit messages since the last tag for versioning for commit in $(git rev-list $latest_tag..HEAD); do message=$(git log --format=%B -n 1 $commit) @@ -22,20 +24,26 @@ for commit in $(git rev-list $latest_tag..HEAD); do let major+=1 minor=0 patch=0 + new_tag="${major}.${minor}.${patch}" break elif [[ $message == *"#minor"* ]]; then let minor+=1 patch=0 + new_tag="${major}.${minor}.${patch}" elif [[ $message == *"#patch"* ]]; then let patch+=1 + new_tag="${major}.${minor}.${patch}" fi done -new_tag="${major}.${minor}.${patch}" - -# Set output for the next steps using environment file -echo "new_tag=$new_tag" >> $GITHUB_ENV +# Check if new version is different from the latest tag +if [ "$new_tag" != "$latest_tag" ]; then + # Set output for the next steps using environment file + echo "new_tag=$new_tag" >> $GITHUB_ENV -# Create the new tag -git tag $new_tag -git push --tags + # Create the new tag + git tag $new_tag + git push --tags +else + echo "new_tag=" >> $GITHUB_ENV +fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 745e1e5..fe019f1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,8 +33,16 @@ jobs: run: | chmod +x .github/scripts/bump_version.sh .github/scripts/bump_version.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Application + if: env.new_tag != '' + run: | + go build -ldflags "-X 'github.com/deggja/netfetch/backend/cmd.Version=${{ env.new_tag }}'" -o netfetch - name: Run GoReleaser + if: env.new_tag != '' uses: goreleaser/goreleaser-action@v2 with: version: latest