|
50 | 50 | - name: Checkout docs-internal |
51 | 51 | uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
52 | 52 |
|
| 53 | + # `preserve-redirects.ts` reads the pre-sync state from `git HEAD` to learn |
| 54 | + # which URLs are currently live. That is only a valid baseline when HEAD is |
| 55 | + # the published branch. `pull_request` runs are safe because they never |
| 56 | + # publish, but a `workflow_dispatch` from another branch would publish while |
| 57 | + # comparing against that branch's tree, writing stale redirects into a real |
| 58 | + # PR. Fail early rather than let the run reach the push step. |
| 59 | + - name: Verify publishing runs start from the default branch |
| 60 | + if: github.event_name != 'pull_request' && inputs.dry_run != 'true' |
| 61 | + run: | |
| 62 | + if [ "$GITHUB_REF_NAME" != "$DEFAULT_BRANCH" ]; then |
| 63 | + echo "::error::This run would push and open a PR, but it started from" \ |
| 64 | + "'$GITHUB_REF_NAME' rather than the default branch '$DEFAULT_BRANCH'." \ |
| 65 | + "HEAD is the baseline for redirect preservation, so syncing from another" \ |
| 66 | + "branch can drop or invent redirects. Re-run from '$DEFAULT_BRANCH', or" \ |
| 67 | + "use the dry_run input to test from a branch." |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + env: |
| 71 | + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} |
| 72 | + |
53 | 73 | - name: Fetch SDK docs from copilot-sdk |
54 | 74 | env: |
55 | 75 | GH_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }} |
@@ -91,6 +111,22 @@ jobs: |
91 | 111 | --content-dir content \ |
92 | 112 | --sdk-docs-dir "$SDK_DOCS_TARGET" |
93 | 113 |
|
| 114 | + - name: Preserve redirects |
| 115 | + run: | |
| 116 | + # `--git-ref HEAD` is the record of which URLs are currently live. On |
| 117 | + # publishing runs a preceding step has verified HEAD is the default |
| 118 | + # branch, and the sync branch is only created later with `checkout -B`. |
| 119 | + # On `pull_request` runs HEAD is the merge commit instead, which is fine |
| 120 | + # because those runs are dry-run only. |
| 121 | + # |
| 122 | + # A removed page that needs a redirect decision should still produce a |
| 123 | + # PR, because the PR is where that decision gets made and committed. The |
| 124 | + # script still writes the at-risk URLs and a copy-pasteable |
| 125 | + # `redirect_from` block to the run summary either way. |
| 126 | + npx tsx src/workflows/sync-sdk-docs/preserve-redirects.ts \ |
| 127 | + --sdk-docs-dir "$SDK_DOCS_TARGET" \ |
| 128 | + --git-ref HEAD |
| 129 | +
|
94 | 130 | - name: Convert Mermaid diagrams to PNG |
95 | 131 | env: |
96 | 132 | PUPPETEER_CHROMIUM_REVISION: '' |
@@ -165,7 +201,7 @@ jobs: |
165 | 201 | ${{ env.ASSETS_TARGET }} |
166 | 202 | retention-days: 7 |
167 | 203 |
|
168 | | - # --- Push and PR (only on schedule/dispatch, not dry-run, and changes exist) --- |
| 204 | + # --- Push and PR (only on dispatch, not dry-run, and changes exist) --- |
169 | 205 | - name: Commit and push |
170 | 206 | if: >- |
171 | 207 | env.has_changes == 'true' |
@@ -212,7 +248,7 @@ jobs: |
212 | 248 | - Normalizes code fence languages and list formatting |
213 | 249 |
|
214 | 250 | > [!NOTE] |
215 | | - > This PR is auto-generated. Do not edit it directly — make changes in the [copilot-sdk docs](https://github.com/github/copilot-sdk/tree/main/docs) instead. |
| 251 | + > This PR is auto-generated. Do not edit it directly — make changes in the [copilot-sdk docs](https://github.com/github/copilot-sdk/tree/main/docs) instead. Exception: \`redirect_from\` cannot come from upstream, so add redirects here. |
216 | 252 |
|
217 | 253 | --- |
218 | 254 | _Generated by the [sync-sdk-docs workflow run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)._" |
|
0 commit comments