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
This commit is contained in:
parent
9ec0f4749d
commit
814feae6a9
3 changed files with 16 additions and 46 deletions
56
.github/workflows/release.yml
vendored
56
.github/workflows/release.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
1
VERSION
Normal file
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.1.0-alpha
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue