Skip to content

Commit e78948d

Browse files
TplemeEndBug
andauthored
fix: updated node version to 20 (#269)
* updated node version from 16 to 20 * chore: update deps to Node v20 * chore: set engines * ci: build with node v20 * docs: update versions in docs --------- Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
1 parent 6b0b376 commit e78948d

7 files changed

Lines changed: 117 additions & 103 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
branches:
55
- main
66
paths:
7-
- "src/**"
8-
- "package.json"
9-
- ".github/workflows/build.yml"
7+
- 'src/**'
8+
- 'package.json'
9+
- '.github/workflows/build.yml'
1010

1111
jobs:
1212
build:
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: 16.x
22+
node-version: 20.x
2323
cache: npm
2424

2525
- name: Install dependencies
@@ -32,5 +32,5 @@ jobs:
3232
uses: EndBug/add-and-commit@v9
3333
with:
3434
add: lib
35-
message: "[auto] build: update compiled version"
35+
message: '[auto] build: update compiled version'
3636
push: --force

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ outputs:
4040
description: The SHA of the commit where the version change has been detected
4141

4242
runs:
43-
using: node16
43+
using: node20
4444
main: 'lib/index.js'
4545

4646
branding:

doc/auto-publish-example.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ jobs:
77
publish:
88
name: Publish to NPM & GitHub Package Registry
99
runs-on: ubuntu-latest
10-
if: contains(github.ref, 'master') # Publish it only if the push comes from the master branch
10+
if: contains(github.ref, 'main') # Publish it only if the push comes from the main branch
1111
needs: build # We need to wait for the build to be committed before publishing
1212

1313
steps:
1414
- name: Checkout repository
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616
with:
17-
ref: master
17+
ref: main
1818

1919
- name: Check version changes
20-
uses: EndBug/version-check@v1
20+
uses: EndBug/version-check@v2
2121
id: check
2222

2323
- name: Version update detected
@@ -26,9 +26,9 @@ jobs:
2626

2727
- name: Set up Node.js for NPM
2828
if: steps.check.outputs.changed == 'true'
29-
uses: actions/setup-node@v1
29+
uses: actions/setup-node@v4
3030
with:
31-
registry-url: "https://registry.npmjs.org"
31+
registry-url: 'https://registry.npmjs.org'
3232

3333
- name: Install dependencies
3434
if: steps.check.outputs.changed == 'true'
@@ -42,10 +42,10 @@ jobs:
4242

4343
- name: Set up Node.js for GPR
4444
if: steps.check.outputs.changed == 'true'
45-
uses: actions/setup-node@v1
45+
uses: actions/setup-node@v4
4646
with:
47-
registry-url: "https://npm.pkg.github.com/"
48-
scope: "@endbug"
47+
registry-url: 'https://npm.pkg.github.com/'
48+
scope: '@endbug'
4949

5050
- name: Set up package for GPR # You need to make sure you package name has the scope needed for GPR
5151
if: steps.check.outputs.changed == 'true'

doc/auto-publish-walkthrough.md

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
*Note: the result of all these steps can be found [here][1], in the workflow file I actually used for my package.*
1+
_Note: the result of all these steps can be found [here][1], in the workflow file I actually used for my package._
22

33
## 1. Making sure that the "publish" job gets executed on the version that has been just built
44

5-
The easiest way I found was just to put the two jobs in the same workflow, and having them both fire on every `push` event: the publish job was then limited to execute only if on the `master` branch and after the first one.
5+
The easiest way I found was just to put the two jobs in the same workflow, and having them both fire on every `push` event: the publish job was then limited to execute only if on the `main` branch and after the first one.
66

7-
- **Build job:**
7+
- **Build job:**
88

99
It needs to build the new version of the package, then **commit** it to the repository: committing is crucial because that allows the other job to pick the built version. To commit the changes made inside a workflow run, you can use one of my actions, [`add-and-commit`][2]: it will push the changes to the GitHub repository using a "fake" git user.
1010
You workflow job should look something like this:
@@ -15,61 +15,57 @@ jobs:
1515
name: Build
1616
runs-on: ubuntu-latest
1717

18-
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v2
21-
22-
- name: Set up Node.js
23-
uses: actions/setup-node@v1
24-
with:
25-
node-version: '10.x'
26-
27-
- name: Install dependencies
28-
run: npm install --only=prod
29-
30-
- name: Compile build
31-
run: npm run build # This can be whatever command you use to build your package
32-
33-
- name: Commit changes
34-
uses: EndBug/add-and-commit@v2
35-
with: # More info about the arguments on the action page
36-
author_name: Displayed name
37-
author_email: Displayed email
38-
message: "Message for the commit"
39-
path: local/path/to/built/version
40-
pattern: "*.js" # Pattern that matches the files to commit
41-
force: true # Whether to use the --force flag
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This gets generated automatically
44-
```
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '20.x'
26+
27+
- name: Install dependencies
28+
run: npm install --only=prod
4529

30+
- name: Compile build
31+
run: npm run build # This can be whatever command you use to build your package
32+
33+
- name: Commit changes
34+
uses: EndBug/add-and-commit@v9
35+
with: # More info about the arguments on the action page
36+
author_name: Displayed name
37+
author_email: Displayed email
38+
message: 'Message for the commit'
39+
add: local/path/to/built/version/"*.js --force
40+
```
4641
47-
- **Publish job:**
42+
- **Publish job:**
4843
49-
We want it to run only in the `master` branch after `build` is completed, so we can set it like this:
44+
We want it to run only in the `main` branch after `build` is completed, so we can set it like this:
5045

5146
```yml
5247
publish:
5348
name: Publish to NPM & GitHub Package Registry
5449
runs-on: ubuntu-latest
55-
if: contains(github.ref, 'master') # This sets the branch
50+
if: contains(github.ref, 'main') # This sets the branch
5651
needs: build # This makes it wait for the build job
5752
```
5853

59-
## 2. Detecting a version change
54+
## 2. Detecting a version change
55+
6056
I didn't find a good way to do that so I made another action, [`version-check`][3]: this action scans the commits of every push and tries to figure out whether they include a version change. Remeber to set eventual needed arguments/inputs!
6157
You need to set up these two steps:
6258

6359
```yml
6460
steps:
65-
- name: Checkout repository
66-
uses: actions/checkout@v2
67-
with:
68-
ref: master
69-
70-
- name: Check version changes
71-
uses: EndBug/version-check@v1 # More info about the arguments on the action page
72-
id: check # This will be the reference for later
61+
- name: Checkout repository
62+
uses: actions/checkout@v4
63+
with:
64+
ref: main
65+
66+
- name: Check version changes
67+
uses: EndBug/version-check@v2 # More info about the arguments on the action page
68+
id: check # This will be the reference for later
7369
```
7470

7571
You could also use the `static-check` and `file-url` option to detect teh version change, but if more checks run at the same time this can make it try to publish it multiple times.
@@ -114,9 +110,9 @@ In this example, I'll assume your secret is called `NPM_TOKEN`:
114110
As for now, GitHub Package Registry is not very pleasant to work with if you want to keep publishing your existing package to npm: that's why it requires packages to be scoped, and that can mess thing up (your package may not be scoped or be scoped under a different name).
115111
I found that the easiest way to deal with that is doing this workaround:
116112

117-
- In your workflow, re-setup Node.js but adding GPR's registry URL and your name-scope
118-
- Create an npm script that edits your package.json so that it changes the original name of the package to the one you need to publish to GPR (scope included)
119-
- After calling that script in your workflow, use `npm publish` as before, but this time using the built-in `GITHUB_TOKEN` as `NODE_AUTH_TOKEN`.
113+
- In your workflow, re-setup Node.js but adding GPR's registry URL and your name-scope
114+
- Create an npm script that edits your package.json so that it changes the original name of the package to the one you need to publish to GPR (scope included)
115+
- After calling that script in your workflow, use `npm publish` as before, but this time using the built-in `GITHUB_TOKEN` as `NODE_AUTH_TOKEN`.
120116

121117
```json
122118
{
@@ -166,15 +162,14 @@ fs.writeFileSync(join(__dirname, '../package.json'), JSON.stringify(pkg))
166162
Your package is now published both to NPM and GPR (a description needs to be manually added to GPR though).
167163
You can find all of the stuff I'm referring to in the 4.0.3 version of uptime-monitor:
168164

169-
- [Build/publish workflow][1]
170-
- [GPR script][8]
171-
172-
173-
[1]: https://github.com/EndBug/uptime-monitor/blob/v4.0.3/.github/workflows/build-and-publish.yml
174-
[2]: https://github.com/marketplace/actions/add-commit
175-
[3]: https://github.com/marketplace/actions/version-check
176-
[4]: https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#steps-context
177-
[5]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idif
178-
[6]: https://npmjs.com
179-
[7]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
180-
[8]: https://github.com/EndBug/uptime-monitor/blob/v4.0.3/scripts/gpr.js
165+
- [Build/publish workflow][1]
166+
- [GPR script][8]
167+
168+
[1]: https://github.com/EndBug/uptime-monitor/blob/v4.0.3/.github/workflows/build-and-publish.yml
169+
[2]: https://github.com/marketplace/actions/add-commit
170+
[3]: https://github.com/marketplace/actions/version-check
171+
[4]: https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#steps-context
172+
[5]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idif
173+
[6]: https://npmjs.com
174+
[7]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
175+
[8]: https://github.com/EndBug/uptime-monitor/blob/v4.0.3/scripts/gpr.js

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 29 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
"prepare": "husky install",
1212
"test": "echo \"Error: no test specified\" && exit 1"
1313
},
14+
"dependencies": {
15+
"@actions/core": "^1.10.1",
16+
"got": "^11.8.3",
17+
"semver-diff": "^4.0.0"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^20.11.6",
21+
"@typescript-eslint/eslint-plugin": "^6.13.1",
22+
"@typescript-eslint/parser": "^6.16.0",
23+
"@vercel/ncc": "^0.38.1",
24+
"all-contributors-cli": "^6.26.1",
25+
"eslint": "^8.45.0",
26+
"eslint-config-prettier": "^9.1.0",
27+
"eslint-plugin-prettier": "^5.1.3",
28+
"husky": "^8.0.3",
29+
"prettier": "^3.1.1",
30+
"typescript": "^5.3.3"
31+
},
1432
"repository": {
1533
"type": "git",
1634
"url": "git+https://github.com/EndBug/version-check.git"
@@ -28,22 +46,7 @@
2846
"url": "https://github.com/EndBug/version-check/issues"
2947
},
3048
"homepage": "https://github.com/EndBug/version-check#readme",
31-
"dependencies": {
32-
"@actions/core": "^1.10.1",
33-
"got": "^11.8.3",
34-
"semver-diff": "^4.0.0"
35-
},
36-
"devDependencies": {
37-
"@types/node": "^12.20.6",
38-
"@typescript-eslint/eslint-plugin": "^6.13.1",
39-
"@typescript-eslint/parser": "^6.16.0",
40-
"@vercel/ncc": "^0.38.1",
41-
"all-contributors-cli": "^6.26.1",
42-
"eslint": "^8.45.0",
43-
"eslint-config-prettier": "^9.1.0",
44-
"eslint-plugin-prettier": "^5.1.3",
45-
"husky": "^8.0.3",
46-
"prettier": "^3.1.1",
47-
"typescript": "^5.3.3"
49+
"engines": {
50+
"node": ">=20"
4851
}
4952
}

0 commit comments

Comments
 (0)