Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
startsWith(github.event.comment.body, '/codeboarding') &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 180

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay that's good

permissions:
contents: read
actions: read # download the analysis an earlier run published
Expand All @@ -60,7 +60,7 @@ jobs:
sync:
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 180
permissions:
contents: write
actions: read # catch up from an analysis a review saved
Expand All @@ -72,6 +72,8 @@ jobs:
llm: hosted
```

A first analysis of a large repository, around a million lines, can take over an hour, hence `timeout-minutes: 180`; GitHub bills the minutes used, not the limit.

Both jobs use the default `codeboarding_analysis_location`, so review always reads the analysis where sync saves it. If you set it, set it in both jobs. Keep both jobs in this one file: a repository running CodeBoarding from more than one workflow file is an [older setup](#moving-an-existing-setup), which the CodeBoarding dashboard flags and offers to fold into one.

## Review pull requests
Expand Down Expand Up @@ -380,7 +382,7 @@ Off by default. With `problem_history: 'true'` on the sync job, every sync (a pu
sync:
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 180
permissions:
contents: write # also writes codeboarding/briefing
actions: read # also reads merged pull requests' review artifacts
Expand Down
62 changes: 33 additions & 29 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ runs:
ANALYSIS_DIR: ${{ steps.sync_analyze.outputs.analysis_dir }}
CHECKOUT_DIR: ${{ github.workspace }}/.codeboarding-target
SYNCED_BRANCH: ${{ steps.guard.outputs.synced_branch }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
BASELINE_BRANCH: ${{ steps.guard.outputs.analysis_branch }}
ENGINE_VERSION: ${{ steps.state.outputs.engine_version }}
# Recorded with each baseline-branch commit, so a reader can tell which configuration made it.
Expand All @@ -553,15 +554,14 @@ runs:
run: "$GITHUB_ACTION_PATH/scripts/action/deliver-sync.sh"

# Named for the commit pull requests branch from, so a review that forks there
# finds this graph and skips analyzing the base entirely. Published under both
# the analyzed commit and the baseline commit written on top, because a pull
# request opened either side of that commit has a different merge base.
- name: Publish baseline analysis
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.baseline_sha != '' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com'
# finds this graph and skips analyzing the base entirely. Published whatever the
# delivery did, so a refused push does not throw the analysis away.
- name: Publish baseline analysis for the analyzed commit
if: "!cancelled() && steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_analyze.outcome == 'success' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com'"
continue-on-error: true
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.baseline_sha }}
name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_analyze.outputs.analyzed_sha }}
path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base
# Longer than a review's 14 days on purpose, and the margin is the whole
# point: correctness comes from the renewal check, which republishes any
Expand All @@ -572,12 +572,14 @@ runs:
retention-days: 30
if-no-files-found: ignore

- name: Publish baseline analysis for the analyzed commit
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.analyzed_sha != '' && steps.sync_commit.outputs.analyzed_sha != steps.sync_commit.outputs.baseline_sha && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com'
# Also under the commit in_place writes on top of the analyzed one: a pull request
# opened either side of that commit has a different merge base.
- name: Publish baseline analysis for the baseline commit
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.baseline_sha != '' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com'
continue-on-error: true
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.analyzed_sha }}
name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.baseline_sha }}
path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base
# Longer than a review's 14 days on purpose, and the margin is the whole
# point: correctness comes from the renewal check, which republishes any
Expand Down Expand Up @@ -650,6 +652,28 @@ runs:
KEEP_AUTH: 'true'
run: '"$GITHUB_ACTION_PATH/scripts/action/with-auth.sh" "$GITHUB_ACTION_PATH/scripts/action/review-generate-baseline.sh"'

# Published before the head is analyzed, so a run that then fails or times out
# does not leave the next review to build the base again.
# Only a trusted run publishes a base graph: it is named for a commit, so
# every pull request forking there would read it, and a fork's analysis must
# never be what they read.
- name: Publish base analysis
id: publish_base
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.review_baseline.outputs.publish_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.state.outputs.base_name != '' && github.server_url == 'https://github.com'
continue-on-error: true
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ steps.state.outputs.base_name }}
path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base
# Longer than a review's 14 days on purpose, and the margin is the whole
# point: correctness comes from the renewal check, which republishes any
# base with less than a review's lifetime left, while this surplus
# decides how often that fires. Equal lifetimes renew on every run and
# publish a base per run rather than per merge base — more storage, not
# less. 30 leaves a 16-day reuse window.
retention-days: 30
if-no-files-found: ignore

- name: Analyze pull request
id: review_analyze
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review'
Expand Down Expand Up @@ -687,26 +711,6 @@ runs:
retention-days: ${{ inputs.warmstart_retention_days }}
if-no-files-found: ignore

# Only a trusted run publishes a base graph: it is named for a commit, so
# every pull request forking there would read it, and a fork's analysis must
# never be what they read.
- name: Publish base analysis
id: publish_base
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.review_baseline.outputs.publish_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.state.outputs.base_name != '' && github.server_url == 'https://github.com'
continue-on-error: true
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ steps.state.outputs.base_name }}
path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base
# Longer than a review's 14 days on purpose, and the margin is the whole
# point: correctness comes from the renewal check, which republishes any
# base with less than a review's lifetime left, while this surplus
# decides how often that fires. Equal lifetimes renew on every run and
# publish a base per run rather than per merge base — more storage, not
# less. 30 leaves a 16-day reuse window.
retention-days: 30
if-no-files-found: ignore

- name: Render review diagram
id: review_render
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review'
Expand Down
27 changes: 17 additions & 10 deletions docs/COMMIT_STRATEGY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ pays for them. Health configuration stays, because a run seeded from a bundle
reads it.

The base graph is published only by the run that *computed* it, so it is written
about once per merge base rather than once per run — with two exceptions. A
review artifact references a base by id for its whole retention, so a base about
to expire inside that window is republished rather than left dangling under a
review that outlives it. And when no artifact holds the base at all, because the
about once per merge base rather than once per run. It is published as soon as it
exists, before the head is analyzed: building a base from scratch can take most of
a job's time limit, and a run that then fails or times out on the head still saves
it, so the next review starts from it instead of building it again. There are two
exceptions to "once per merge base". A review artifact references a base by id
for its whole retention, so a base about to expire inside that window is
republished rather than left dangling under a review that outlives it. And when no artifact holds the base at all, because the
upload failed or because a fork review publishes nothing, the review artifact
carries the graph inline and leaves `base_artifact` empty: a reader should prefer
an inline `base_analysis.json` and fall back to the named artifact — ten runs on one pull request
Expand Down Expand Up @@ -75,8 +78,10 @@ never fires.
| `analysed_files_changed` | string | analysed files whose content hash differs between base and head; `unknown` when the analyses cannot say |
| `pr_number`, `mode`, `seed_source`, `chain_depth` | string | provenance; nothing rendering a diagram needs them. `mode` is the head's engine mode |

**A sync run** publishes the base graph under both the commit it analyzed and the
baseline commit it writes on top, because a pull request opened either side of
**A sync run** publishes the base graph under the commit it analyzed whether or
not delivering it succeeds, so a push the remote refuses does not throw the
analysis away: the next sync or review catches up from the artifact. When delivery writes a baseline commit on top (`in_place`), it
is published under that commit too, because a pull request opened either side of
that commit has a different merge base.

## Retention is what costs
Expand Down Expand Up @@ -195,9 +200,11 @@ a code branch that happens to be named `codeboarding/baseline` fails, before any
during the analysis, the result is still saved for the commit it analyzed:
entries are keyed by commit, and a branch that merges faster than sync runs would
otherwise never be saved. Only an analysis of an older commit than the tip's is
dropped, so the tip stays the latest diagram. If another sync moved the baseline branch, it builds on that tip once. A push the
remote refuses while the tip did not move is a branch rule, and the run fails
saying so.
dropped, so the tip stays the latest diagram. If another sync moved the baseline branch, it builds on that tip once. A push GitHub
refuses with a branch rule error (`GH006` for branch protection, `GH013` for a
ruleset) fails the run naming the bypass to add; any other refusal while the tip
did not move fails it asking to check the token. On github.com the analysis is
still published as an artifact.

The tip is compared just before the push, not in the same transaction: if a sync
of a newer commit lands in that window, the push is no longer a fast-forward and
Expand Down Expand Up @@ -234,7 +241,7 @@ from a same-repository pull request branch, can still push to the branch and pla
the pickle sync loads.

Creation is covered too, so the bypass actor must be the identity sync pushes as
before the first sync, or that sync fails on the rule. Rulesets on a private repository need a paid GitHub plan
before the first sync, or that sync fails on the rule, saying which bypass to add. Rulesets on a private repository need a paid GitHub plan
(Pro, Team or Enterprise); on Free they apply to public repositories only.

## Trust boundary
Expand Down
22 changes: 15 additions & 7 deletions scripts/action/codeboarding-baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ baseline_fail() {
exit 1
}

# True when git push output $1 is GitHub refusing a branch rule: GH006 is classic
# branch protection, GH013 a ruleset.
refused_by_rule() { grep -qiE 'protected branch|GH006|GH013|rule violation' <<< "$1"; }

# Returns 0 when branch $2 (BASELINE_BRANCH by default) exists in repository $1 and
# 2 when it does not. Any other failure is retried once, so one network blip does
# not fail the run.
Expand Down Expand Up @@ -108,7 +112,7 @@ from_codeboarding_baseline() {
# whose REMOTE, BASE_SHA and emit_result it uses; always exits.
save_to_codeboarding_baseline() {
local branch="$BASELINE_BRANCH" tree="$RUNNER_TEMP/codeboarding-baseline-tree"
local index="$RUNNER_TEMP/codeboarding-baseline-index" git_dir files new_tree tip tip_source parent commit now
local index="$RUNNER_TEMP/codeboarding-baseline-index" git_dir files new_tree tip tip_source parent commit push_output now
git_dir="$(git rev-parse --absolute-git-dir)"
rm -rf "$tree" "$index"
mkdir -p "$tree"
Expand Down Expand Up @@ -154,15 +158,15 @@ CodeBoarding-Config: $CFG_HASH")
parent=(-p "$tip")
if [ "$tip_source" = "$BASE_SHA" ] &&
git diff --quiet -I '"generated_at"' -I '"timestamp"' "$tip" "$new_tree"; then
emit_result "$files" false "$BASE_SHA"
emit_result "$files" false
echo "::notice::$branch already holds this analysis of $SYNCED_BRANCH @${BASE_SHA:0:7}."
exit 0
fi
# The tip is the latest diagram, so an older analysis never replaces a newer one.
if [ "$tip_source" != "$BASE_SHA" ]; then
git fetch -q --depth="$(( CATCHUP_BOUND + 1 ))" "$REMOTE" "$SYNCED_BRANCH"
if git merge-base --is-ancestor "$BASE_SHA" "$tip_source" 2>/dev/null; then
emit_result "$files" false "$BASE_SHA"
emit_result "$files" false
echo "::notice::$branch already holds the analysis of a newer commit, ${tip_source:0:7}; leaving it."
exit 0
fi
Expand All @@ -171,16 +175,20 @@ CodeBoarding-Config: $CFG_HASH")
commit="$(git commit-tree "$new_tree" ${parent[@]+"${parent[@]}"} \
-m "chore(codeboarding): diagram of $SYNCED_BRANCH @${BASE_SHA:0:7}" "${trailers[@]}")"
# Never forced: the parent is the tip just read, so this only ever fast-forwards.
if git push -q "$REMOTE" "$commit:refs/heads/$branch"; then
emit_result "$files" true "$BASE_SHA"
if push_output="$(git push -q "$REMOTE" "$commit:refs/heads/$branch" 2>&1)"; then
emit_result "$files" true
exit 0
fi
echo "$push_output" >&2
if refused_by_rule "$push_output"; then
baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Add GitHub Actions (or the CodeBoarding app, if github_token is its token) as a bypass actor: https://github.com/CodeBoarding/CodeBoarding-action/blob/main/docs/COMMIT_STRATEGY.md#the-baseline-branch"
fi
now="$(git ls-remote "$REMOTE" "refs/heads/$branch" | awk '{print $1; exit}')"
if [ "$now" = "$tip" ]; then
baseline_fail "GitHub refused the push to $branch, most likely because a branch rule protects it. Add the identity sync pushes with (the CodeBoarding app, or GitHub Actions for the default token) as a bypass actor for $branch in the repository's rulesets, and check that github_token may push to it."
baseline_fail "GitHub refused the push to $branch. Check that github_token may push to it and that no branch rule covers it."
fi
done
emit_result "$files" false "$BASE_SHA"
emit_result "$files" false
echo "::notice::Another sync keeps updating $branch; leaving it to that run."
exit 0
}
34 changes: 20 additions & 14 deletions scripts/action/deliver-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ SH
chmod 700 "$ASKPASS"
export GIT_ASKPASS="$ASKPASS" GIT_TERMINAL_PROMPT=0
trap 'rm -f "$ASKPASS"' EXIT
# A pull request's merge base is whichever commit its author branched from, and
# this run's analysis is valid for two of them: the commit it analyzed, and the
# baseline commit it writes on top, which differs only in .codeboarding files
# that the fingerprint ignores. Publishing both means a pull request opened
# either side of a sync commit still gets an exact hit.
# baseline_sha is the commit written on top of the analyzed one, set only when
# in_place writes one. It differs only in .codeboarding files the fingerprint
# ignores, so the analysis is published under it too: a pull request opened
# either side of it still gets an exact hit.
emit_result() {
printf 'files_written=%s\ncommitted=%s\nbaseline_sha=%s\nanalyzed_sha=%s\n' \
"$1" "$2" "$3" "$BASE_SHA" >> "$GITHUB_OUTPUT"
printf 'files_written=%s\ncommitted=%s\nbaseline_sha=%s\n' "$1" "$2" "${3:-}" >> "$GITHUB_OUTPUT"
}
classify_push_failure() {
local expected="$1" branch="$2" current
local expected="$1" branch="$2" push_output="$3" current
current="$(git ls-remote "$REMOTE" "refs/heads/$branch" | awk '{print $1; exit}')"
[ "$current" != "$(git rev-parse HEAD)" ] || return 0
if [ "$current" != "$expected" ]; then
emit_result "$files_written" false "$BASE_SHA"
emit_result "$files_written" false
echo "::notice::A newer run updated $branch; leaving it untouched."
exit 0
fi
if refused_by_rule "$push_output"; then
# Only the default branch's analysis can live on codeboarding/baseline.
if [ "$branch" = "${DEFAULT_BRANCH:-}" ]; then
baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Remove \`codeboarding_analysis_location: in_place\` from both CodeBoarding jobs, and sync saves the analysis to \`codeboarding/baseline\`, a branch of its own: https://github.com/CodeBoarding/CodeBoarding-action#keep-the-baseline-current"
fi
baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Add GitHub Actions (or the CodeBoarding app, if github_token is its token) as a bypass actor: https://github.com/CodeBoarding/CodeBoarding-action#keep-the-analysis-on-the-code-branch"
fi
baseline_fail "Could not push the CodeBoarding baseline to $branch."
}

Expand Down Expand Up @@ -67,7 +72,7 @@ files_written="$(find "$CHECKOUT_DIR/.codeboarding" -maxdepth 1 -type f \
git fetch "$REMOTE" "$SYNCED_BRANCH"
remote_sha="$(git rev-parse FETCH_HEAD)"
if [ "$remote_sha" != "$BASE_SHA" ]; then
emit_result "$files_written" false "$BASE_SHA"
emit_result "$files_written" false
echo "::notice::$SYNCED_BRANCH advanced during analysis; a newer run should update its baseline."
exit 0
fi
Expand All @@ -77,14 +82,15 @@ fi
# every run. Dropping either filter turns every sync into a commit.
if git diff --cached --quiet || git diff --cached --quiet -I '"generated_at"' -I '"timestamp"'; then
git reset -q
emit_result "$files_written" false "$BASE_SHA"
emit_result "$files_written" false
echo "::notice::The CodeBoarding baseline is unchanged."
exit 0
fi

git commit -m 'chore(codeboarding): sync analysis baseline' >/dev/null

if ! git push "$REMOTE" "HEAD:refs/heads/$SYNCED_BRANCH"; then
classify_push_failure "$BASE_SHA" "$SYNCED_BRANCH"
fi
push_status=0
push_output="$(git push "$REMOTE" "HEAD:refs/heads/$SYNCED_BRANCH" 2>&1)" || push_status=$?
echo "$push_output" >&2
[ "$push_status" = 0 ] || classify_push_failure "$BASE_SHA" "$SYNCED_BRANCH" "$push_output"
emit_result "$files_written" true "$(git rev-parse HEAD)"
2 changes: 2 additions & 0 deletions scripts/action/sync-generate-baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ stage "$state" base
{
echo "$result"
echo "analysis_dir=$state"
# The base is published under this commit whatever the delivery does.
echo "analyzed_sha=$head_sha"
} >> "$GITHUB_OUTPUT"
Loading
Loading