|
| 1 | +name: Docs dispatch |
| 2 | + |
| 3 | +# Fires on push to the repo's default branch when content that affects external |
| 4 | +# docs (or the public changelog) changes. Notifies the composer repo |
| 5 | +# (makegov/docs) via repository_dispatch so it rebuilds without waiting for |
| 6 | +# someone to push to docs directly. |
| 7 | +# |
| 8 | +# Installed by mg-tools into repos whose docsRole is `coloc-source` or |
| 9 | +# `editorial-split-source`. For editorial-split repos (e.g. tango), the |
| 10 | +# external paths watched are narrower — only docs/CHANGELOG.md and |
| 11 | +# docs/internal/** (since the rest of external docs lives in the composer). |
| 12 | +# |
| 13 | +# Required secrets: |
| 14 | +# DOCS_DISPATCH_TOKEN — GitHub token with repo:write on makegov/docs |
| 15 | +# |
| 16 | +# Required variables (optional): |
| 17 | +# DOCS_TARGET_REPO — override target (default: makegov/docs) |
| 18 | +# |
| 19 | +# On install, mg-tools substitutes the path filters based on docsRole. |
| 20 | + |
| 21 | +on: |
| 22 | + push: |
| 23 | + branches: |
| 24 | + - main |
| 25 | + - master |
| 26 | + - staging |
| 27 | + paths: |
| 28 | + - "docs/**" |
| 29 | + - "docs/CHANGELOG.md" |
| 30 | + - "README.md" |
| 31 | + workflow_dispatch: |
| 32 | + |
| 33 | +jobs: |
| 34 | + dispatch: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 2 |
| 42 | + |
| 43 | + - name: Detect changed paths |
| 44 | + id: changes |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | + # Default to all-on-first-commit if there's only one commit in the ref. |
| 48 | + base=$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD) |
| 49 | + changed=$(git diff --name-only "$base" HEAD | paste -sd, -) |
| 50 | + echo "changed=$changed" >> "$GITHUB_OUTPUT" |
| 51 | + if [[ -n "$changed" ]]; then |
| 52 | + echo "has_changes=true" >> "$GITHUB_OUTPUT" |
| 53 | + else |
| 54 | + echo "has_changes=false" >> "$GITHUB_OUTPUT" |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Dispatch to docs composer |
| 58 | + if: steps.changes.outputs.has_changes == 'true' |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ secrets.DOCS_DISPATCH_TOKEN }} |
| 61 | + TARGET: ${{ vars.DOCS_TARGET_REPO || 'makegov/docs' }} |
| 62 | + run: | |
| 63 | + gh api "repos/$TARGET/dispatches" \ |
| 64 | + -f event_type=external_updated \ |
| 65 | + -f "client_payload[source_repo]=${{ github.repository }}" \ |
| 66 | + -f "client_payload[source_ref]=${{ github.sha }}" \ |
| 67 | + -f "client_payload[changed_paths]=${{ steps.changes.outputs.changed }}" |
0 commit comments