Support action metadata version files

This commit is contained in:
copilot-swe-agent[bot] 2026-07-27 02:35:56 +00:00 committed by GitHub
parent 32f57ac043
commit 8f018f5241
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 3 deletions

View File

@ -49,7 +49,7 @@ See [action.yml](action.yml)
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: ''
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions, action.yml.
# If node-version and node-version-file are both provided the action will use version from node-version.
node-version-file: ''

View File

@ -197,6 +197,7 @@ describe('main tests', () => {
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'}
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'}
${"name: 'My Action'\nruns:\n using: 'node24'\n main: 'dist/index.js'\n"} | ${'24'}
`.it('parses "$contents"', ({contents, expected}: any) => {
const existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true);

View File

@ -5,7 +5,7 @@ inputs:
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
node-version-file:
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.'
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions, action.yml.'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:

View File

@ -76,7 +76,7 @@ steps:
## Node version file
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version`, `.tool-versions`, or `package.json`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc`, `.node-version`, `.tool-versions`, `package.json`, or an action metadata file such as `action.yml`. For action metadata, the action reads the Node.js version from `runs.using` (for example, `node24`). If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used.
See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax).
> The action will search for the node version file relative to the repository root.

View File

@ -68,6 +68,16 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
core.info('Node version file is not JSON file');
}
const runsSection = contents.match(
/^runs\s*:\s*$(?<contents>[\s\S]*?)(?=^[^\s].*?:|\s*$)/m
)?.groups?.contents;
const actionRuntime = runsSection?.match(
/^\s+using:\s*['"]?node(?<version>\d+)['"]?\s*(?:#.*)?$/m
);
if (actionRuntime?.groups?.version) {
return actionRuntime.groups.version;
}
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
return found?.groups?.version ?? contents.trim();
}