Skip to content
Draft
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
11 changes: 6 additions & 5 deletions .github/scripts/version-archive-review.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const STATUS_CONTEXT = 'version-archives';
const POLICY_PATHS = new Set([
'.github/version_protection.md',
'docs/bylaws.md',
'.github/workflows/version-archive-review.yml',
'.github/workflows/version-archive-review-signal.yml',
'.github/scripts/version-archive-review.cjs',
Expand Down Expand Up @@ -68,10 +69,10 @@ async function run({ github, context, core, pull_number }) {
if (files.length >= 3000) throw new Error('PR has 3000+ files; cannot verify complete changes');
const paths = protectedFiles(files);
if (!paths.length) {
await status('success', 'No archive approval required');
await status('success', 'No protected-file approval required');
return;
}
await status('pending', 'Checking approvals for archived documentation changes');
await status('pending', 'Checking approvals for protected documentation changes');
const reviews = await github.paginate(github.rest.pulls.listReviews, {
owner, repo, pull_number: prNumber, per_page: 100
});
Expand All @@ -83,14 +84,14 @@ async function run({ github, context, core, pull_number }) {
if (['admin', 'write'].includes(data.permission)) eligible.push(reviewer);
}
if (eligible.length) {
await status('success', 'Archive changes approved by ' + eligible[0]);
await status('success', 'Protected changes approved by ' + eligible[0]);
} else {
await status('failure', 'Archived documentation changes require approval');
await status('failure', 'Protected documentation changes require approval');
core.setFailed('Changes to ' + paths.join(', ') +
' require a fresh APPROVED review from a different human with write/admin access on SHA ' + sha);
}
} catch (error) {
await status('failure', 'Unable to verify version archive approvals');
await status('failure', 'Unable to verify protected-file approvals');
throw error;
}
}
Expand Down
35 changes: 27 additions & 8 deletions .github/scripts/version-archive-review.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { run, protectedFiles, approvedReviewers } = require('./version-archive-re
test('detects all protected version paths and historic rename sources', () => {
assert.deepEqual(protectedFiles([
{ filename: 'docs/intro.md' },
{ filename: 'docs/bylaws.md' },
{ filename: 'docs/renamed-bylaws.md', previous_filename: 'docs/bylaws.md' },
{ filename: 'versions/archive-0.1.0/intro.md' },
{ filename: 'new/location.md', previous_filename: 'versions/archive-0.1.0/old.md' },
{ filename: 'versions/sidebars/version-0.1.0.json' },
Expand All @@ -17,13 +19,27 @@ test('detects all protected version paths and historic rename sources', () => {
'.github/scripts/version-archive-review.cjs',
'.github/version_protection.md',
'.github/workflows/version-archive-review.yml',
'docs/bylaws.md',
'versions/archive-0.1.0/intro.md',
'versions/archive-0.1.0/old.md',
'versions/sidebars/version-0.1.0.json'
]);
assert.deepEqual(protectedFiles([{ filename: 'docs/intro.md' }]), []);
});

test('protects bylaws additions, edits, deletions, and both rename directions', () => {
for (const file of [
{ filename: 'docs/bylaws.md', status: 'added' },
{ filename: 'docs/bylaws.md', status: 'modified' },
{ filename: 'docs/bylaws.md', status: 'removed' },
{ filename: 'docs/relocated.md', previous_filename: 'docs/bylaws.md', status: 'renamed' },
{ filename: 'docs/bylaws.md', previous_filename: 'docs/old.md', status: 'renamed' }
]) {
assert.ok(protectedFiles([file]).includes('docs/bylaws.md'));
}
assert.deepEqual(protectedFiles([{ filename: 'docs/bylaws-notes.md' }]), []);
});

test('only most recent independent human approval on exact head counts', () => {
assert.deepEqual(approvedReviewers([
{ id: 1, user: { login: 'author', type: 'User' }, state: 'APPROVED', commit_id: 'new' },
Expand Down Expand Up @@ -85,7 +101,8 @@ test('unrelated docs changes pass automatically without fetching reviews', async
for (const filename of [
'versions/archive-0.1.0/intro.md', 'versions/sidebars/version-0.1.0.json',
'.github/scripts/version-archive-review.cjs',
'.github/version_protection.md'
'.github/version_protection.md',
'docs/bylaws.md'
]) {
test('unapproved protected change fails: ' + filename, async () => {
const gh = fake({ files: [{ filename }] });
Expand All @@ -104,14 +121,16 @@ test('renaming a file out of versions still requires approval', async () => {
assert.equal(errors.length, 1);
});

test('fresh independent contributor approval passes', async () => {
const gh = fake({
files: [{ filename: 'versions/sidebars/version-0.1.0.json' }],
reviews: [{ id: 1, user: { login: 'reviewer', type: 'User' }, state: 'APPROVED', commit_id: 'head' }]
for (const filename of ['versions/sidebars/version-0.1.0.json', 'docs/bylaws.md']) {
test('fresh independent contributor approval passes: ' + filename, async () => {
const gh = fake({
files: [{ filename }],
reviews: [{ id: 1, user: { login: 'reviewer', type: 'User' }, state: 'APPROVED', commit_id: 'head' }]
});
await run({ github: gh, context, core: { setFailed: () => { throw new Error('unexpected'); } } });
assert.deepEqual(gh.statuses.map(x => x.state), ['pending', 'success']);
});
await run({ github: gh, context, core: { setFailed: () => { throw new Error('unexpected'); } } });
assert.deepEqual(gh.statuses.map(x => x.state), ['pending', 'success']);
});
}

test('stale review, bot review, self approval, or read-only reviewer fail', async () => {
for (const [reviewer, permission] of [
Expand Down
5 changes: 4 additions & 1 deletion .github/version_protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The root manifest is ignored by Git. Do **not** create `versions/history.json`.
Protected changes include:

- All paths under `versions/`, including archived snapshots and sidebars.
- `docs/bylaws.md`, the governing bylaws path proposed in PR #56, including
additions, amendments, deletions, and renames to or from this path.
- The version generation, staging and cleanup scripts under `scripts/`.
- `package.json`, `.gitignore`, the version-protection policy, and the
privileged verifier workflow and helper files to prevent unreviewed bypasses.
Expand Down Expand Up @@ -45,7 +47,8 @@ create an active branch ruleset called **Version archive protection**:
4. Prohibit force pushes and deletions; do not configure bypass permissions.
5. Verify a test PR changing `versions/archive-0.1.0/` is blocked until
another write/admin collaborator approves the current head SHA.
Confirm that a `docs/`-only PR passes without this approval.
Confirm that an unrelated `docs/`-only PR passes without this approval,
while a PR modifying `docs/bylaws.md` requires approval.

After merging the workflow, open or update a PR to produce the first
`version-archives` check if the ruleset UI does not yet list it.
Expand Down
Loading