Skip to content
This repository was archived by the owner on Jun 22, 2026. It is now read-only.

Commit 87ed3c5

Browse files
authored
ci: automate releases with release-please (#2)
* ci: automate releases with release-please * ci: simplify release-please setup
1 parent 4d1926f commit 87ed3c5

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

.github/workflows/cd.yml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- "v*.*.*"
77

88
permissions:
9-
contents: read
9+
contents: write
1010
packages: write
1111

1212
env:
@@ -58,3 +58,61 @@ jobs:
5858
cache-to: type=gha,mode=max
5959
tags: ${{ steps.meta.outputs.tags }}
6060
labels: ${{ steps.meta.outputs.labels }}
61+
62+
update-release-notes:
63+
runs-on: ubuntu-latest
64+
needs: build-and-push
65+
66+
steps:
67+
- name: Ensure GitHub release exists
68+
env:
69+
GH_TOKEN: ${{ github.token }}
70+
run: |
71+
tag="${GITHUB_REF_NAME}"
72+
if ! gh release view "$tag" >/dev/null 2>&1; then
73+
gh release create "$tag" --title "$tag" --generate-notes
74+
fi
75+
76+
- name: Append container image instructions to release body
77+
env:
78+
GH_TOKEN: ${{ github.token }}
79+
IMAGE_REF: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
80+
run: |
81+
# GITHUB_REF_NAME comes from the trusted maintainer-created tag ref that triggered this workflow.
82+
python3 <<'PY'
83+
import os
84+
import subprocess
85+
import textwrap
86+
87+
tag = os.environ["GITHUB_REF_NAME"]
88+
image_ref = os.environ["IMAGE_REF"]
89+
marker = "## Container image"
90+
91+
body = subprocess.check_output(
92+
["gh", "release", "view", tag, "--json", "body", "-q", ".body"],
93+
text=True,
94+
)
95+
96+
container_section = textwrap.dedent(
97+
f"""
98+
## Container image
99+
100+
Pull the published container from GHCR:
101+
102+
```bash
103+
docker pull {image_ref}:{tag.lstrip('v')}
104+
docker pull {image_ref}:latest
105+
```
106+
"""
107+
).strip()
108+
109+
if marker in body:
110+
body = body.split(marker, 1)[0].rstrip()
111+
112+
body = f"{body}\n\n{container_section}\n" if body.strip() else f"{container_section}\n"
113+
114+
with open("RELEASE_NOTES.md", "w", encoding="utf-8") as fh:
115+
fh.write(body)
116+
PY
117+
118+
gh release edit "$GITHUB_REF_NAME" --notes-file RELEASE_NOTES.md
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
issues: write
11+
pull-requests: write
12+
13+
concurrency:
14+
group: release-please-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
release-please:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Validate release-please token is configured
23+
env:
24+
RELEASE_PLEASE_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
25+
run: |
26+
if [ -z "$RELEASE_PLEASE_TOKEN" ]; then
27+
echo "::error::Missing RELEASE_PLEASE_TOKEN secret. Configure a PAT or GitHub App token with repository write access before enabling this workflow."
28+
exit 1
29+
fi
30+
31+
- name: Run release-please
32+
uses: googleapis/release-please-action@v4
33+
with:
34+
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
35+
release-type: go

0 commit comments

Comments
 (0)