|
| 1 | +# ───────────────────────────────────────────────────────────────────────────── |
| 2 | +# Notify the docs site (greenmaskio.github.io) of a docs change or release. |
| 3 | +# |
| 4 | +# doctest is published by the site with a version dropdown: |
| 5 | +# - `Next` always follows doctest `main` (the `docs/` tree). |
| 6 | +# - each released major.minor line follows its latest STABLE tag. |
| 7 | +# This workflow fires a `docs-release` repository_dispatch at the site in both cases: |
| 8 | +# - a push to `main` touching `docs/**` → payload {product} (updates Next) |
| 9 | +# - a STABLE tag push `vMAJOR.MINOR.PATCH` → payload {product, tag} (records a line) |
| 10 | +# Prerelease tags (e.g. v1.0.0b1) are ignored. |
| 11 | +# |
| 12 | +# SETUP: |
| 13 | +# Add a repo (or org) secret DOCS_SITE_DISPATCH_TOKEN: a fine-grained PAT with |
| 14 | +# "Contents: Read and write" on greenmaskio/greenmaskio.github.io, so it may POST to |
| 15 | +# that repo's /dispatches endpoint. |
| 16 | +# ───────────────────────────────────────────────────────────────────────────── |
| 17 | +name: Notify docs site of a docs change or release |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: [main] |
| 22 | + tags: ['v*'] |
| 23 | + |
| 24 | +env: |
| 25 | + SITE_REPO: greenmaskio/greenmaskio.github.io |
| 26 | + PRODUCT_ID: doctest # must match the product `id` in the site's .github/products.json |
| 27 | + DOCS_GLOB: 'docs/' # doctest serves from the default docs/ root |
| 28 | + |
| 29 | +jobs: |
| 30 | + dispatch: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + # Need history to diff a main push for docs/** changes. |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + - name: Decide and send docs-release dispatch |
| 38 | + env: |
| 39 | + TOKEN: ${{ secrets.DOCS_SITE_DISPATCH_TOKEN }} |
| 40 | + BEFORE: ${{ github.event.before }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + send() { # $1 = client_payload JSON object |
| 44 | + curl -fsS -X POST \ |
| 45 | + -H "Authorization: Bearer ${TOKEN}" \ |
| 46 | + -H "Accept: application/vnd.github+json" \ |
| 47 | + "https://api.github.com/repos/${SITE_REPO}/dispatches" \ |
| 48 | + -d "{\"event_type\":\"docs-release\",\"client_payload\":$1}" |
| 49 | + } |
| 50 | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then |
| 51 | + TAG="${GITHUB_REF_NAME}" |
| 52 | + # Only stable vMAJOR.MINOR.PATCH tags record a version line. |
| 53 | + if ! printf '%s' "$TAG" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 54 | + echo "Tag $TAG is a prerelease — not notifying the docs site." |
| 55 | + exit 0 |
| 56 | + fi |
| 57 | + send "{\"product\":\"${PRODUCT_ID}\",\"tag\":\"${TAG}\"}" |
| 58 | + echo "Dispatched release ${PRODUCT_ID}@${TAG} → ${SITE_REPO}" |
| 59 | + else |
| 60 | + # main push: only notify when docs/** actually changed. |
| 61 | + if [ -z "${BEFORE}" ] || [ "${BEFORE}" = "0000000000000000000000000000000000000000" ]; then |
| 62 | + changed=1 |
| 63 | + else |
| 64 | + changed=$(git diff --name-only "${BEFORE}" "${GITHUB_SHA}" -- "${DOCS_GLOB}" | wc -l) |
| 65 | + fi |
| 66 | + if [ "${changed}" -eq 0 ]; then |
| 67 | + echo "No ${DOCS_GLOB} changes in this push — skipping." |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + send "{\"product\":\"${PRODUCT_ID}\"}" |
| 71 | + echo "Dispatched docs-on-main ${PRODUCT_ID} → ${SITE_REPO}" |
| 72 | + fi |
0 commit comments