name: Release on: push: branches: - main # Requires Forgejo v12+; older versions ignore this block. concurrency: group: release cancel-in-progress: false jobs: tag: runs-on: debian outputs: new_tag: ${{ steps.tag.outputs.new_tag }} steps: - uses: https://git.sbriggs.io/actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a 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: debian steps: #- uses: https://code.forgejo.org/actions/checkout@v4 - uses: https://git.sbriggs.io/actions/checkout@f548e57e544e1ff5a4c46bf1e1b8685f8e4a348a 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: 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://git.sbriggs.io/actions/forgejo-release@585a6614e80a6bcfc429b956ae34831889cabb78 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