Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ on:
tags:
- "v*"

# Ceiling for the whole workflow, including the called test.yml — a
# reusable workflow can only reduce permissions from its caller, never
# elevate them. Omitting this block entirely (rather than setting it
# to `read`) does NOT mean read-only; it falls back to the repo's
# default GITHUB_TOKEN permissions, which for this repo is a wide set
# of write scopes.
permissions:
contents: write
contents: read

jobs:
# A tag push has no relation to the test workflow (that only triggers
# on push:branches/pull_request) — without this gate, goreleaser
# would publish from a tagged commit whose tests never ran, or
# failed. `just release` checks version.txt/clean-tree/tag-existence
# but not CI status, so this has to hold regardless of how the tag
# was created. Reused from test.yml (rather than duplicated) so the
# two can't drift out of sync.
test:
uses: ./.github/workflows/test.yml

goreleaser:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ on:
push:
branches: [master]
pull_request:
workflow_call:

# This also covers the direct push/pull_request triggers, not just
# the workflow_call path from release.yml — the repo's default
# GITHUB_TOKEN permissions are a wide set of write scopes, and this
# job only ever needs to read.
permissions:
contents: read

jobs:
test:
Expand All @@ -16,4 +24,6 @@ jobs:
- run: go build ./...
- run: go vet ./...
- run: go test ./...
- run: gofmt -l . | tee /tmp/fmt.out && test ! -s /tmp/fmt.out
- name: gofmt
shell: bash
run: gofmt -l . | tee /tmp/fmt.out && test ! -s /tmp/fmt.out
11 changes: 10 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,22 @@ release-pr VERSION:
[[ "{{VERSION}}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "✗ version must be X.Y.Z (no leading v), got '{{VERSION}}'"; exit 1; }
[ -z "$(git status --porcelain)" ] || { echo "✗ working tree not clean"; exit 1; }
git fetch origin
if [ "$(git show origin/master:version.txt | tr -d '[:space:]')" = "{{VERSION}}" ]; then
echo "✗ version.txt on master is already {{VERSION}} — nothing to bump; run: just release {{VERSION}}"
exit 1
fi
git ls-remote --exit-code --heads origin "release/v{{VERSION}}" >/dev/null 2>&1 && \
{ echo "✗ release/v{{VERSION}} already on origin — open the PR with: gh pr create --head release/v{{VERSION}} (or delete it: git push -d origin release/v{{VERSION}})"; exit 1; }
trap 'git checkout master 2>/dev/null; git branch -D "release/v{{VERSION}}" 2>/dev/null || true' EXIT
git checkout -b "release/v{{VERSION}}" origin/master
echo "{{VERSION}}" > version.txt
git add version.txt
git commit -m "Release v{{VERSION}}"
git push -u origin "release/v{{VERSION}}"
trap - EXIT
gh pr create --title "Release v{{VERSION}}" \
--body "Bumps version.txt to {{VERSION}}. After merge: \`just release {{VERSION}}\` tags master and CI publishes the release."
--body "Bumps version.txt to {{VERSION}}. After merge: \`just release {{VERSION}}\` tags master and CI publishes the release." \
|| { echo "✗ branch pushed but PR creation failed — finish with: gh pr create --head release/v{{VERSION}}"; exit 1; }
echo "✓ release PR opened — merge it, then run: just release {{VERSION}}"

# Local test-build of the release pipeline — same artifacts as a real
Expand Down
Loading