-
Notifications
You must be signed in to change notification settings - Fork 3
ci: gate notebook PRs on a real Wherobots job run #206
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
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env bash | ||
| # Post (or update) a single sticky comment on the PR with notebook job run results. | ||
| set -euo pipefail | ||
|
|
||
| MARKER='<!-- notebook-job-run-gate -->' | ||
| REPORT="notebook-run-results/report.md" | ||
|
|
||
| if [[ ! -f "$REPORT" ]]; then | ||
| # The runner never got far enough to write a report -- say so rather than | ||
| # leaving a red check with no explanation. | ||
| mkdir -p "$(dirname "$REPORT")" | ||
| { | ||
| echo "$MARKER" | ||
| echo "## Notebook job runs" | ||
| echo | ||
| echo "The notebook gate did not complete (job status: \`${JOB_STATUS}\`), so no" | ||
| echo "notebook was validated. See the [workflow run](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) for details." | ||
| } > "$REPORT" | ||
| fi | ||
|
|
||
| # Nothing changed that needed a run, and no prior comment to update: stay quiet. | ||
| existing=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" --paginate \ | ||
| --jq "[.[] | select(.body | contains(\"$MARKER\")) | .id] | first // empty") | ||
|
|
||
| if grep -q "no job runs were needed" "$REPORT" && [[ -z "$existing" ]]; then | ||
| echo "No code cell changes and no existing comment; skipping." | ||
| exit 0 | ||
| fi | ||
|
|
||
| { | ||
| echo | ||
| echo "---" | ||
| echo "[Workflow run](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) · commit \`${GITHUB_SHA:0:7}\`" | ||
| } >> "$REPORT" | ||
|
|
||
| if [[ -n "$existing" ]]; then | ||
| gh api --method PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${existing}" \ | ||
| -F "body=@${REPORT}" > /dev/null | ||
| echo "Updated comment $existing" | ||
| else | ||
| gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" \ | ||
| -F "body=@${REPORT}" > /dev/null | ||
| echo "Created new comment" | ||
| fi | ||
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.
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.
issue (blocking): Any PR commenter can preempt the sticky marker, causing the workflow to PATCH a comment it does not own and fail with a 403.
The
--jqfilter selects any comment whose bodycontainsthe marker, regardless of author. Filter the lookup to comments authored bygithub-actions[bot](or the token's actual bot identity); otherwise one<!-- notebook-job-run-gate -->in a user comment turns a successful notebook run red. Tiny HTML comment, surprisingly large blast radius.