From d824dd7b6d9e7efd68fc2a65ef1b5fe3793e7fe8 Mon Sep 17 00:00:00 2001 From: mr0xb Date: Wed, 26 Aug 2026 21:31:27 -0400 Subject: [PATCH] forgejo release workflow --- .forgejo/workflows/release.yml | 135 +++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 .forgejo/workflows/release.yml diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..e2ba980 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,135 @@ +name: Release + +on: + push: + branches: + - main + +permissions: + contents: write + +# Requires Forgejo v12+; older versions ignore this block. +concurrency: + group: release + cancel-in-progress: false + +jobs: + tag: + runs-on: ubuntu-latest + outputs: + new_tag: ${{ steps.tag.outputs.new_tag }} + steps: + - uses: https://code.forgejo.org/actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Bump version and push tag + id: tag + shell: bash + env: + DEFAULT_BUMP: patch + run: | + set -euo pipefail + git config user.name "forgejo-actions[bot]" + git config user.email "forgejo-actions[bot]@noreply.localhost" + + # Already tagged? Reuse it instead of creating a duplicate. + if existing=$(git describe --exact-match --tags HEAD 2>/dev/null); then + echo "HEAD already tagged as $existing" + echo "new_tag=$existing" >> "$GITHUB_OUTPUT" + exit 0 + fi + + latest=$(git tag -l 'v[0-9]*' --sort=-v:refname | head -n1) + if [ -z "$latest" ]; then + major=0; minor=0; patch=0 + log=$(git log --pretty=%B) + else + ver=${latest#v} + IFS=. read -r major minor patch <<< "$ver" + log=$(git log --pretty=%B "$latest..HEAD") + fi + + bump="$DEFAULT_BUMP" + case "$log" in + *'#major'*) bump=major ;; + *'#minor'*) bump=minor ;; + *'#patch'*) bump=patch ;; + esac + + case "$bump" in + major) major=$((major + 1)); minor=0; patch=0 ;; + minor) minor=$((minor + 1)); patch=0 ;; + patch) patch=$((patch + 1)) ;; + esac + + new_tag="v${major}.${minor}.${patch}" + echo "Bumping ${latest:-} -> $new_tag ($bump)" + + git tag -a "$new_tag" -m "$new_tag" + git push origin "$new_tag" + echo "new_tag=$new_tag" >> "$GITHUB_OUTPUT" + + build-and-release: + needs: tag + runs-on: ubuntu-latest + steps: + - uses: https://code.forgejo.org/actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ needs.tag.outputs.new_tag }} + + - uses: https://code.forgejo.org/actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Build release binaries + run: make build + + - name: Install UPX + run: | + set -eux + SUDO="" + [ "$(id -u)" -ne 0 ] && SUDO=sudo + $SUDO apt-get update + $SUDO apt-get install -y upx-ucl + + - name: Compress Linux binaries + run: upx --best --lzma dist/*-linux-* + + - name: Generate release notes + id: notes + shell: bash + env: + TAG: ${{ needs.tag.outputs.new_tag }} + run: | + set -euo pipefail + prev=$(git tag -l 'v[0-9]*' --sort=-v:refname | grep -vFx "$TAG" | head -n1) + if [ -n "$prev" ]; then + range="$prev..$TAG" + header="## Changes since $prev" + else + range="$TAG" + header="## Changes" + fi + { + echo "notes<<__EOF__" + echo "$header" + echo + git log --no-merges --pretty='- %s (%h)' "$range" + echo "__EOF__" + } >> "$GITHUB_OUTPUT" + + - name: Publish Forgejo release + uses: https://code.forgejo.org/actions/forgejo-release@v2 + with: + direction: upload + url: ${{ github.server_url }} + repo: ${{ github.repository }} + tag: ${{ needs.tag.outputs.new_tag }} + sha: ${{ github.sha }} + token: ${{ secrets.GITHUB_TOKEN }} + release-dir: dist + release-notes: ${{ steps.notes.outputs.notes }} + override: true + verbose: true \ No newline at end of file