Skip to content

Commit c92f633

Browse files
authored
fix: rename version to node-version, as using --version will log out versions of Node, Octokit, and the script (#4)
BREAKING CHANGE: `version` is now `node-version` as is now a required argument
1 parent 5f4efd1 commit c92f633

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-node@v2
1414
with:
15-
node-version: 16
15+
node-version: lts/*
1616
- uses: actions/cache@v2
1717
with:
1818
path: ~/.npm

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node_version: ["12", "14"]
14+
node_version: ["14", "16", "18"]
1515

1616
steps:
1717
- uses: actions/checkout@v2

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pass all options as CLI flags to avoid user prompts
2121
npx octoherd-script-bump-node-version-in-workflows \
2222
-T ghp_0123456789abcdefghjklmnopqrstuvwxyzA \
2323
-R "gr2m/*" \
24-
--version 16 \
24+
--node-version 16 \
2525
--workflow release.yml
2626
```
2727

@@ -35,7 +35,7 @@ I run the script against all [@octokit repositories](https://github.com/orgs/oct
3535

3636
| option | type | description |
3737
| ---------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38-
| `--version` | number | Defaults to latest Node LTS major version (v16). You can set it to [`lts/*`](https://github.com/actions/setup-node#supported-version-syntax) to always get the latest LTS version if you prefer |
38+
| `--node-version` | number | **Required** May be set to `lts/*`. See [all supported versions](https://github.com/actions/setup-node#supported-version-syntax) |
3939
| `--workflow` | string | workflow file name or pattern to only update a subset of workflows. [matcher](https://github.com/sindresorhus/matcher#usage) is used for matching. Defaults to `*` |
4040
| `--octoherd-token`, `-T` | string | A personal access token ([create](https://github.com/settings/tokens/new?scopes=repo)). Script will create one if option is not set |
4141
| `--octoherd-repos`, `-R` | array of strings | One or multiple space-separated repositories in the form of `repo-owner/repo-name`. `repo-owner/*` will find all repositories for one owner. `*` will find all repositories the user has access to. Will prompt for repositories if not set |

script.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import yaml from "js-yaml";
1010
* @param {import('@octoherd/cli').Octokit} octokit
1111
* @param {import('@octoherd/cli').Repository} repository
1212
* @param {object} options
13-
* @param {number} [options.version] Defaults to latest Node LTS major version
13+
* @param {number | string} [options.nodeVersion] Defaults to latest Node LTS major version
1414
* @param {string} [options.workflow] workflow file name or pattern to only update a subset of workflows
1515
*/
1616
export async function script(
1717
octokit,
1818
repository,
19-
{ version = 16, workflow = "*" }
19+
{ nodeVersion = "", workflow = "*" }
2020
) {
21+
if (!nodeVersion) {
22+
throw new Error(`--node-version is required`);
23+
}
2124
if (repository.archived) {
2225
octokit.log.info(`Repository is archived, ignoring`);
2326
return;
@@ -82,7 +85,7 @@ export async function script(
8285
return content;
8386
}
8487

85-
if (!config.jobs) {
88+
if (!config?.jobs) {
8689
octokit.log.warn(`No jobs in ${name}`);
8790
return content;
8891
}
@@ -105,10 +108,10 @@ export async function script(
105108
}
106109
}
107110

108-
if (Number(step.with["node-version"]) === version) continue;
111+
if (Number(step.with["node-version"]) === nodeVersion) continue;
109112
if (String(step.with["node-version"]).includes("${{")) continue;
110113

111-
step.with["node-version"] = version;
114+
step.with["node-version"] = nodeVersion;
112115
nodeVersionChanged = true;
113116
}
114117
}
@@ -120,7 +123,7 @@ export async function script(
120123
quotingType: '"',
121124
});
122125
},
123-
message: `build(${name}): set node-version to ${version}`,
126+
message: `build(${name}): set node-version to ${nodeVersion}`,
124127
});
125128

126129
if (updated) {

0 commit comments

Comments
 (0)