-
Notifications
You must be signed in to change notification settings - Fork 109
test: PR checks on a broken PR, left broken (do not merge) #1920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+1,013
−91
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7f5bd3
ci: fail PRs that break redirects, with suggested fixes
marcleblanc2 b2f29c2
check-redirects: don't repeat the final destination the Fix line alre…
marcleblanc2 1508206
check-redirects: sync review comments with dev/sync-review-comments.s…
marcleblanc2 80527ae
check-links: one suggestion per fix, synced with findings; report one…
marcleblanc2 e2f24a2
cspell: allow tostring, a jq builtin used in the workflows
marcleblanc2 f922886
check-links: don't repeat the link and fix inside the case-mismatch p…
marcleblanc2 41aae0f
check-links: inbound section wording
marcleblanc2 2407a71
check-links: move review-comment sync to dev/sync-review-comments.sh;…
marcleblanc2 9bc0896
cspell: allow argjson, a jq option used in dev/sync-review-comments.sh
marcleblanc2 e9fe828
spell check: update inline comments whose text changed instead of lea…
marcleblanc2 37049f7
ci: Comment the Vercel build log on PRs whose build fails
marcleblanc2 7333b3f
test: break links, spelling, and redirects to exercise every PR check…
marcleblanc2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| name: Check redirects | ||
|
|
||
| # Reports redirects in src/data/redirects.ts that this PR breaks, compared with | ||
| # the merge base: destinations that no longer exist, #fragments whose heading | ||
| # was renamed, and new redirects that shadow an existing page. Pre-existing | ||
| # broken redirects on the base branch are ignored. | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| # A new push supersedes the run for the previous one | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| check-redirects: | ||
| name: Broken redirects introduced by this PR | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out pull request head | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Install github-slugger, the only dependency of dev/check-redirects.mjs | ||
| # Into a scratch prefix, not the repo: `npm install <pkg>` next to | ||
| # package.json would install every dependency of the site | ||
| run: | | ||
| npm install --prefix "$RUNNER_TEMP/deps" --no-package-lock --no-audit --no-fund \ | ||
| "github-slugger@$(node -p 'require("./package.json").dependencies["github-slugger"]')" | ||
| ln -s "$RUNNER_TEMP/deps/node_modules" node_modules | ||
|
|
||
| - name: Check out merge base | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| merge_base=$(git merge-base "$BASE_SHA" HEAD) | ||
| git worktree add "$RUNNER_TEMP/base" "$merge_base" | ||
| git diff -U0 "$merge_base" HEAD -- src/data/redirects.ts > "$RUNNER_TEMP/changes.diff" | ||
|
|
||
| - name: Record broken redirects already present on the base branch | ||
| # Exit 1 means findings, which is expected here | ||
| run: | | ||
| node dev/check-redirects.mjs --format json \ | ||
| --root "$RUNNER_TEMP/base" > "$RUNNER_TEMP/base-redirects.json" \ | ||
| || [ $? -eq 1 ] | ||
|
|
||
| - name: Find redirects broken by this PR | ||
| id: check | ||
| env: | ||
| # Line links in the report open redirects.ts on the PR branch | ||
| LINK_BASE: ${{ github.event.pull_request.head.repo.html_url }}/blob/${{ github.event.pull_request.head.ref }} | ||
| run: | | ||
| if node dev/check-redirects.mjs --format markdown \ | ||
| --baseline "$RUNNER_TEMP/base-redirects.json" \ | ||
| --diff "$RUNNER_TEMP/changes.diff" \ | ||
| --review "$RUNNER_TEMP/review.json" \ | ||
| --link-base "$LINK_BASE" > "$RUNNER_TEMP/report.md"; then | ||
| echo "broken=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "broken=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| cat "$RUNNER_TEMP/report.md" | ||
|
|
||
| - name: Comment on the pull request | ||
| # Fork PRs get a read-only token; the report is still in the job log | ||
| if: github.event.pull_request.head.repo.full_name == github.repository | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| BROKEN: ${{ steps.check.outputs.broken }} | ||
| run: | | ||
| marker='<!-- check-redirects-report -->' | ||
| existing_comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ | ||
| --paginate --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1) | ||
|
|
||
| # Comment only when there is something to report, or an earlier report to resolve | ||
| if [ "$BROKEN" = true ]; then | ||
| { echo "$marker"; cat "$RUNNER_TEMP/report.md"; } > "$RUNNER_TEMP/comment.md" | ||
| elif [ -n "$existing_comment" ]; then | ||
| printf '%s\n### ✅ The redirects an earlier revision of this PR broke are fixed\n' \ | ||
| "$marker" > "$RUNNER_TEMP/comment.md" | ||
| else | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ -n "$existing_comment" ]; then | ||
| gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$existing_comment" \ | ||
| --field body=@"$RUNNER_TEMP/comment.md" | ||
| else | ||
| gh pr comment "$PR_NUMBER" --body-file "$RUNNER_TEMP/comment.md" | ||
| fi | ||
|
|
||
| - name: Suggest fixes as review comments | ||
| # One suggested change per fixable entry this PR added, kept in sync | ||
| # with the findings; see dev/sync-review-comments.sh | ||
| if: github.event.pull_request.head.repo.full_name == github.repository | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: dev/sync-review-comments.sh '<!-- check-redirects-finding:' "$RUNNER_TEMP/review.json" | ||
|
|
||
| - name: Fail when this PR breaks redirects | ||
| if: steps.check.outputs.broken == 'true' | ||
| run: exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: Vercel build report | ||
|
|
||
| # Vercel only shows build logs to members of its team. When a PR's Vercel | ||
| # build fails, this comments the end of the build log on the PR; when a later | ||
| # revision builds, the comment is updated to say so. | ||
| # | ||
| # GitHub only delivers repository_dispatch to the workflow file on the default | ||
| # branch, so workflow_dispatch takes the same payload fields as inputs for | ||
| # testing before merge and for re-running on a PR by hand: | ||
| # gh workflow run vercel-build-report.yml --ref <branch> \ | ||
| # -f id=dpl_... -f state=error -f sha=<pr head sha> | ||
| on: | ||
| repository_dispatch: | ||
| types: [vercel.deployment.error, vercel.deployment.success] | ||
| workflow_dispatch: | ||
| inputs: | ||
| id: | ||
| description: Vercel deployment ID (client_payload.id) | ||
| required: true | ||
| state: | ||
| description: Deployment state (client_payload.state.type) | ||
| required: true | ||
| type: choice | ||
| options: [error, success] | ||
| sha: | ||
| description: Full commit SHA of the PR head (client_payload.git.sha) | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| report: | ||
| if: github.event.client_payload.environment != 'production' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out dev/report-vercel-build.mjs | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| sparse-checkout: dev/report-vercel-build.mjs | ||
| sparse-checkout-cone-mode: false | ||
|
|
||
| - name: Comment on the pull request | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| DEPLOYMENT_ID: ${{ github.event.client_payload.id || inputs.id }} | ||
| DEPLOYMENT_STATE: ${{ github.event.client_payload.state.type || inputs.state }} | ||
| COMMIT_SHA: ${{ github.event.client_payload.git.sha || inputs.sha }} | ||
| # Scoped to the sourcegraph-docs project, so it needs no team ID | ||
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | ||
| run: node dev/report-vercel-build.mjs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aardvarkis out of alphabetical order: move it aboveacmecoon line 26.