Skip to content

fix: use options.node in CI prepare action #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 2, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
with:
cache: pnpm
node-version: "20"
node-version: 22.14.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
1 change: 0 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const base = createBase({
minimum: z.string(),
pinned: z.string().optional(),
})
.optional()
.describe("Node.js engine version(s) to pin and require a minimum of"),
owner: z.string().describe("organization or user owning the repository"),
packageData: z
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/blockCSpell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe("blockCSpell", () => {
"scripts": [
{
"commands": [
"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 "[email protected]" --words "npm" --words "[email protected]" --words "emoji" --words "💖" --words "owner" --words "test-owner" --words "preset" --words "minimal" --words "repository" --words "test-repository" --words "title" --words "Test Title"",
"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 "[email protected]" --words "npm" --words "[email protected]" --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"",
],
"phase": 3,
},
Expand Down
217 changes: 214 additions & 3 deletions src/blocks/blockGitHubActionsCI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,217 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { optionsBase } from "./options.fakes.js";

describe("blockGitHubActionsCI", () => {
test("without options.node.pinned", () => {
const creation = testBlock(blockGitHubActionsCI, {
options: {
...optionsBase,
node: {
minimum: "20.12.0",
},
},
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"requiredStatusChecks": undefined,
},
"block": [Function],
},
],
"files": {
".github": {
"actions": {
"prepare": {
"action.yml": "description: Prepares the repo for a typical CI job

name: Prepare

runs:
steps:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: 20.12.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
",
},
},
"workflows": {
"accessibility-alt-text-bot.yml": "jobs:
accessibility_alt_text_bot:
if: \${{ !endsWith(github.actor, '[bot]') }}
runs-on: ubuntu-latest
steps:
- uses: github/[email protected]


name: Accessibility Alt Text Bot


on:
issue_comment:
types:
- created
- edited
issues:
types:
- edited
- opened
pull_request:
types:
- edited
- opened


permissions:
issues: write
pull-requests: write
",
"ci.yml": undefined,
"pr-review-requested.yml": "jobs:
pr_review_requested:
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-remove-labels@v1
with:
labels: 'status: waiting for author'
- if: failure()
run: |
echo "Don't worry if the previous step failed."
echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."


name: PR Review Requested


on:
pull_request_target:
types:
- review_requested


permissions:
pull-requests: write
",
},
},
},
}
`);
});

test("with options.node.pinned", () => {
const creation = testBlock(blockGitHubActionsCI, {
options: {
...optionsBase,
node: {
minimum: "20.12.0",
pinned: "22.12.0",
},
},
});

expect(creation).toMatchInlineSnapshot(`
{
"addons": [
{
"addons": {
"requiredStatusChecks": undefined,
},
"block": [Function],
},
],
"files": {
".github": {
"actions": {
"prepare": {
"action.yml": "description: Prepares the repo for a typical CI job

name: Prepare

runs:
steps:
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: 22.12.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
",
},
},
"workflows": {
"accessibility-alt-text-bot.yml": "jobs:
accessibility_alt_text_bot:
if: \${{ !endsWith(github.actor, '[bot]') }}
runs-on: ubuntu-latest
steps:
- uses: github/[email protected]


name: Accessibility Alt Text Bot


on:
issue_comment:
types:
- created
- edited
issues:
types:
- edited
- opened
pull_request:
types:
- edited
- opened


permissions:
issues: write
pull-requests: write
",
"ci.yml": undefined,
"pr-review-requested.yml": "jobs:
pr_review_requested:
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-remove-labels@v1
with:
labels: 'status: waiting for author'
- if: failure()
run: |
echo "Don't worry if the previous step failed."
echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."


name: PR Review Requested


on:
pull_request_target:
types:
- review_requested


permissions:
pull-requests: write
",
},
},
},
}
`);
});

test("without addons or mode", () => {
const creation = testBlock(blockGitHubActionsCI, {
options: optionsBase,
Expand Down Expand Up @@ -34,7 +245,7 @@ describe("blockGitHubActionsCI", () => {
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: '20'
node-version: 20.12.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
Expand Down Expand Up @@ -144,7 +355,7 @@ describe("blockGitHubActionsCI", () => {
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: '20'
node-version: 20.12.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
Expand Down Expand Up @@ -261,7 +472,7 @@ describe("blockGitHubActionsCI", () => {
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: '20'
node-version: 20.12.0
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
Expand Down
6 changes: 5 additions & 1 deletion src/blocks/blockGitHubActionsCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export const blockGitHubActionsCI = base.createBlock({
"v4",
options.workflowsVersions,
),
with: { cache: "pnpm", "node-version": "20" },
with: {
cache: "pnpm",
"node-version":
options.node.pinned ?? options.node.minimum,
},
},
{
run: "pnpm install --frozen-lockfile",
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/blockNvmrc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("blockNvmrc", () => {
});
});

it("also includes files when options.node exists", () => {
it("also includes files when options.node.pinned exists", () => {
const creation = testBlock(blockNvmrc, {
options: {
...optionsBase,
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/blockNvmrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const blockNvmrc = base.createBlock({
overrides: [{ files: ".nvmrc", options: { parser: "yaml" } }],
}),
],
...(options.node?.pinned && {
...(options.node.pinned && {
files: {
".nvmrc": `${options.node.pinned}\n`,
},
Expand Down
18 changes: 9 additions & 9 deletions src/blocks/blockPackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("blockPackageJson", () => {
},
],
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"other":true}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"engines":{"node":">=20.12.0"},"other":true}",
},
"scripts": [
{
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"dependencies":{"is-odd":"1.2.3"},"devDependencies":{"is-even":"4.5.6"},"other":true}",
"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":"[email protected]"},"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}",
},
"scripts": [
{
Expand All @@ -142,7 +142,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand Down Expand Up @@ -195,7 +195,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"]}",
"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":"[email protected]"},"type":"module","bin":"bin/index.js","files":["README.md","bin/index.js","package.json"],"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","bin":{"absolute":"bin/absolute.js","relative":"./bin/relative.js"},"files":["README.md","bin/absolute.js","bin/relative.js","package.json"]}",
"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":"[email protected]"},"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"}}",
},
"scripts": [
{
Expand Down Expand Up @@ -258,7 +258,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"peerDependencies":{"@types/estree":">=1","eslint":">=8"},"peerDependenciesMeta":{"@types/estree":{"optional":true}}}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"peerDependencies":{"@types/estree":">=1","eslint":">=8"},"peerDependenciesMeta":{"@types/estree":{"optional":true}},"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand All @@ -281,7 +281,7 @@ describe("blockPackageJson", () => {
expect(creation).toMatchInlineSnapshot(`
{
"files": {
"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":"[email protected]"},"type":"module","files":["README.md","package.json"]}",
"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":"[email protected]"},"type":"module","files":["README.md","package.json"],"engines":{"node":">=20.12.0"}}",
},
"scripts": [
{
Expand Down
8 changes: 3 additions & 5 deletions src/blocks/blockPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ export const blockPackageJson = base.createBlock({
devDependencies: Object.keys(devDependencies).length
? devDependencies
: undefined,
...(options.node && {
engines: {
node: `>=${options.node.minimum}`,
},
}),
engines: {
node: `>=${options.node.minimum}`,
},
...(options.pnpm && {
packageManager: `pnpm@${options.pnpm}`,
}),
Expand Down
Loading