|
| 1 | +name: Enrich Release Notes |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + format: |
| 13 | + name: Format published release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: ${{ github.event.release.draft == false }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + ref: ${{ github.event.release.tag_name }} |
| 21 | + |
| 22 | + - name: Update release body with install instructions |
| 23 | + env: |
| 24 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + REPOSITORY: ${{ github.repository }} |
| 26 | + TAG_NAME: ${{ github.event.release.tag_name }} |
| 27 | + RAW_VERSION: ${{ github.event.release.tag_name }} |
| 28 | + RELEASE_BODY: ${{ github.event.release.body }} |
| 29 | + run: | |
| 30 | + set -euo pipefail |
| 31 | +
|
| 32 | + version="${RAW_VERSION#v}" |
| 33 | + tar_url="https://github.com/${REPOSITORY}/archive/refs/tags/${TAG_NAME}.tar.gz" |
| 34 | + tmp_archive="$(mktemp)" |
| 35 | + curl -sSL "${tar_url}" -o "${tmp_archive}" |
| 36 | + sha256="$(shasum -a 256 "${tmp_archive}" | cut -d ' ' -f1)" |
| 37 | + rm "${tmp_archive}" |
| 38 | + export SHA256="${sha256}" |
| 39 | +
|
| 40 | + python - <<'PY' > release-body.md |
| 41 | +import os, textwrap |
| 42 | + |
| 43 | +repo = os.environ["REPOSITORY"] |
| 44 | +tag = os.environ["TAG_NAME"] |
| 45 | +version = os.environ["RAW_VERSION"].lstrip("v") |
| 46 | +tar_url = f"https://github.com/{repo}/archive/refs/tags/{tag}.tar.gz" |
| 47 | +sha256 = os.environ["SHA256"] |
| 48 | +existing = os.environ.get("RELEASE_BODY", "").strip() |
| 49 | + |
| 50 | +body = textwrap.dedent(f"""\ |
| 51 | +## Install with Bzlmod |
| 52 | + |
| 53 | +Add to your `MODULE.bazel`: |
| 54 | + |
| 55 | +```starlark |
| 56 | +bazel_dep(name = "rules_sbom", version = "{version}") |
| 57 | +
|
| 58 | +load("@rules_sbom//sbom:setup.bzl", "rules_sbom_setup") |
| 59 | +syft_repo = use_repo_rule("@rules_sbom//sbom:repositories.bzl", "syft_repository") |
| 60 | +rules_sbom_setup(syft_repo) |
| 61 | +``` |
| 62 | + |
| 63 | +## Install with a WORKSPACE |
| 64 | + |
| 65 | +Download and pin the release archive: |
| 66 | + |
| 67 | +- URL: `{tar_url}` |
| 68 | +- SHA256: `{sha256}` |
| 69 | + |
| 70 | +Then in your `WORKSPACE` file: |
| 71 | + |
| 72 | +```starlark |
| 73 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 74 | +
|
| 75 | +http_archive( |
| 76 | + name = "rules_sbom", |
| 77 | + urls = ["{tar_url}"], |
| 78 | + strip_prefix = "rules_sbom-{version}", |
| 79 | + sha256 = "{sha256}", |
| 80 | +) |
| 81 | +
|
| 82 | +load("@rules_sbom//sbom:repositories.bzl", "syft_repository") |
| 83 | +load("@rules_sbom//sbom:setup.bzl", "rules_sbom_setup") |
| 84 | +
|
| 85 | +rules_sbom_setup(syft_repository) |
| 86 | +``` |
| 87 | + |
| 88 | +See [docs/overview.md](https://github.com/{repo}/blob/{tag}/docs/overview.md) for advanced configuration options. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +{existing} |
| 93 | +""") |
| 94 | +
|
| 95 | +print(body) |
| 96 | +PY |
| 97 | +
|
| 98 | + gh release edit "${TAG_NAME}" --notes-file release-body.md |
0 commit comments