diff --git a/.github/workflows/pr-checklist.yml b/.github/workflows/pr-checklist.yml index ebe34dac..554bb73e 100644 --- a/.github/workflows/pr-checklist.yml +++ b/.github/workflows/pr-checklist.yml @@ -31,16 +31,15 @@ jobs: return; } - // Use regex patterns to be robust against checkbox formatting or minor phrasing changes - const requiredPatterns = [ - /preview_removals\.sh/i, - /data\/?backups/i, - /(i will not run|will not run|do not run|don't run|won't run).+--force/i, + // Use a set of named checks with robust regex patterns for checkbox and phrase variants + const checks = [ + { name: 'preview_removals.sh mention', pattern: /preview_removals\.sh/i }, + { name: 'data/backups mention', pattern: /data\/?backups/i }, + // Accept checked checkbox variants and inline code/backtick usage for the '--force' phrase + { name: 'explicit non-run of --force', pattern: /(?:\[\s*[xX]\s*\]\s*)?(?:i will not run|will not run|do not run|don'?t run|won'?t run)\b[^\n]*--force/i }, ]; - const missing = requiredPatterns - .map(p => ({ pattern: p, found: p.test(body) })) - .filter(x => !x.found) - .map(x => x.pattern.source); + + const missing = checks.filter(c => !c.pattern.test(body)).map(c => c.name); if (missing.length > 0) { // Post a comment to the PR with instructions for filling the checklist const commentBody = `Hi! This PR touches history-rewrite artifacts and requires the checklist in .github/PULL_REQUEST_TEMPLATE/history-rewrite.md. The following items are missing in your PR body: ${missing.join(', ')}\n\nPlease update the PR description using the history-rewrite template and re-run checks.`; diff --git a/scripts/history-rewrite/tests/clean_history.dryrun.bats b/scripts/history-rewrite/tests/clean_history.dryrun.bats index 27305bbf..11ec5243 100644 --- a/scripts/history-rewrite/tests/clean_history.dryrun.bats +++ b/scripts/history-rewrite/tests/clean_history.dryrun.bats @@ -33,7 +33,8 @@ teardown() { rm -rf "$TMPREPO" } -SCRIPT="/projects/Charon/scripts/history-rewrite/clean_history.sh" +REPO_ROOT=$(cd "$BATS_TEST_DIRNAME/../../../" && pwd) +SCRIPT="$REPO_ROOT/scripts/history-rewrite/clean_history.sh" @test "clean_history dry-run prints expected log and exits 0" { run bash "$SCRIPT" --dry-run --paths 'backend/codeql-db' --strip-size 1 @@ -42,7 +43,7 @@ SCRIPT="/projects/Charon/scripts/history-rewrite/clean_history.sh" } @test "preview_removals shows commits for the path" { - run bash /projects/Charon/scripts/history-rewrite/preview_removals.sh --paths 'backend/codeql-db' --strip-size 1 + run bash "$REPO_ROOT/scripts/history-rewrite/preview_removals.sh" --paths 'backend/codeql-db' --strip-size 1 [ "$status" -eq 0 ] [[ "$output" == *"Path: backend/codeql-db"* ]] } diff --git a/scripts/history-rewrite/tests/tag_objects_excluded.bats b/scripts/history-rewrite/tests/tag_objects_excluded.bats index 18b14531..a33e7d5a 100644 --- a/scripts/history-rewrite/tests/tag_objects_excluded.bats +++ b/scripts/history-rewrite/tests/tag_objects_excluded.bats @@ -19,7 +19,8 @@ teardown() { rm -rf "$TMPREPO" } -SCRIPT="/projects/Charon/scripts/ci/dry_run_history_rewrite.sh" +REPO_ROOT=$(cd "$BATS_TEST_DIRNAME/../../../" && pwd) +SCRIPT="$REPO_ROOT/scripts/ci/dry_run_history_rewrite.sh" @test "dry_run script ignores tag-only objects and passes" { run bash "$SCRIPT" --paths 'backend/codeql-db' --strip-size 50 diff --git a/scripts/history-rewrite/tests/validate_after_rewrite.bats b/scripts/history-rewrite/tests/validate_after_rewrite.bats index 4993ec4f..0e252837 100644 --- a/scripts/history-rewrite/tests/validate_after_rewrite.bats +++ b/scripts/history-rewrite/tests/validate_after_rewrite.bats @@ -23,7 +23,8 @@ teardown() { rm -rf "$TMPREPO" } -SCRIPT="/projects/Charon/scripts/history-rewrite/validate_after_rewrite.sh" +REPO_ROOT=$(cd "$BATS_TEST_DIRNAME/../../../" && pwd) +SCRIPT="$REPO_ROOT/scripts/history-rewrite/validate_after_rewrite.sh" @test "validate_after_rewrite fails when backup branch is missing" { run bash "$SCRIPT"