From 814feae6a905786a3bf0589996f9cb12cc4533c2 Mon Sep 17 00:00:00 2001 From: Victor Hugo Vargas Date: Thu, 30 Jul 2026 22:30:16 -0700 Subject: [PATCH] build: introduce VERSION file and tag-driven release - VERSION file at repo root is the source of truth - main.version is now a var, overridable via -ldflags - release workflow triggers on tag push and validates tag == VERSION - manual bump flow: bump VERSION, commit, tag, push --- .github/workflows/release.yml | 56 +++++++---------------------------- VERSION | 1 + cmd/chat-bot/main.go | 5 +++- 3 files changed, 16 insertions(+), 46 deletions(-) create mode 100644 VERSION diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cee39aa..f73ae00 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,18 +2,12 @@ name: Release on: push: - branches: - - main - paths-ignore: - - '.github/workflows/**' + tags: + - 'v*.*.*' permissions: contents: write -concurrency: - group: release - cancel-in-progress: false - jobs: release: runs-on: ubuntu-latest @@ -23,51 +17,23 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - name: Bump version and push tag - id: bump - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Verify tag matches VERSION run: | set -euo pipefail - git fetch --tags --force - - if git describe --tags --exact-match HEAD >/dev/null 2>&1; then - echo "HEAD is already tagged, skipping bump" - exit 0 - fi - - latest=$(git tag --sort=-v:refname --list 'v*.*.*-alpha' | head -n 1) - if [ -z "$latest" ]; then - echo "::error::No tag matching vX.Y.Z-alpha pattern found" + tag="${GITHUB_REF_NAME#v}" + file_version=$(tr -d '[:space:]' < VERSION) + if [ "$tag" != "$file_version" ]; then + echo "::error::Tag v$tag does not match VERSION file ($file_version)" + echo "Bump VERSION first, then tag and push." exit 1 fi - echo "Latest tag: $latest" - - version="${latest#v}" - version="${version%-alpha}" - IFS='.' read -r major minor patch <<< "$version" - new_version="${major}.${minor}.$((patch + 1))-alpha" - new_tag="v${new_version}" - - if git rev-parse "$new_tag" >/dev/null 2>&1; then - echo "::error::Tag $new_tag already exists" - exit 1 - fi - - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git tag -a "$new_tag" -m "Release $new_tag" - git push origin "$new_tag" - - echo "tag=$new_tag" >> "$GITHUB_OUTPUT" + echo "VERSION=$file_version OK" - name: Create GitHub release - if: steps.bump.outputs.tag uses: softprops/action-gh-release@v2 with: - tag_name: ${{ steps.bump.outputs.tag }} - name: ${{ steps.bump.outputs.tag }} + tag_name: ${{ github.ref_name }} + name: ${{ github.ref_name }} prerelease: true generate_release_notes: true diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..388bb06 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0-alpha diff --git a/cmd/chat-bot/main.go b/cmd/chat-bot/main.go index 9fb5955..31dbd9d 100644 --- a/cmd/chat-bot/main.go +++ b/cmd/chat-bot/main.go @@ -23,7 +23,10 @@ import ( "github.com/VictorVargas/rony-chat-bot/internal/server" ) -const version = "0.2.0-dev" +// Override at build time: +// +// go build -ldflags "-X main.version=$(cat VERSION)" -o bin/chat-bot ./cmd/chat-bot +var version = "dev" var ( cfgFile string