Skip to content

Commit b55395a

Browse files
feat: re-add branch protection toggling in release.yml (#144)
1 parent a9249b8 commit b55395a

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

.github/workflows/release.yml

+52-8
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,61 @@ jobs:
1818
- env:
1919
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2020
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
21-
- name: Temporarily disable "include administrators" branch protection
22-
uses: benjefferies/[email protected]
21+
- name: Delete branch protection on main
22+
uses: actions/[email protected]
2323
with:
24-
access_token: ${{ secrets.ACCESS_TOKEN }}
25-
branch: ${{ github.event.repository.default_branch }}
24+
github-token: ${{ secrets.ACCESS_TOKEN }}
25+
script: |
26+
try {
27+
await github.request(
28+
`DELETE /repos/JoshuaKGoldberg/template-typescript-node-package/branches/main/protection`,
29+
);
30+
} catch (error) {
31+
if (!error.message?.includes?.("Branch not protected")) {
32+
throw error;
33+
}
34+
}
2635
- env:
2736
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2837
run: pnpm release-it
2938
- if: always()
30-
name: Enable "include administrators" branch protection
31-
uses: benjefferies/[email protected]
39+
name: Recreate branch protection on main
40+
uses: actions/[email protected]
3241
with:
33-
access_token: ${{ secrets.ACCESS_TOKEN }}
34-
branch: ${{ github.event.repository.default_branch }}
42+
github-token: ${{ secrets.ACCESS_TOKEN }}
43+
# Note: keep this inline script in sync with script/setup.js!
44+
# Todo: it would be nice to not have two sources of truth...
45+
script: |
46+
github.request(
47+
`PUT /repos/JoshuaKGoldberg/template-typescript-node-package/branches/main/protection`,
48+
{
49+
allow_deletions: false,
50+
allow_force_pushes: true,
51+
allow_fork_pushes: false,
52+
allow_fork_syncing: true,
53+
block_creations: false,
54+
branch: "main",
55+
enforce_admins: false,
56+
owner: "JoshuaKGoldberg",
57+
repo: "template-typescript-node-package",
58+
required_conversation_resolution: true,
59+
required_linear_history: false,
60+
required_pull_request_reviews: null,
61+
required_status_checks: {
62+
checks: [
63+
{ context: "build" },
64+
{ context: "compliance" },
65+
{ context: "lint" },
66+
{ context: "markdown" },
67+
{ context: "package" },
68+
{ context: "packages" },
69+
{ context: "prettier" },
70+
{ context: "prune" },
71+
{ context: "spelling" },
72+
{ context: "test" },
73+
],
74+
strict: false,
75+
},
76+
restrictions: null,
77+
}
78+
);

script/setup.js

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ try {
197197
console.log();
198198
console.log(chalk.gray`Hydrating branch protection settings...`);
199199

200+
// Note: keep this inline script in sync with .github/workflows/release.yml!
201+
// Todo: it would be nice to not have two sources of truth...
200202
await octokit.request(
201203
`PUT /repos/${owner}/${repository}/branches/main/protection`,
202204
{

0 commit comments

Comments
 (0)