Skip to content

Merge pull request #693 from re-cinq/691-dag-rework-only #1505

Merge pull request #693 from re-cinq/691-dag-rework-only

Merge pull request #693 from re-cinq/691-dag-rework-only #1505

Workflow file for this run

name: Release
on:
push:
branches: ["*"]
tags: ["v*"]
pull_request:
permissions:
contents: write
jobs:
validate:
if: "!startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: go test -race ./...
- name: Install GoReleaser
run: go install github.com/goreleaser/goreleaser/v2@latest
- name: Validate config
run: goreleaser check
- name: Test build
run: goreleaser release --snapshot --clean
auto-tag:
if: github.ref == 'refs/heads/main'
needs: validate
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.bump.outputs.next }}
tag_created: ${{ steps.push_tag.outputs.created }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version bump
id: bump
run: |
# Get the latest tag, default to v0.0.0 if none exists
LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -n1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="v0.0.0"
fi
echo "latest=$LATEST_TAG" >> "$GITHUB_OUTPUT"
# Parse current version
VERSION="${LATEST_TAG#v}"
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)
# Analyze commits since last tag to determine bump type
BUMP="patch"
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COMMITS=$(git log --oneline --format="%s")
else
COMMITS=$(git log "${LATEST_TAG}..HEAD" --oneline --format="%s")
fi
if echo "$COMMITS" | grep -qE '!:|BREAKING CHANGE'; then
BUMP="major"
elif echo "$COMMITS" | grep -qE '^feat(\(.+\))?:'; then
BUMP="minor"
fi
# Calculate next version
case "$BUMP" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEXT="v${MAJOR}.${MINOR}.${PATCH}"
echo "next=$NEXT" >> "$GITHUB_OUTPUT"
echo "bump=$BUMP" >> "$GITHUB_OUTPUT"
echo "Bump: $BUMP ($LATEST_TAG → $NEXT)"
- name: Create and push tag
id: push_tag
if: steps.bump.outputs.next != steps.bump.outputs.latest
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.bump.outputs.next }}" -m "Release ${{ steps.bump.outputs.next }}"
git push origin "${{ steps.bump.outputs.next }}"
echo "created=true" >> "$GITHUB_OUTPUT"
# Runs after auto-tag in the same workflow (GITHUB_TOKEN tag pushes don't trigger new runs).
# Also runs independently when a tag is pushed manually.
release:
if: >-
always() && (
startsWith(github.ref, 'refs/tags/')
|| (needs.auto-tag.result == 'success' && needs.auto-tag.outputs.tag_created == 'true')
)
needs: [auto-tag]
runs-on: ubuntu-latest
steps:
- name: Checkout at tag
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.auto-tag.outputs.new_tag || github.ref }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ needs.auto-tag.outputs.new_tag || github.ref_name }}