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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
tags:
|
||||||
- main
|
- 'v*.*.*'
|
||||||
paths-ignore:
|
|
||||||
- '.github/workflows/**'
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: release
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -23,51 +17,23 @@ jobs:
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Bump version and push tag
|
- name: Verify tag matches VERSION
|
||||||
id: bump
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
git fetch --tags --force
|
tag="${GITHUB_REF_NAME#v}"
|
||||||
|
file_version=$(tr -d '[:space:]' < VERSION)
|
||||||
if git describe --tags --exact-match HEAD >/dev/null 2>&1; then
|
if [ "$tag" != "$file_version" ]; then
|
||||||
echo "HEAD is already tagged, skipping bump"
|
echo "::error::Tag v$tag does not match VERSION file ($file_version)"
|
||||||
exit 0
|
echo "Bump VERSION first, then tag and push."
|
||||||
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"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Latest tag: $latest"
|
echo "VERSION=$file_version OK"
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
- name: Create GitHub release
|
- name: Create GitHub release
|
||||||
if: steps.bump.outputs.tag
|
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ steps.bump.outputs.tag }}
|
tag_name: ${{ github.ref_name }}
|
||||||
name: ${{ steps.bump.outputs.tag }}
|
name: ${{ github.ref_name }}
|
||||||
prerelease: true
|
prerelease: true
|
||||||
generate_release_notes: 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"
|
"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 (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue