Skip to content

Commit 58c31de

Browse files
feat: use release-it-action for release flow (#927)
## PR Checklist - [x] Addresses an existing open issue: fixes #145 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Uses my new https://github.com/JoshuaKGoldberg/release-it-action that contains much of the same logic as the previous `release.yml` contents. I stuck with the "delete and recreate branch protections" approach because (a) it's worked well and (b) other approaches had other limitations. I can't be 100% sure this works in this repo until it lands on `main` and tries a few release flows. But I did test it in a separate repo and it worked well there.
1 parent ef2e348 commit 58c31de

File tree

3 files changed

+6
-200
lines changed

3 files changed

+6
-200
lines changed

.github/workflows/release.yml

+2-62
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,10 @@ jobs:
1111
ref: main
1212
- uses: ./.github/actions/prepare
1313
- run: pnpm build
14-
- run: git config user.name "${GITHUB_ACTOR}"
15-
- run: git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
16-
- env:
17-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
18-
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
19-
- name: Delete branch protection on main
20-
uses: actions/[email protected]
21-
with:
22-
github-token: ${{ secrets.ACCESS_TOKEN }}
23-
script: |
24-
try {
25-
await github.request(
26-
`DELETE /repos/JoshuaKGoldberg/create-typescript-app/branches/main/protection`,
27-
);
28-
} catch (error) {
29-
if (!error.message?.includes?.("Branch not protected")) {
30-
throw error;
31-
}
32-
}
3314
- env:
3415
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
35-
run: |
36-
if pnpm run should-semantic-release ; then
37-
pnpm release-it --verbose
38-
fi
39-
- if: always()
40-
name: Recreate branch protection on main
41-
uses: actions/[email protected]
42-
with:
43-
github-token: ${{ secrets.ACCESS_TOKEN }}
44-
script: |
45-
github.request(
46-
`PUT /repos/JoshuaKGoldberg/create-typescript-app/branches/main/protection`,
47-
{
48-
allow_deletions: false,
49-
allow_force_pushes: true,
50-
allow_fork_pushes: false,
51-
allow_fork_syncing: true,
52-
block_creations: false,
53-
branch: "main",
54-
enforce_admins: false,
55-
owner: "JoshuaKGoldberg",
56-
repo: "create-typescript-app",
57-
required_conversation_resolution: true,
58-
required_linear_history: false,
59-
required_pull_request_reviews: null,
60-
required_status_checks: {
61-
checks: [
62-
{ context: "build" },
63-
{ context: "compliance" },
64-
{ context: "lint" },
65-
{ context: "lint_knip" },
66-
{ context: "lint_markdown" },
67-
{ context: "lint_package_json" },
68-
{ context: "lint_packages" },
69-
{ context: "lint_spelling" },
70-
{ context: "prettier" },
71-
{ context: "test" },
72-
],
73-
strict: false,
74-
},
75-
restrictions: null,
76-
}
77-
);
16+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
17+
uses: JoshuaKGoldberg/[email protected]
7818

7919
name: Release
8020

src/steps/writing/creation/dotGitHub/createWorkflows.test.ts

+2-62
Original file line numberDiff line numberDiff line change
@@ -281,70 +281,10 @@ describe("createWorkflows", () => {
281281
ref: main
282282
- uses: ./.github/actions/prepare
283283
- run: pnpm build
284-
- run: git config user.name \\"\${GITHUB_ACTOR}\\"
285-
- run: git config user.email \\"\${GITHUB_ACTOR}@users.noreply.github.com\\"
286-
- env:
287-
NPM_TOKEN: \${{ secrets.NPM_TOKEN }}
288-
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
289-
- name: Delete branch protection on main
290-
uses: actions/[email protected]
291-
with:
292-
github-token: \${{ secrets.ACCESS_TOKEN }}
293-
script: |
294-
try {
295-
await github.request(
296-
\`DELETE /repos/StubOwner/stub-repository/branches/main/protection\`,
297-
);
298-
} catch (error) {
299-
if (!error.message?.includes?.(\\"Branch not protected\\")) {
300-
throw error;
301-
}
302-
}
303284
- env:
304285
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
305-
run: |
306-
if pnpm run should-semantic-release ; then
307-
pnpm release-it --verbose
308-
fi
309-
- if: always()
310-
name: Recreate branch protection on main
311-
uses: actions/[email protected]
312-
with:
313-
github-token: \${{ secrets.ACCESS_TOKEN }}
314-
script: |
315-
github.request(
316-
\`PUT /repos/StubOwner/stub-repository/branches/main/protection\`,
317-
{
318-
allow_deletions: false,
319-
allow_force_pushes: true,
320-
allow_fork_pushes: false,
321-
allow_fork_syncing: true,
322-
block_creations: false,
323-
branch: \\"main\\",
324-
enforce_admins: false,
325-
owner: \\"StubOwner\\",
326-
repo: \\"stub-repository\\",
327-
required_conversation_resolution: true,
328-
required_linear_history: false,
329-
required_pull_request_reviews: null,
330-
required_status_checks: {
331-
checks: [
332-
{ context: \\"build\\" },
333-
{ context: \\"compliance\\" },
334-
{ context: \\"lint\\" },
335-
{ context: \\"lint_knip\\" },
336-
{ context: \\"lint_markdown\\" },
337-
{ context: \\"lint_package_json\\" },
338-
{ context: \\"lint_packages\\" },
339-
{ context: \\"lint_spelling\\" },
340-
{ context: \\"prettier\\" },
341-
{ context: \\"test\\" },
342-
],
343-
strict: false,
344-
},
345-
restrictions: null,
346-
}
347-
);
286+
NPM_TOKEN: \${{ secrets.NPM_TOKEN }}
287+
uses: JoshuaKGoldberg/[email protected]
348288
349289
name: Release
350290

src/steps/writing/creation/dotGitHub/createWorkflows.ts

+2-76
Original file line numberDiff line numberDiff line change
@@ -182,86 +182,12 @@ export function createWorkflows(options: Options) {
182182
{
183183
run: "pnpm build",
184184
},
185-
{
186-
run: 'git config user.name "${GITHUB_ACTOR}"',
187-
},
188-
{
189-
run: 'git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"',
190-
},
191-
{
192-
env: {
193-
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}",
194-
},
195-
run: "npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN",
196-
},
197-
{
198-
name: "Delete branch protection on main",
199-
uses: "actions/[email protected]",
200-
with: {
201-
"github-token": "${{ secrets.ACCESS_TOKEN }}",
202-
script: `
203-
try {
204-
await github.request(
205-
\`DELETE /repos/${options.owner}/${options.repository}/branches/main/protection\`,
206-
);
207-
} catch (error) {
208-
if (!error.message?.includes?.("Branch not protected")) {
209-
throw error;
210-
}
211-
}`,
212-
},
213-
},
214185
{
215186
env: {
216187
GITHUB_TOKEN: "${{ secrets.ACCESS_TOKEN }}",
188+
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}",
217189
},
218-
run: `
219-
if pnpm run should-semantic-release ; then
220-
pnpm release-it --verbose
221-
fi`,
222-
},
223-
{
224-
if: "always()",
225-
name: "Recreate branch protection on main",
226-
uses: "actions/[email protected]",
227-
with: {
228-
"github-token": "${{ secrets.ACCESS_TOKEN }}",
229-
script: `
230-
github.request(
231-
\`PUT /repos/${options.owner}/${options.repository}/branches/main/protection\`,
232-
{
233-
allow_deletions: false,
234-
allow_force_pushes: true,
235-
allow_fork_pushes: false,
236-
allow_fork_syncing: true,
237-
block_creations: false,
238-
branch: "main",
239-
enforce_admins: false,
240-
owner: "${options.owner}",
241-
repo: "${options.repository}",
242-
required_conversation_resolution: true,
243-
required_linear_history: false,
244-
required_pull_request_reviews: null,
245-
required_status_checks: {
246-
checks: [
247-
{ context: "build" },
248-
{ context: "compliance" },
249-
{ context: "lint" },
250-
{ context: "lint_knip" },
251-
{ context: "lint_markdown" },
252-
{ context: "lint_package_json" },
253-
{ context: "lint_packages" },
254-
{ context: "lint_spelling" },
255-
{ context: "prettier" },
256-
{ context: "test" },
257-
],
258-
strict: false,
259-
},
260-
restrictions: null,
261-
}
262-
);
263-
`,
264-
},
190+
uses: "JoshuaKGoldberg/[email protected]",
265191
},
266192
],
267193
}),

0 commit comments

Comments
 (0)