Repository navigation
Weekly workflow: refetch the public board and push a branch only when it changed #673
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f839a3c
Weekly workflow: refetch the public board and open a pull request onl…
bompus ca4e8a6
Deny screen: a capital sharp s and a sigma's context-dependent form f…
bompus cb9a1f3
Round 1: the publish step never overwrites work that is not the job's…
bompus ba0e7b4
Independent review: the write token reaches only the publish and pull…
bompus 82c0949
Weekly workflow: push the branch and log its URL; open no pull reques…
bompus 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,55 @@ | ||
| name: Panel board refresh | ||
|
|
||
| # Weekly: refetch the public Bug Hunt board for the panel recommendations catalog and, only when it changed, | ||
| # push the regenerated snapshot and catalog to the branch panel-board-refresh and log its URL. The job opens no | ||
| # pull request (this repository does not allow Actions to create them): a maintainer opens one from the branch. | ||
| # Own results never enter this job (a fetch keeps the catalog's own entries). The job runs the catalog check | ||
| # and the skill tests itself before it pushes, because a branch pushed with the workflow token starts no CI. | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "17 14 * * 1" # Monday 14:17 UTC | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: panel-board-refresh | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| refresh: | ||
| if: github.repository == 'bompus/house-rules' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| permissions: | ||
| contents: write | ||
| env: | ||
| BRANCH: panel-board-refresh | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| # Always main, even for a manual run started from another branch, and the whole history, so the | ||
| # publish step can tell which commits the refresh branch has that main lacks. | ||
| ref: main | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
| - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 | ||
| with: | ||
| bun-version: 1.4.4 | ||
| - name: Install dependencies | ||
| run: bun install --frozen-lockfile | ||
| - name: Refetch the board and check the result | ||
| id: refresh | ||
| run: bash scripts/refresh-panel-board.sh | ||
| # The write token reaches only this step, never the install, the board fetch or the tests. | ||
| - name: Put the result on the refresh branch | ||
| id: publish | ||
| if: steps.refresh.outputs.changed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | ||
| bash scripts/publish-panel-board.sh | ||
| echo "The refresh branch holds the new board: https://github.com/${GITHUB_REPOSITORY}/tree/${BRANCH}" | tee -a "$GITHUB_STEP_SUMMARY" | ||
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,71 @@ | ||
| #!/usr/bin/env bash | ||
| # Puts the regenerated snapshot and catalog on the refresh branch, without ever rewriting work that is not the job's | ||
| # own and without a new commit when the branch already holds this board. The branch is overwritten only when every | ||
| # commit on it that main lacks was made by the workflow bot and touches only the two generated files; it is then | ||
| # replaced with a lease on the SHA that was read. Run from a full clone of main with the regenerated files in place. | ||
| # | ||
| # Usage: BRANCH=panel-board-refresh scripts/publish-panel-board.sh | ||
| # Prints ready=true (the branch holds this board) or ready=false (the branch holds other work and was left alone; | ||
| # the script then exits 1, so the run is red) to $GITHUB_OUTPUT when set. REMOTE (default origin) names the remote. | ||
| set -euo pipefail | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| branch="${BRANCH:?set BRANCH to the refresh branch}" | ||
| remote="${REMOTE:-origin}" | ||
| refs=skills/hr-code-review/references | ||
| files=("$refs/panel-board-snapshot.json" "$refs/panel-recommendations.json") | ||
| bot_email="41898282+github-actions[bot]@users.noreply.github.com" | ||
| out="${GITHUB_OUTPUT:-/dev/stdout}" | ||
|
|
||
| # A JSON file from stdin without the dates every fetch rewrites. | ||
| shape() { | ||
| jq -S 'del(.fetched, .reviewed) | if .entries then .entries |= map(del(.checked)) else . end' | ||
| } | ||
|
|
||
| # The branch holds work that is not the job's: leave it alone and fail the run, so a stuck refresh is seen. | ||
| refuse() { | ||
| echo "::error::$1; left alone. Delete or merge the branch so the weekly refresh can continue." | ||
| echo "ready=false" >>"$out" | ||
| exit 1 | ||
| } | ||
|
|
||
| lease=() | ||
| if git ls-remote --exit-code --heads "$remote" "$branch" >/dev/null 2>&1; then | ||
| git fetch --no-tags "$remote" "$branch" | ||
| tip="$(git rev-parse FETCH_HEAD)" | ||
| # Every commit the branch has that main lacks must be the bot's and touch only the generated files. | ||
| while read -r commit; do | ||
| [ -n "$commit" ] || continue | ||
| # A merge commit (GitHub's "Update branch" makes one) lists no files of its own, so it is never the job's. | ||
| if [ "$(git log -1 --format=%ae "$commit")" != "$bot_email" ] \ | ||
| || [ "$(git rev-list --parents -n 1 "$commit" | wc -w)" -ne 2 ]; then | ||
| refuse "$branch has a commit that is not the workflow's, or is a merge ($commit)" | ||
| fi | ||
| while read -r name; do | ||
| [ -n "$name" ] || continue | ||
| if [ "$name" != "${files[0]}" ] && [ "$name" != "${files[1]}" ]; then | ||
| refuse "$branch has a commit that touches $name ($commit)" | ||
| fi | ||
| done < <(git diff-tree --no-commit-id --name-only -r "$commit") | ||
| done < <(git rev-list "$tip" "^HEAD") | ||
| same=true | ||
| for file in "${files[@]}"; do | ||
| if [ "$(shape <"$file")" != "$(git show "$tip:$file" | shape)" ]; then | ||
| same=false | ||
| fi | ||
| done | ||
| if [ "$same" = true ]; then | ||
| echo "$branch already holds this board; nothing pushed" | ||
| echo "ready=true" >>"$out" | ||
| exit 0 | ||
| fi | ||
| lease=("--force-with-lease=refs/heads/$branch:$tip") | ||
| fi | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "$bot_email" | ||
| git checkout -B "$branch" | ||
| git add -- "${files[@]}" | ||
| git commit -m "Panel recommendations: refresh the board snapshot and catalog" | ||
| git push ${lease[@]+"${lease[@]}"} "$remote" "$branch" | ||
| echo "ready=true" >>"$out" |
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,47 @@ | ||
| #!/usr/bin/env bash | ||
| # Refetches the public Bug Hunt board for the panel recommendations catalog and says whether anything but the | ||
| # dates changed. When it did, the catalog is checked and the skill's tests run before the caller commits it. | ||
| # Own results are never read: a fetch keeps the catalog's own entries as they are. Only the snapshot and the | ||
| # catalog are touched, and when nothing but a date changed they are put back byte for byte from copies taken | ||
| # before the fetch, so other edits in the references folder are never discarded. | ||
| # | ||
| # Usage: scripts/refresh-panel-board.sh (prints changed=true or changed=false; to $GITHUB_OUTPUT when set) | ||
| # PANEL_BOARD_FILE: a saved board to read instead of fetching (a dry run; it must sit outside the skill folder). | ||
| set -euo pipefail | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| refs=skills/hr-code-review/references | ||
| script=skills/hr-code-review/scripts/refresh-recommendations.mjs | ||
| snapshot="$refs/panel-board-snapshot.json" | ||
| catalog="$refs/panel-recommendations.json" | ||
| out="${GITHUB_OUTPUT:-/dev/stdout}" | ||
|
|
||
| # The files without the dates every fetch rewrites (the fetch date, the review date, each entry's checked date). | ||
| shape() { | ||
| jq -S 'del(.fetched, .reviewed) | if .entries then .entries |= map(del(.checked)) else . end' "$1" | ||
| } | ||
| before_snapshot="$(shape "$snapshot")" | ||
| before_catalog="$(shape "$catalog")" | ||
| saved="$(mktemp -d)" | ||
| trap 'rm -rf "$saved"' EXIT | ||
| cp "$snapshot" "$saved/snapshot.json" | ||
| cp "$catalog" "$saved/catalog.json" | ||
|
|
||
| args=(--fetch) | ||
| if [ -n "${PANEL_BOARD_FILE:-}" ]; then | ||
| args+=(--board-file "$PANEL_BOARD_FILE") | ||
| fi | ||
| bun "$script" "${args[@]}" | ||
|
|
||
| if [ "$before_snapshot" = "$(shape "$snapshot")" ] \ | ||
| && [ "$before_catalog" = "$(shape "$catalog")" ]; then | ||
| cp "$saved/snapshot.json" "$snapshot" | ||
| cp "$saved/catalog.json" "$catalog" | ||
| echo "the board is unchanged" | ||
| echo "changed=false" >>"$out" | ||
| exit 0 | ||
| fi | ||
|
|
||
| bun "$script" --check | ||
| bun test skills/hr-code-review test/doc-rules.test.mjs | ||
| echo "changed=true" >>"$out" |
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.