A GitHub Action to automatically update you repository to the latest Node.js
versions. Supports updating GitHub workflows, package.json engines
and
arbitrary files.
This example workflow will check for new Node versions every Sunday at 7:30 AM. If a new version is found, versions are updated, the changes will be automatically committed to a new branch and a pull request created.
# .github/workflows/update-node-versions.yml
name: update-node-versions
on:
schedule:
- cron: "30 7 * * 0"
jobs:
update-node-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hongaar/update-node-versions@v2
- uses: peter-evans/create-pull-request@v5
with:
title: "feat: update node.js versions"
body: |
Automated changes by [update-node-versions](https://github.com/hongaar/update-node-versions) GitHub action
BREAKING CHANGE: This updates the supported node.js versions
token: ${{ secrets.GH_PAT }}
Note: If you're using
updaters.workflows
(enabled by default), thepeter-evans/create-pull-request
action needs a Personal Access Token with write access to 'pull requests' and 'workflows' (fine-grained tokens) or 'repo'/'public_repo' and 'workflow' scopes (classic token). The defaultsecrets.GITHUB_TOKEN
does not have the required permissions.
By default, versions will be updated to reflect the 'current' and 'LTS' versions of Node which are not end-of-life.
Optionally, you can configure the action to use another strategy for selecting Node versions.
You can configure which parts of your repository are updated. By default, the GitHub workflows and Engines updaters are enabled. These updaters are available:
-
GitHub workflows
This will scan all your GitHub workflows for anode-version
variable in a matrix strategy and update them accordingly. The name of the variable can be configured.strategy: matrix: node-version: [18, 20, 21]
-
Engines
This will update theengines
field in yourpackage.json
file. It will use the lowest Node version as the minimal supported version.{ "engines": { "node": ">=18" } }
-
Files
This will update arbitrary files in your repository. You can specify a glob pattern of files to update, a regex to match and a replacement template to replace the matches with. Files innode_modules
are ignored. You can use these tags in the template:tag output example $1
,$2
, etc.Match group ${versions}
18, 20, 21
${minVersion}
18
${maxVersion}
21
Note: You can specify a list of glob patterns by specifying each pattern on a new line. If you also provide a list regexes and templates, each glob pattern will use the respective line in the regex and template inputs.
name | default | description |
---|---|---|
versions |
latest |
Node versions to select, should be resolvable by node-version-alias. Specify each version on a new line. |
versions.filter-eol |
true |
Filter out Node versions which are end-of-life. Source used for filtering. |
updaters.workflows |
true |
Update GitHub workflows. |
updaters.workflows.variable |
"node-version" |
Use this name as the matrix strategy variable to update the Node versions in. |
updaters.engines |
true |
Update package.json engines . |
updaters.files |
false |
Update arbitrary files. |
updaters.files.glob |
Glob pattern for files to update. | |
updaters.files.regex |
Matches will be replaced with the template. | |
updaters.files.template |
Replace matches with this template. |
All inputs are optional. Example:
- uses: hongaar/update-node-versions@v1
with:
versions: |
current
lts
lts/-1
lts/-2
versions.filter-eol: true
updaters.workflows: true
updaters.workflows.variable: node
updaters.engines: false
name | description |
---|---|
versions |
The Node versions to update to as stringified JSON array (e.g. "[18, 20, 21]" ) |