aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-02-12 04:17:10 +0100
committerOnur Gündüz <ogunduz@gmail.com>2026-02-12 04:17:10 +0100
commitac66a7f3305a44721d84a4938e951fdaf1eb7c1f (patch)
tree0239df7a4df76414e59956bd679b32eb40054a6c /.github/workflows/release.yml
parenta057d33890da4ddb1d10067a3f4beb1f77a9c886 (diff)
downloadmp4-ac66a7f3305a44721d84a4938e951fdaf1eb7c1f.tar.gz
mp4-ac66a7f3305a44721d84a4938e951fdaf1eb7c1f.zip
Add GitHub Actions release workflow
Diffstat (limited to '.github/workflows/release.yml')
-rw-r--r--.github/workflows/release.yml113
1 files changed, 113 insertions, 0 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..8a91e96
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,113 @@
+name: release
+
+concurrency:
+ group: release-${{ github.head_ref }}
+ cancel-in-progress: true
+on:
+ workflow_dispatch:
+ inputs:
+ version:
+ description: "Impact"
+ required: true
+ default: 'patch'
+ type: choice
+ options:
+ - minor
+ - patch
+jobs:
+ linux:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ go-version: [1.25.x]
+
+ steps:
+ - name: Set up Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: ${{ matrix.go-version }}
+ id: go
+
+ - name: Check out code
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Run tests
+ run: go test ./...
+
+ - name: Release
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ set -euxo pipefail
+
+ MAJOR=$(echo "$GITHUB_REF_NAME" | sed -nE 's/^v([0-9]+)\.x$/\1/p')
+ if [[ -z "$MAJOR" ]]; then
+ echo "Invalid branch name format (expected vX.x)" >&2
+ exit 1
+ fi
+
+ next_version () {
+ local current impact MINOR PATCH
+ impact="${1:-patch}"
+
+ current=$(git tag | grep "^v$MAJOR\.[0-9]*\.[0-9]*" | sort -t "." -k1,1nr -k2,2nr -k3,3nr | cut -c2- | head -1) || true
+
+ if [[ -z "$current" ]]; then
+ if [[ "$MAJOR" -eq 0 ]]; then
+ echo "0.1.0"
+ else
+ echo "$MAJOR.0.0"
+ fi
+ return
+ fi
+
+ IFS='.' read -r _ MINOR PATCH <<< "$current"
+
+ case "$impact" in
+ major)
+ ((MAJOR+=1))
+ MINOR=0
+ PATCH=0
+ ;;
+ minor)
+ ((MINOR+=1))
+ PATCH=0
+ ;;
+ patch)
+ ((PATCH+=1))
+ ;;
+ *)
+ echo "Invalid impact: $impact" >&2
+ exit 1
+ ;;
+ esac
+
+ echo "$MAJOR.$MINOR.$PATCH"
+ }
+
+ push_release () {
+ local commit next
+
+ commit=$(git rev-parse HEAD)
+
+ if git tag --points-at "$commit" | grep -q .; then
+ echo "Commit already tagged, skipping release"
+ return
+ fi
+
+ next="v$(next_version "${1:-patch}")"
+
+ git config user.name github-actions
+ git config user.email github-actions@github.com
+
+ git tag "$next"
+ git push --tags
+
+ echo "BUILD_VERSION=$next" >> "$GITHUB_ENV"
+ }
+
+ git fetch --all --tags
+
+ push_release minor