Skip to content

Commit

Permalink
chore: update version bumping script and release workflow
Browse files Browse the repository at this point in the history
Signed-off-by: deggja <danieldagfinrud@gmail.com>
  • Loading branch information
deggja committed May 26, 2024
1 parent 4082070 commit 7727972
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/scripts/bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7727972

Please sign in to comment.