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
20 changes: 20 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Categories for the notes `gh release create --generate-notes` writes (the Release
# workflow). A merged PR lands in the first category whose label it carries.
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: Plugins
labels:
- plugin
- enhancement
- title: Fixes
labels:
- bug
- title: Docs
labels:
- documentation
- title: Other changes
labels:
- "*"
146 changes: 146 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Release: tag main's HEAD with the next version and publish a GitHub release.
#
# A maintainer runs it by hand: Actions -> Release -> Run workflow -> pick the bump.
# It never runs on push, on a schedule or on a PR.
#
# patch v0.4.1 -> v0.4.2 fixes, new providers on an existing format plugin
# minor v0.4.1 -> v0.5.0 new format plugins, new exported API, anything a user should read about
# (no tag yet -> v0.1.0)
#
# v1.0.0 and later majors are not an option here: they are a deliberate decision a
# maintainer makes by hand, not a button.
#
# Fail closed: the leak guard, gitleaks, build, vet, gofmt and the tests run on the exact
# commit being tagged, and any failure stops the run before a tag exists.
#
# NEVER delete or move a pushed tag. Go's module proxy (proxy.golang.org) and checksum
# database remember every version forever, so a moved tag breaks everyone who already
# fetched it. If a release is wrong, fix it on main and release a new patch version.
name: Release

on:
workflow_dispatch:
inputs:
bump:
description: "Which part of the version to bump (patch: fixes and providers; minor: new format plugins or API)"
type: choice
options:
- patch
- minor
default: patch

permissions:
contents: write

# One release at a time; a second run waits instead of cancelling the first.
concurrency:
group: release
cancel-in-progress: false

env:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb

jobs:
release:
name: tag and release main
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: only from main
if: github.ref != 'refs/heads/main'
env:
REF: ${{ github.ref }}
run: |
echo "::error::Run the Release workflow from main, not $REF."
exit 1

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
fetch-tags: true

- name: next version
id: version
env:
BUMP: ${{ inputs.bump }}
run: |
head=$(git rev-parse HEAD)
existing=$(git tag --points-at "$head")
if [ -n "$existing" ]; then
echo "::error::main's HEAD ($head) is already tagged: $existing. Nothing new to release."
exit 1
fi

latest=$(git tag -l 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1 || true)
if [ -z "$latest" ]; then
next=v0.1.0
else
IFS=. read -r major minor patch <<< "${latest#v}"
case "$BUMP" in
patch) next="v${major}.${minor}.$((patch + 1))" ;;
minor) next="v${major}.$((minor + 1)).0" ;;
*) echo "::error::unknown bump '$BUMP'"; exit 1 ;;
esac
fi

if git rev-parse -q --verify "refs/tags/$next" >/dev/null; then
echo "::error::$next already exists."
exit 1
fi
echo "latest=${latest:-none}, bump=$BUMP -> $next at $head"
echo "tag=$next" >> "$GITHUB_OUTPUT"
echo "sha=$head" >> "$GITHUB_OUTPUT"

- name: internal names (hashed), whole tree
run: python3 scripts/leak_guard.py --all

- name: install gitleaks ${{ env.GITLEAKS_VERSION }}
run: |
tarball="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -fsSL -o "$RUNNER_TEMP/$tarball" "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${tarball}"
echo "${GITLEAKS_SHA256} $RUNNER_TEMP/$tarball" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/$tarball" -C "$RUNNER_TEMP" gitleaks

- name: gitleaks, whole history
run: '"$RUNNER_TEMP/gitleaks" git --no-banner --redact --verbose .'

- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
cache-dependency-path: go.sum

- name: go build
run: go build ./...

- name: go vet
run: go vet ./...

- name: gofmt
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "::error::not gofmt-formatted:"; echo "$unformatted"; exit 1
fi

- name: go test
run: go test -race -count=1 ./...

# Only reached when every check above passed.
- name: create and push the annotated tag
env:
TAG: ${{ steps.version.outputs.tag }}
SHA: ${{ steps.version.outputs.sha }}
ACTOR: ${{ github.actor }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" "$SHA" -m "$TAG" -m "Released by @$ACTOR with the Release workflow."
git push origin "refs/tags/$TAG"

- name: publish the GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: gh release create "$TAG" --verify-tag --generate-notes --title "$TAG"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: if this step fails after the tag push succeeds (a GitHub API error, for example), the run leaves a tag with no release. Re-running won't fix it, because the next version step refuses when HEAD is already tagged. You could add a one-liner to CONTRIBUTING's Releasing section: "if the tag exists but the release doesn't, run gh release create <tag> --verify-tag --generate-notes". That still follows the "never move a tag" rule.

7 changes: 6 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ docs/plugins.md the list of supported plugins (Rule 1)
docs/ contributor docs, including writing-a-plugin.md
providers/<api>.md one page per provider
scripts/ leak_guard.py (hashed internal names), check_contract.py
.github/ CODEOWNERS, PR template, workflows (CI_go, CI_dco, CI_leak_guard, CI_contract)
.github/ CODEOWNERS, PR template, release-notes categories, workflows
(CI_go, CI_dco, CI_leak_guard, CI_contract, Release)
```

The [change-event contract](https://github.com/patch-it-dev/patch-it/tree/main/docs/contract) is owned by patch-it: don't change `contract/fixtures/` here first.
Expand All @@ -71,3 +72,7 @@ The [change-event contract](https://github.com/patch-it-dev/patch-it/tree/main/d
- One plugin or fix per PR; fill in every checkbox of the PR template, including "added to docs/plugins.md".
- AI-assisted commits keep their co-author trailer.
- Never re-run, dispatch or retrigger CI to "see if it passes"; fix the cause and push.

## Releases

Agents never tag or release. A maintainer runs the **Release** workflow (see [CONTRIBUTING.md](CONTRIBUTING.md#releasing)). Never delete or move a tag.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ That adds `Signed-off-by: Your Name <you@example.com>`, matching the commit's au
| `CI_dco` | Every commit in the PR is signed off by its author |
| `CI_leak_guard` | gitleaks over the PR's commits, and a check for known internal names (stored as hashes only). Also runs weekly over the whole repo |
| `Claude Code Review` | Claude reviews the PR against the rules above, once (PRs from this repo's branches; forks: a maintainer comments `@claude review`). Advisory, not a required check |
| `Release` | Not a check: a maintainer runs it by hand to tag a release (see [Releasing](#releasing)) |

## Releasing

Releases are tags on `main` (`v0.x.y`), made only by the **Release** workflow, which a maintainer runs by hand. Nothing is tagged on push, and agents never tag or release.

1. Merge the PRs that should go out.
2. **Actions → Release → Run workflow** (branch `main`), pick the bump:
- **patch** (`v0.4.1` → `v0.4.2`): fixes, a new provider on an existing format plugin, docs;
- **minor** (`v0.4.1` → `v0.5.0`): a new format plugin, new exported API, anything users should read about.
3. The workflow refuses if `main`'s HEAD is already tagged, then runs, on that exact commit, the internal-names check over every file, gitleaks over the whole history, `go build`, `go vet`, `gofmt` and `go test -race`. Any failure stops it before a tag exists.
4. When everything passes it pushes an annotated tag and publishes a GitHub release with generated notes (grouped by the PR's label: `plugin`/`enhancement`, `bug`, `documentation`; see [`.github/release.yml`](.github/release.yml)).

`v1.0.0` (and any later major) is not a button: it is a deliberate decision a maintainer makes and tags by hand.

**Never delete or move a pushed tag.** Go's module proxy and checksum database keep every published version forever, so a moved tag breaks everyone who already fetched it. If a release is wrong, fix it on `main` and release the next patch version.

## License

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ The tests are offline: every plugin's test reads a saved copy of its source from

Nothing else is read from the environment.

## Releases

Every release is a `v0.x.y` tag on `main` with a [GitHub release](https://github.com/patch-it-dev/patch-it-plugins/releases) and generated notes. Maintainers make them with the manual **Release** workflow ([how](CONTRIBUTING.md#releasing)); tags are never moved or deleted, so a bad release is fixed with a new patch version.

```sh
go get github.com/patch-it-dev/patch-it-plugins@latest
```

## Contributing

New providers and fixes are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) first (DCO sign-off, golden tests, adding your plugin to `docs/plugins.md`). AI coding agents: [AGENTS.md](AGENTS.md).
Expand Down
Loading