Skip to content

Commit 9838cd9

Browse files
committed
chore: migrate to release please
1 parent 5f12bb9 commit 9838cd9

11 files changed

Lines changed: 136 additions & 98 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: release-please
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
steps:
16+
# A PAT (GITHUBRELEASETOKEN) is required, not the default GITHUB_TOKEN:
17+
# tags/releases created with the default token don't trigger other
18+
# workflows, which would prevent the tag push below from firing
19+
# release.yml (the GoReleaser publish job).
20+
- uses: googleapis/release-please-action@v4
21+
with:
22+
token: ${{ secrets.GITHUBRELEASETOKEN }}
23+
config-file: release-please-config.json
24+
manifest-file: .release-please-manifest.json

.github/workflows/release.yml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
name: Release
22

3+
# Publishes a GitHub Release with GoReleaser whenever release-please pushes
4+
# a version tag (see release-please.yml and RELEASING.md). The
5+
# workflow_dispatch input exists only to re-run publishing against an
6+
# already-tagged release, e.g. after a failed run.
37
on:
48
workflow_dispatch:
59
inputs:
610
tag:
7-
description: 'Tag to release (e.g. v2.4.3). Must not already exist. The tag will be created at the current HEAD of the default branch.'
11+
description: 'Existing tag to (re-)publish, e.g. v2.4.3.'
812
required: true
913
push:
1014
tags:
@@ -19,23 +23,7 @@ jobs:
1923
uses: actions/checkout@v6
2024
with:
2125
fetch-depth: 0
22-
-
23-
name: Create and push tag (workflow_dispatch only)
24-
if: github.event_name == 'workflow_dispatch'
25-
run: |
26-
TAG="${{ github.event.inputs.tag }}"
27-
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9] ]]; then
28-
echo "Error: tag '$TAG' does not match expected format (e.g. v2.4.3)"
29-
exit 1
30-
fi
31-
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" > /dev/null 2>&1; then
32-
echo "Error: tag '$TAG' already exists on the remote"
33-
exit 1
34-
fi
35-
git config user.name "github-actions[bot]"
36-
git config user.email "github-actions[bot]@users.noreply.github.com"
37-
git tag "$TAG"
38-
git push origin "$TAG"
26+
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
3927
-
4028
name: Set up Go
4129
uses: actions/setup-go@v6
@@ -48,4 +36,4 @@ jobs:
4836
version: latest
4937
args: release --clean
5038
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUBRELEASETOKEN }}
39+
GITHUB_TOKEN: ${{ secrets.GITHUBRELEASETOKEN }}

.goreleaser.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@ builds:
1111
- linux
1212
- windows
1313
- darwin
14+
ldflags:
15+
- -s -w -X github.com/pact-foundation/pact-go/v2/command.Version={{.Tag}}
1416
checksum:
1517
name_template: 'checksums.txt'
1618
snapshot:
1719
version_template: "{{ .Tag }}-next"
1820
changelog:
1921
sort: asc
22+
groups:
23+
- title: "Features"
24+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
25+
order: 0
26+
- title: "Bug fixes"
27+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
28+
order: 1
29+
- title: "Other changes"
30+
order: 999
2031
filters:
2132
exclude:
2233
- '^docs:'
2334
- '^test:'
2435
- '^chore:'
2536
- '^wip:'
37+
- '^ci:'
38+
- 'Merge branch'
39+
- 'Merge pull request'

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "2.5.1"
3+
}

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Changelog
2-
Do this to generate your change history
32

4-
git log --pretty=format:' * [%h](https://github.com/pact-foundation/pact-go/commit/%h) - %s (%an, %ad)' vX.Y.Z..HEAD | egrep -v "wip(:|\()" | grep -v "docs(" | grep -v "chore(" | grep -v Merge | grep -v "test("
3+
Releases from here on are generated automatically by [release-please](https://github.com/googleapis/release-please) from [Conventional Commits](https://www.conventionalcommits.org/) - see [RELEASING.md](RELEASING.md).
54

6-
## Versions
5+
## Previous releases
6+
7+
_Entries below this point were generated manually before the release-please migration._
78

89
### v2.5.1 (26 May 2026)
910
* f7737e8 - docs: update verifier error result sentinel descriptions

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ publish:
135135
@echo "-- 📃 Publishing pacts"
136136
@"${PACT_CLI}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod
137137

138-
release:
139-
echo "--- 🚀 Releasing it"
140-
"$(CURDIR)/scripts/release.sh"
141-
142138
ifeq ($(SKIP_PROVIDER_TESTS),true)
143139
PROVIDER_TEST_TAGS=
144140
else
@@ -169,7 +165,7 @@ testrace:
169165
updatedeps:
170166
go get -d -v -p 2 ./...
171167

172-
.PHONY: install bin default dev test pact updatedeps clean release
168+
.PHONY: install bin default dev test pact updatedeps clean
173169

174170
PROTOC ?= $(shell which protoc)
175171

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Detail on the native Go implementation can be found [here](https://github.com/pa
313313

314314
## Contributing
315315

316-
See [CONTRIBUTING](CONTRIBUTING.md).
316+
See [CONTRIBUTING](CONTRIBUTING.md). Maintainers cutting a release should see [RELEASING](RELEASING.md).
317317

318318
<a href="https://github.com/pact-foundation/pact-go/graphs/contributors">
319319
<img src="https://contrib.rocks/image?repo=pact-foundation/pact-go" />

RELEASING.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
21
# Releasing
32

4-
Once your changes are in master, the latest release should be set as a draft at https://github.com/pact-foundation/pact-go/releases/.
3+
Releasing is fully automated with [release-please](https://github.com/googleapis/release-please). There is nothing to run locally, no version to bump, and no changelog to hand-edit.
4+
5+
## How it works
6+
7+
1. Every push to `master` runs the [`release-please`](https://github.com/pact-foundation/pact-go/actions/workflows/release-please.yml) workflow. It scans commits since the last release for [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `feat!:`/`fix!:` or a `BREAKING CHANGE:` footer, `perf:`, `deps:`, etc.) and keeps a **Release PR** up to date with:
8+
- The next version, computed via semver from the commit types seen (`feat` → minor, `fix`/`perf`/`deps` → patch, breaking change → major).
9+
- A generated `CHANGELOG.md` entry.
10+
2. To cut a release, **merge the release PR**. On merge, release-please:
11+
- Tags `master` with the new version (e.g. `v2.6.0`).
12+
- Publishes a GitHub Release.
13+
3. The tag push triggers [`release.yml`](.github/workflows/release.yml), which runs [GoReleaser](https://goreleaser.com/) to build the release binaries and attach them to that GitHub Release.
14+
15+
That's the whole process. Keep merging PRs into `master` with conventional commit messages, and merge the standing release PR whenever you're ready to ship what's accumulated on it.
516

6-
Once you've tested that it works as expected:
17+
## Notes
718

8-
1. Bump version in `command/version.go`.
9-
2. Run `make release` to generate release notes and release commit.
10-
3. Push tags `git push --follow-tags`
11-
4. The pipeline will automatically trigger a release
12-
1. Edit the release notes at https://github.com/pact-foundation/pact-go/releases/edit/v<VERSION> if needed.
19+
- No `command/version.go` bump is needed: `pact-go version` resolves itself at runtime, either from the GoReleaser `-ldflags` (release binaries) or from the Go module version (`go install .../pact-go/v2@vX.Y.Z`).
20+
- Release-please's config lives in [`release-please-config.json`](release-please-config.json); the version it currently believes is released is tracked in [`.release-please-manifest.json`](.release-please-manifest.json).
21+
- If a GoReleaser run fails after a tag is already published, re-run [`release.yml`](https://github.com/pact-foundation/pact-go/actions/workflows/release.yml) manually via `workflow_dispatch`, passing the existing tag - it won't create a new tag or PR.
22+
- Commits that aren't `feat`/`fix`/etc. (e.g. `chore:`, `docs:`, `test:`) don't trigger a version bump on their own, but will still be picked up once a `feat`/`fix` commit lands.

command/version.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ package command
22

33
import (
44
"fmt"
5+
"runtime/debug"
56

67
"github.com/spf13/cobra"
78
)
89

10+
// Version is the Pact Go version. It is normally left as "dev" here and
11+
// resolved automatically:
12+
// - Official release binaries (built via `goreleaser`) have this
13+
// overridden at build time via -ldflags (see .goreleaser.yml).
14+
// - Builds via `go install github.com/pact-foundation/pact-go/v2@vX.Y.Z`,
15+
// or when pact-go is imported as a module dependency, resolve it from
16+
// the Go module's build info at runtime, so no source change is needed.
17+
//
18+
// There is no version to bump for a release - see RELEASING.md.
919
var (
10-
Version = "v2.5.1"
20+
Version = "dev"
1121
versionCmd = &cobra.Command{
1222
Use: "version",
1323
Short: "Print the version number of Pact Go",
@@ -19,5 +29,36 @@ var (
1929
)
2030

2131
func init() {
32+
if Version == "dev" {
33+
if v := moduleVersion(); v != "" {
34+
Version = v
35+
}
36+
}
2237
RootCmd.AddCommand(versionCmd)
2338
}
39+
40+
// moduleVersion resolves the pact-go version from Go module build info,
41+
// covering both `go install .../pact-go/v2@vX.Y.Z` (module is main) and
42+
// pact-go being imported as a dependency of another module.
43+
func moduleVersion() string {
44+
info, ok := debug.ReadBuildInfo()
45+
if !ok {
46+
return ""
47+
}
48+
49+
if isResolvedVersion(info.Main.Version) {
50+
return info.Main.Version
51+
}
52+
53+
for _, dep := range info.Deps {
54+
if dep.Path == "github.com/pact-foundation/pact-go/v2" && isResolvedVersion(dep.Version) {
55+
return dep.Version
56+
}
57+
}
58+
59+
return ""
60+
}
61+
62+
func isResolvedVersion(v string) bool {
63+
return v != "" && v != "(devel)"
64+
}

release-please-config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"packages": {
4+
".": {
5+
"release-type": "simple",
6+
"package-name": "pact-go",
7+
"changelog-path": "CHANGELOG.md",
8+
"include-component-in-tag": false,
9+
"include-v-in-tag": true,
10+
"pull-request-title-pattern": "chore(release): release ${version}",
11+
"changelog-sections": [
12+
{ "type": "feat", "section": "Features" },
13+
{ "type": "fix", "section": "Bug Fixes" },
14+
{ "type": "perf", "section": "Performance Improvements" },
15+
{ "type": "deps", "section": "Dependencies" },
16+
{ "type": "docs", "section": "Documentation", "hidden": true },
17+
{ "type": "chore", "section": "Miscellaneous", "hidden": true },
18+
{ "type": "test", "section": "Tests", "hidden": true }
19+
]
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)