|
6 | 6 | - "v*.*.*" |
7 | 7 |
|
8 | 8 | permissions: |
9 | | - contents: read |
| 9 | + contents: write |
10 | 10 | packages: write |
11 | 11 |
|
12 | 12 | env: |
|
58 | 58 | cache-to: type=gha,mode=max |
59 | 59 | tags: ${{ steps.meta.outputs.tags }} |
60 | 60 | 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 |
0 commit comments