Skip to content

Commit cbcc586

Browse files
authoredApr 2, 2025··
fix: use options.node in CI prepare action (#2100)
## PR Checklist - [x] Addresses an existing open issue: fixes #2096 - [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 Switches `.github/actions/prepare/action.yml` to use the Node version requested by options, not a hardcoded `"20"`. Also fixes the `node` option schema to no longer be marked `.optional()`. It was always inferred, so this was inaccurate. 🎁
1 parent 7f4f226 commit cbcc586

10 files changed

+238
-23
lines changed
 

‎.github/actions/prepare/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ runs:
88
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
99
with:
1010
cache: pnpm
11-
node-version: "20"
11+
node-version: 22.14.0
1212
- run: pnpm install --frozen-lockfile
1313
shell: bash
1414
using: composite

‎src/base.ts

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export const base = createBase({
130130
minimum: z.string(),
131131
pinned: z.string().optional(),
132132
})
133-
.optional()
134133
.describe("Node.js engine version(s) to pin and require a minimum of"),
135134
owner: z.string().describe("organization or user owning the repository"),
136135
packageData: z

‎src/blocks/blockCSpell.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe("blockCSpell", () => {
280280
"scripts": [
281281
{
282282
"commands": [
283-
"node path/to/cspell-populate-words/bin/index.mjs --words "access" --words "public" --words "description" --words "Test description" --words "directory" --words "." --words "documentation" --words "readme" --words "usage" --words "Test usage." --words "email" --words "github" --words "github@email.com" --words "npm" --words "npm@email.com" --words "emoji" --words "💖" --words "owner" --words "test-owner" --words "preset" --words "minimal" --words "repository" --words "test-repository" --words "title" --words "Test Title"",
283+
"node path/to/cspell-populate-words/bin/index.mjs --words "access" --words "public" --words "description" --words "Test description" --words "directory" --words "." --words "documentation" --words "readme" --words "usage" --words "Test usage." --words "email" --words "github" --words "github@email.com" --words "npm" --words "npm@email.com" --words "emoji" --words "💖" --words "node" --words "minimum" --words "20.12.0" --words "owner" --words "test-owner" --words "preset" --words "minimal" --words "repository" --words "test-repository" --words "title" --words "Test Title"",
284284
],
285285
"phase": 3,
286286
},

‎src/blocks/blockGitHubActionsCI.test.ts

+214-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,217 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
55
import { optionsBase } from "./options.fakes.js";
66

77
describe("blockGitHubActionsCI", () => {
8+
test("without options.node.pinned", () => {
9+
const creation = testBlock(blockGitHubActionsCI, {
10+
options: {
11+
...optionsBase,
12+
node: {
13+
minimum: "20.12.0",
14+
},
15+
},
16+
});
17+
18+
expect(creation).toMatchInlineSnapshot(`
19+
{
20+
"addons": [
21+
{
22+
"addons": {
23+
"requiredStatusChecks": undefined,
24+
},
25+
"block": [Function],
26+
},
27+
],
28+
"files": {
29+
".github": {
30+
"actions": {
31+
"prepare": {
32+
"action.yml": "description: Prepares the repo for a typical CI job
33+
34+
name: Prepare
35+
36+
runs:
37+
steps:
38+
- uses: pnpm/action-setup@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
cache: pnpm
42+
node-version: 20.12.0
43+
- run: pnpm install --frozen-lockfile
44+
shell: bash
45+
using: composite
46+
",
47+
},
48+
},
49+
"workflows": {
50+
"accessibility-alt-text-bot.yml": "jobs:
51+
accessibility_alt_text_bot:
52+
if: \${{ !endsWith(github.actor, '[bot]') }}
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: github/accessibility-alt-text-bot@v1.4.0
56+
57+
58+
name: Accessibility Alt Text Bot
59+
60+
61+
on:
62+
issue_comment:
63+
types:
64+
- created
65+
- edited
66+
issues:
67+
types:
68+
- edited
69+
- opened
70+
pull_request:
71+
types:
72+
- edited
73+
- opened
74+
75+
76+
permissions:
77+
issues: write
78+
pull-requests: write
79+
",
80+
"ci.yml": undefined,
81+
"pr-review-requested.yml": "jobs:
82+
pr_review_requested:
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions-ecosystem/action-remove-labels@v1
86+
with:
87+
labels: 'status: waiting for author'
88+
- if: failure()
89+
run: |
90+
echo "Don't worry if the previous step failed."
91+
echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."
92+
93+
94+
name: PR Review Requested
95+
96+
97+
on:
98+
pull_request_target:
99+
types:
100+
- review_requested
101+
102+
103+
permissions:
104+
pull-requests: write
105+
",
106+
},
107+
},
108+
},
109+
}
110+
`);
111+
});
112+
113+
test("with options.node.pinned", () => {
114+
const creation = testBlock(blockGitHubActionsCI, {
115+
options: {
116+
...optionsBase,
117+
node: {
118+
minimum: "20.12.0",
119+
pinned: "22.12.0",
120+
},
121+
},
122+
});
123+
124+
expect(creation).toMatchInlineSnapshot(`
125+
{
126+
"addons": [
127+
{
128+
"addons": {
129+
"requiredStatusChecks": undefined,
130+
},
131+
"block": [Function],
132+
},
133+
],
134+
"files": {
135+
".github": {
136+
"actions": {
137+
"prepare": {
138+
"action.yml": "description: Prepares the repo for a typical CI job
139+
140+
name: Prepare
141+
142+
runs:
143+
steps:
144+
- uses: pnpm/action-setup@v4
145+
- uses: actions/setup-node@v4
146+
with:
147+
cache: pnpm
148+
node-version: 22.12.0
149+
- run: pnpm install --frozen-lockfile
150+
shell: bash
151+
using: composite
152+
",
153+
},
154+
},
155+
"workflows": {
156+
"accessibility-alt-text-bot.yml": "jobs:
157+
accessibility_alt_text_bot:
158+
if: \${{ !endsWith(github.actor, '[bot]') }}
159+
runs-on: ubuntu-latest
160+
steps:
161+
- uses: github/accessibility-alt-text-bot@v1.4.0
162+
163+
164+
name: Accessibility Alt Text Bot
165+
166+
167+
on:
168+
issue_comment:
169+
types:
170+
- created
171+
- edited
172+
issues:
173+
types:
174+
- edited
175+
- opened
176+
pull_request:
177+
types:
178+
- edited
179+
- opened
180+
181+
182+
permissions:
183+
issues: write
184+
pull-requests: write
185+
",
186+
"ci.yml": undefined,
187+
"pr-review-requested.yml": "jobs:
188+
pr_review_requested:
189+
runs-on: ubuntu-latest
190+
steps:
191+
- uses: actions-ecosystem/action-remove-labels@v1
192+
with:
193+
labels: 'status: waiting for author'
194+
- if: failure()
195+
run: |
196+
echo "Don't worry if the previous step failed."
197+
echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."
198+
199+
200+
name: PR Review Requested
201+
202+
203+
on:
204+
pull_request_target:
205+
types:
206+
- review_requested
207+
208+
209+
permissions:
210+
pull-requests: write
211+
",
212+
},
213+
},
214+
},
215+
}
216+
`);
217+
});
218+
8219
test("without addons or mode", () => {
9220
const creation = testBlock(blockGitHubActionsCI, {
10221
options: optionsBase,
@@ -34,7 +245,7 @@ describe("blockGitHubActionsCI", () => {
34245
- uses: actions/setup-node@v4
35246
with:
36247
cache: pnpm
37-
node-version: '20'
248+
node-version: 20.12.0
38249
- run: pnpm install --frozen-lockfile
39250
shell: bash
40251
using: composite
@@ -144,7 +355,7 @@ describe("blockGitHubActionsCI", () => {
144355
- uses: actions/setup-node@v4
145356
with:
146357
cache: pnpm
147-
node-version: '20'
358+
node-version: 20.12.0
148359
- run: pnpm install --frozen-lockfile
149360
shell: bash
150361
using: composite
@@ -261,7 +472,7 @@ describe("blockGitHubActionsCI", () => {
261472
- uses: actions/setup-node@v4
262473
with:
263474
cache: pnpm
264-
node-version: '20'
475+
node-version: 20.12.0
265476
- run: pnpm install --frozen-lockfile
266477
shell: bash
267478
using: composite

‎src/blocks/blockGitHubActionsCI.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ export const blockGitHubActionsCI = base.createBlock({
6464
"v4",
6565
options.workflowsVersions,
6666
),
67-
with: { cache: "pnpm", "node-version": "20" },
67+
with: {
68+
cache: "pnpm",
69+
"node-version":
70+
options.node.pinned ?? options.node.minimum,
71+
},
6872
},
6973
{
7074
run: "pnpm install --frozen-lockfile",

‎src/blocks/blockNvmrc.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("blockNvmrc", () => {
1818
});
1919
});
2020

21-
it("also includes files when options.node exists", () => {
21+
it("also includes files when options.node.pinned exists", () => {
2222
const creation = testBlock(blockNvmrc, {
2323
options: {
2424
...optionsBase,

‎src/blocks/blockNvmrc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const blockNvmrc = base.createBlock({
1212
overrides: [{ files: ".nvmrc", options: { parser: "yaml" } }],
1313
}),
1414
],
15-
...(options.node?.pinned && {
15+
...(options.node.pinned && {
1616
files: {
1717
".nvmrc": `${options.node.pinned}\n`,
1818
},

‎src/blocks/blockPackageJson.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("blockPackageJson", () => {
1717
expect(creation).toMatchInlineSnapshot(`
1818
{
1919
"files": {
20-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"]}",
20+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
2121
},
2222
"scripts": [
2323
{
@@ -50,7 +50,7 @@ describe("blockPackageJson", () => {
5050
},
5151
],
5252
"files": {
53-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"]}",
53+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
5454
},
5555
"scripts": [
5656
{
@@ -81,7 +81,7 @@ describe("blockPackageJson", () => {
8181
expect(creation).toMatchInlineSnapshot(`
8282
{
8383
"files": {
84-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"other":true}",
84+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"engines":{"node":">=20.12.0"},"other":true}",
8585
},
8686
"scripts": [
8787
{
@@ -116,7 +116,7 @@ describe("blockPackageJson", () => {
116116
expect(creation).toMatchInlineSnapshot(`
117117
{
118118
"files": {
119-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"devDependencies":{"is-even":"4.5.6"},"other":true}",
119+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"devDependencies":{"is-even":"4.5.6"},"engines":{"node":">=20.12.0"},"other":true}",
120120
},
121121
"scripts": [
122122
{
@@ -142,7 +142,7 @@ describe("blockPackageJson", () => {
142142
expect(creation).toMatchInlineSnapshot(`
143143
{
144144
"files": {
145-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","keywords":["abc","def","ghi"],"repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"]}",
145+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","keywords":["abc","def","ghi"],"repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
146146
},
147147
"scripts": [
148148
{
@@ -195,7 +195,7 @@ describe("blockPackageJson", () => {
195195
expect(creation).toMatchInlineSnapshot(`
196196
{
197197
"files": {
198-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"]}",
198+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"],"engines":{"node":">=20.12.0"}}",
199199
},
200200
"scripts": [
201201
{
@@ -223,7 +223,7 @@ describe("blockPackageJson", () => {
223223
expect(creation).toMatchInlineSnapshot(`
224224
{
225225
"files": {
226-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","bin":{"absolute":"bin/absolute.js","relative":"./bin/relative.js"},"files":["README.md","bin/absolute.js","bin/relative.js","package.json"]}",
226+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","bin":{"absolute":"bin/absolute.js","relative":"./bin/relative.js"},"files":["README.md","bin/absolute.js","bin/relative.js","package.json"],"engines":{"node":">=20.12.0"}}",
227227
},
228228
"scripts": [
229229
{
@@ -258,7 +258,7 @@ describe("blockPackageJson", () => {
258258
expect(creation).toMatchInlineSnapshot(`
259259
{
260260
"files": {
261-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"peerDependencies":{"@types/estree":">=1","eslint":">=8"},"peerDependenciesMeta":{"@types/estree":{"optional":true}}}",
261+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"peerDependencies":{"@types/estree":">=1","eslint":">=8"},"peerDependenciesMeta":{"@types/estree":{"optional":true}},"engines":{"node":">=20.12.0"}}",
262262
},
263263
"scripts": [
264264
{
@@ -281,7 +281,7 @@ describe("blockPackageJson", () => {
281281
expect(creation).toMatchInlineSnapshot(`
282282
{
283283
"files": {
284-
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"]}",
284+
"package.json": "{"name":"test-repository","version":"0.0.0","description":"A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵","repository":{"type":"git","url":"git+https://github.com/test-owner/test-repository.git"},"license":"MIT","author":{"email":"npm@email.com"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
285285
},
286286
"scripts": [
287287
{

‎src/blocks/blockPackageJson.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ export const blockPackageJson = base.createBlock({
5353
devDependencies: Object.keys(devDependencies).length
5454
? devDependencies
5555
: undefined,
56-
...(options.node && {
57-
engines: {
58-
node: `>=${options.node.minimum}`,
59-
},
60-
}),
56+
engines: {
57+
node: `>=${options.node.minimum}`,
58+
},
6159
...(options.pnpm && {
6260
packageManager: `pnpm@${options.pnpm}`,
6361
}),

‎src/blocks/options.fakes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const optionsBase = {
1414
npm: "npm@email.com",
1515
},
1616
emoji: "💖",
17+
node: {
18+
minimum: "20.12.0",
19+
},
1720
owner: "test-owner",
1821
preset: "minimal",
1922
repository: "test-repository",

0 commit comments

Comments
 (0)
Please sign in to comment.