Skip to content

Commit e24a141

Browse files
committed
fix: update release workflow to work with dynamic version injection
- Remove hardcoded version extraction from source code - Use git tags to determine current version - Remove unnecessary source code updates since version is injected at build time - Simplify tag creation process
1 parent b730581 commit e24a141

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

.github/workflows/release.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ jobs:
3232
- name: Create Tag
3333
id: create_tag
3434
run: |
35-
# Extract current version from version command
36-
CURRENT_VERSION=$(grep -o 'commitron v[0-9]\+\.[0-9]\+\.[0-9]\+' cmd/commitron/commands.go | head -1 | sed 's/commitron v//')
37-
if [ -z "$CURRENT_VERSION" ]; then
38-
CURRENT_VERSION="0.1.0" # Default if no version found
39-
fi
40-
35+
# Get the latest tag or start with 0.1.0
36+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0")
37+
CURRENT_VERSION=$(echo $LATEST_TAG | sed 's/v//')
38+
4139
# Split the version into components
4240
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
4341
@@ -54,18 +52,10 @@ jobs:
5452
git config --global user.name "github-actions[bot]"
5553
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
5654
57-
# Update version in code
58-
awk -v new_version="$NEW_VERSION" '{gsub(/commitron v[0-9]+\.[0-9]+\.[0-9]+/, "commitron v" new_version); print}' cmd/commitron/commands.go > cmd/commitron/commands.go.tmp && mv cmd/commitron/commands.go.tmp cmd/commitron/commands.go
59-
60-
# Commit the version change
61-
git add cmd/commitron/commands.go
62-
git commit -m "Bump version to $NEW_VERSION [skip ci]"
63-
64-
# Create and push the tag
55+
# Create and push the tag (no need to update source code since version is injected at build time)
6556
git tag $TAG_VERSION
6657
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
6758
git push origin $TAG_VERSION
68-
git push origin HEAD
6959
7060
echo "Created and pushed tag $TAG_VERSION"
7161
@@ -103,7 +93,7 @@ jobs:
10393
VERSION="${{ needs.tag-and-release.outputs.new_version }}"
10494
COMMIT_SHA="${{ github.sha }}"
10595
BUILD_DATE="$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
106-
96+
10797
go build -v \
10898
-ldflags "-X github.com/johnstilia/commitron/pkg/version.Version=$VERSION \
10999
-X github.com/johnstilia/commitron/pkg/version.CommitSHA=$COMMIT_SHA \

0 commit comments

Comments
 (0)