mirror of
https://github.com/actions/setup-node.git
synced 2026-06-17 14:23:47 +08:00
Compare commits
10 Commits
v4.0.0
...
ba94aebe4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba94aebe4c | ||
|
|
0d716b2cd5 | ||
|
|
d86ebcd40b | ||
|
|
b39b52d121 | ||
|
|
7247617371 | ||
|
|
f3ec4ca66f | ||
|
|
ec97f37504 | ||
|
|
5ef044f9d0 | ||
|
|
c45882a6ea | ||
|
|
ee36e8b5c0 |
78
.github/workflows/azure-webapps-node.yml
vendored
Normal file
78
.github/workflows/azure-webapps-node.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# This workflow will build and push a node.js application to an Azure Web App when a commit is pushed to your default branch.
|
||||||
|
#
|
||||||
|
# This workflow assumes you have already created the target Azure App Service web app.
|
||||||
|
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=linux&pivots=development-environment-cli
|
||||||
|
#
|
||||||
|
# To configure this workflow:
|
||||||
|
#
|
||||||
|
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
|
||||||
|
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
|
||||||
|
#
|
||||||
|
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
|
||||||
|
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
|
||||||
|
#
|
||||||
|
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the AZURE_WEBAPP_PACKAGE_PATH and NODE_VERSION environment variables below.
|
||||||
|
#
|
||||||
|
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
|
||||||
|
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
AZURE_WEBAPP_NAME: your-app-name # set this to your application's name
|
||||||
|
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
|
||||||
|
NODE_VERSION: '14.x' # set this to the node version to use
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: npm install, build, and test
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run build --if-present
|
||||||
|
npm run test --if-present
|
||||||
|
|
||||||
|
- name: Upload artifact for deployment job
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
path: .
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'Development'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download artifact from build job
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
|
||||||
|
- name: 'Deploy to Azure WebApp'
|
||||||
|
id: deploy-to-webapp
|
||||||
|
uses: azure/webapps-deploy@v2
|
||||||
|
with:
|
||||||
|
app-name: ${{ env.AZURE_WEBAPP_NAME }}
|
||||||
|
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
|
||||||
|
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
|
||||||
2
.github/workflows/basic-validation.yml
vendored
2
.github/workflows/basic-validation.yml
vendored
@@ -15,3 +15,5 @@ jobs:
|
|||||||
call-basic-validation:
|
call-basic-validation:
|
||||||
name: Basic validation
|
name: Basic validation
|
||||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
||||||
|
with:
|
||||||
|
node-version: '20.x'
|
||||||
|
|||||||
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@@ -15,3 +15,5 @@ jobs:
|
|||||||
call-check-dist:
|
call-check-dist:
|
||||||
name: Check dist/
|
name: Check dist/
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||||
|
with:
|
||||||
|
node-version: '20.x'
|
||||||
|
|||||||
2
.github/workflows/e2e-cache.yml
vendored
2
.github/workflows/e2e-cache.yml
vendored
@@ -93,7 +93,7 @@ jobs:
|
|||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: yarn install --ignore-engines
|
||||||
- name: Verify node and yarn
|
- name: Verify node and yarn
|
||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
20
.github/workflows/versions.yml
vendored
20
.github/workflows/versions.yml
vendored
@@ -162,9 +162,6 @@ jobs:
|
|||||||
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Remove volta from package.json
|
|
||||||
shell: bash
|
|
||||||
run: cat <<< "$(jq 'del(.volta)' ./__tests__/data/package.json)" > ./__tests__/data/package.json
|
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -183,7 +180,22 @@ jobs:
|
|||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
node-version-file: '__tests__/data/package.json'
|
node-version-file: '__tests__/data/package-volta.json'
|
||||||
|
- name: Verify node
|
||||||
|
run: __tests__/verify-node.sh 16
|
||||||
|
|
||||||
|
version-file-volta-extends:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup node from node version file
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version-file: '__tests__/data/package-volta-extends.json'
|
||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 16
|
run: __tests__/verify-node.sh 16
|
||||||
|
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -18,14 +18,14 @@ See [action.yml](action.yml)
|
|||||||
|
|
||||||
<!-- start usage -->
|
<!-- start usage -->
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
# Version Spec of the version to use in SemVer notation.
|
# Version Spec of the version to use in SemVer notation.
|
||||||
# It also emits such aliases as lts, latest, nightly and canary builds
|
# It also emits such aliases as lts, latest, nightly and canary builds
|
||||||
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
|
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
|
||||||
node-version: ''
|
node-version: ''
|
||||||
|
|
||||||
# File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.
|
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
|
||||||
# If node-version and node-version-file are both provided the action will use version from node-version.
|
# If node-version and node-version-file are both provided the action will use version from node-version.
|
||||||
node-version-file: ''
|
node-version-file: ''
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ See [action.yml](action.yml)
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -103,12 +103,12 @@ The `node-version` input supports the Semantic Versioning Specification, for mor
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
- Major versions: `14`, `16`, `18`
|
- Major versions: `16`, `18`, `20`
|
||||||
- More specific versions: `10.15`, `16.15.1` , `18.4.0`
|
- More specific versions: `10.15`, `16.15.1` , `18.4.0`
|
||||||
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
|
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
|
||||||
- Latest release: `*` or `latest`/`current`/`node`
|
- Latest release: `*` or `latest`/`current`/`node`
|
||||||
|
|
||||||
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
|
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
|
||||||
|
|
||||||
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
|
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
|
||||||
That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not.
|
That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not.
|
||||||
@@ -133,7 +133,7 @@ See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` in
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -146,7 +146,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -168,7 +168,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -182,7 +182,7 @@ jobs:
|
|||||||
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
node-version: 16
|
node-version: 16
|
||||||
|
|||||||
5
__tests__/data/package-volta-extends.json
Normal file
5
__tests__/data/package-volta-extends.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"volta": {
|
||||||
|
"extends": "./package-volta.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
8
__tests__/data/package-volta.json
Normal file
8
__tests__/data/package-volta.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"engines": {
|
||||||
|
"node": "^14.0.0"
|
||||||
|
},
|
||||||
|
"volta": {
|
||||||
|
"node": "16.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
{
|
{
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^14.0.0"
|
"node": "^14.0.0"
|
||||||
},
|
|
||||||
"volta": {
|
|
||||||
"node": "16.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,9 @@ describe('main tests', () => {
|
|||||||
let startGroupSpy: jest.SpyInstance;
|
let startGroupSpy: jest.SpyInstance;
|
||||||
let endGroupSpy: jest.SpyInstance;
|
let endGroupSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let existsSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
let getExecOutputSpy: jest.SpyInstance;
|
let getExecOutputSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let parseNodeVersionSpy: jest.SpyInstance;
|
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
||||||
let cnSpy: jest.SpyInstance;
|
let cnSpy: jest.SpyInstance;
|
||||||
let findSpy: jest.SpyInstance;
|
let findSpy: jest.SpyInstance;
|
||||||
let isCacheActionAvailable: jest.SpyInstance;
|
let isCacheActionAvailable: jest.SpyInstance;
|
||||||
@@ -41,6 +39,7 @@ describe('main tests', () => {
|
|||||||
// node
|
// node
|
||||||
os = {};
|
os = {};
|
||||||
console.log('::stop-commands::stoptoken');
|
console.log('::stop-commands::stoptoken');
|
||||||
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||||
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
||||||
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
||||||
infoSpy = jest.spyOn(core, 'info');
|
infoSpy = jest.spyOn(core, 'info');
|
||||||
@@ -62,12 +61,10 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
||||||
|
|
||||||
existsSpy = jest.spyOn(fs, 'existsSync');
|
|
||||||
|
|
||||||
cnSpy = jest.spyOn(process.stdout, 'write');
|
cnSpy = jest.spyOn(process.stdout, 'write');
|
||||||
cnSpy.mockImplementation(line => {
|
cnSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
// process.stderr.write('write:' + line + '\n');
|
process.stderr.write('write:' + line + '\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs');
|
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs');
|
||||||
@@ -85,7 +82,7 @@ describe('main tests', () => {
|
|||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
describe('parseNodeVersionFile', () => {
|
describe('getNodeVersionFromFile', () => {
|
||||||
each`
|
each`
|
||||||
contents | expected
|
contents | expected
|
||||||
${'12'} | ${'12'}
|
${'12'} | ${'12'}
|
||||||
@@ -100,9 +97,27 @@ describe('main tests', () => {
|
|||||||
${'unknown format'} | ${'unknown format'}
|
${'unknown format'} | ${'unknown format'}
|
||||||
${' 14.1.0 '} | ${'14.1.0'}
|
${' 14.1.0 '} | ${'14.1.0'}
|
||||||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
||||||
|
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
|
||||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
||||||
|
${'{}'} | ${null}
|
||||||
`.it('parses "$contents"', ({contents, expected}) => {
|
`.it('parses "$contents"', ({contents, expected}) => {
|
||||||
expect(util.parseNodeVersionFile(contents)).toBe(expected);
|
const existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
|
existsSpy.mockImplementation(() => true);
|
||||||
|
|
||||||
|
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
|
readFileSpy.mockImplementation(filePath => {
|
||||||
|
if (
|
||||||
|
typeof filePath === 'string' &&
|
||||||
|
path.basename(filePath) === 'package.json'
|
||||||
|
) {
|
||||||
|
// Special case for volta.extends
|
||||||
|
return '{"volta": {"node": "18.0.0"}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
return contents;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(util.getNodeVersionFromFile('file')).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -141,10 +156,17 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
describe('node-version-file flag', () => {
|
describe('node-version-file flag', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
parseNodeVersionSpy = jest.spyOn(util, 'parseNodeVersionFile');
|
delete inputs['node-version'];
|
||||||
|
inputs['node-version-file'] = '.nvmrc';
|
||||||
|
|
||||||
|
getNodeVersionFromFileSpy = jest.spyOn(util, 'getNodeVersionFromFile');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('not used if node-version is provided', async () => {
|
afterEach(() => {
|
||||||
|
getNodeVersionFromFileSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not read node-version-file if node-version is provided', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
inputs['node-version'] = '12';
|
inputs['node-version'] = '12';
|
||||||
|
|
||||||
@@ -152,107 +174,54 @@ describe('main tests', () => {
|
|||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
|
expect(inputs['node-version']).toBeDefined();
|
||||||
}, 10000);
|
expect(inputs['node-version-file']).toBeDefined();
|
||||||
|
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled();
|
||||||
it('not used if node-version-file not provided', async () => {
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reads node-version-file if provided', async () => {
|
|
||||||
// Arrange
|
|
||||||
const versionSpec = 'v14';
|
|
||||||
const versionFile = '.nvmrc';
|
|
||||||
const expectedVersionSpec = '14';
|
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
|
||||||
inputs['node-version-file'] = versionFile;
|
|
||||||
|
|
||||||
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
|
|
||||||
existsSpy.mockImplementationOnce(
|
|
||||||
input => input === path.join(__dirname, 'data', versionFile)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(existsSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(existsSpy).toHaveReturnedWith(true);
|
|
||||||
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
|
||||||
`Resolved ${versionFile} as ${expectedVersionSpec}`
|
|
||||||
);
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
it('reads package.json as node-version-file if provided', async () => {
|
|
||||||
// Arrange
|
|
||||||
const versionSpec = fs.readFileSync(
|
|
||||||
path.join(__dirname, 'data/package.json'),
|
|
||||||
'utf-8'
|
|
||||||
);
|
|
||||||
const versionFile = 'package.json';
|
|
||||||
const expectedVersionSpec = '14';
|
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
|
||||||
inputs['node-version-file'] = versionFile;
|
|
||||||
|
|
||||||
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
|
|
||||||
existsSpy.mockImplementationOnce(
|
|
||||||
input => input === path.join(__dirname, 'data', versionFile)
|
|
||||||
);
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(existsSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(existsSpy).toHaveReturnedWith(true);
|
|
||||||
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
|
||||||
`Resolved ${versionFile} as ${expectedVersionSpec}`
|
|
||||||
);
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
it('both node-version-file and node-version are provided', async () => {
|
|
||||||
inputs['node-version'] = '12';
|
|
||||||
const versionSpec = 'v14';
|
|
||||||
const versionFile = '.nvmrc';
|
|
||||||
const expectedVersionSpec = '14';
|
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..');
|
|
||||||
inputs['node-version-file'] = versionFile;
|
|
||||||
|
|
||||||
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(existsSpy).toHaveBeenCalledTimes(0);
|
|
||||||
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
'Both node-version and node-version-file inputs are specified, only node-version will be used'
|
'Both node-version and node-version-file inputs are specified, only node-version will be used'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if node-version-file is not found', async () => {
|
it('does not read node-version-file if node-version-file is not provided', async () => {
|
||||||
const versionFile = '.nvmrc';
|
// Arrange
|
||||||
const versionFilePath = path.join(__dirname, '..', versionFile);
|
delete inputs['node-version-file'];
|
||||||
inputs['node-version-file'] = versionFile;
|
|
||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
// Act
|
||||||
existsSpy.mockImplementationOnce(
|
await main.run();
|
||||||
input => input === path.join(__dirname, 'data', versionFile)
|
|
||||||
|
// Assert
|
||||||
|
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reads node-version-file', async () => {
|
||||||
|
// Arrange
|
||||||
|
const expectedVersionSpec = '14';
|
||||||
|
getNodeVersionFromFileSpy.mockImplementation(() => expectedVersionSpec);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(getNodeVersionFromFileSpy).toHaveBeenCalled();
|
||||||
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
|
`Resolved ${inputs['node-version-file']} as ${expectedVersionSpec}`
|
||||||
|
);
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
|
it('should throw an error if node-version-file is not accessible', async () => {
|
||||||
|
// Arrange
|
||||||
|
inputs['node-version-file'] = 'non-existing-file';
|
||||||
|
const versionFilePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'data',
|
||||||
|
inputs['node-version-file']
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(existsSpy).toHaveBeenCalled();
|
expect(getNodeVersionFromFileSpy).toHaveBeenCalled();
|
||||||
expect(existsSpy).toHaveReturnedWith(false);
|
|
||||||
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
|
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ inputs:
|
|||||||
node-version:
|
node-version:
|
||||||
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
|
||||||
node-version-file:
|
node-version-file:
|
||||||
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
|
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.'
|
||||||
architecture:
|
architecture:
|
||||||
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
check-latest:
|
check-latest:
|
||||||
|
|||||||
78
dist/cache-save/index.js
vendored
78
dist/cache-save/index.js
vendored
@@ -82953,11 +82953,20 @@ process.on('uncaughtException', e => {
|
|||||||
const warningPrefix = '[warning]';
|
const warningPrefix = '[warning]';
|
||||||
core.info(`${warningPrefix}${e.message}`);
|
core.info(`${warningPrefix}${e.message}`);
|
||||||
});
|
});
|
||||||
function run() {
|
// Added early exit to resolve issue with slow post action step:
|
||||||
|
function run(earlyExit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const cacheLock = core.getState(constants_1.State.CachePackageManager);
|
const cacheLock = core.getState(constants_1.State.CachePackageManager);
|
||||||
yield cachePackages(cacheLock);
|
if (cacheLock) {
|
||||||
|
yield cachePackages(cacheLock);
|
||||||
|
if (earlyExit) {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug(`Caching for '${cacheLock}' is not supported`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
@@ -82990,7 +82999,7 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func
|
|||||||
}
|
}
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
});
|
});
|
||||||
run();
|
run(true);
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -83320,33 +83329,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
function parseNodeVersionFile(contents) {
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
var _a, _b, _c;
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
let nodeVersion;
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
|
var _a, _b, _c, _d, _e;
|
||||||
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
||||||
|
}
|
||||||
|
const contents = fs_1.default.readFileSync(versionFilePath, 'utf8');
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
const manifest = JSON.parse(contents);
|
||||||
if (!nodeVersion)
|
// Presume package.json file.
|
||||||
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
if (typeof manifest === 'object' && !!manifest) {
|
||||||
|
// Support Volta.
|
||||||
|
// See https://docs.volta.sh/guide/understanding#managing-your-project
|
||||||
|
if ((_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node) {
|
||||||
|
return manifest.volta.node;
|
||||||
|
}
|
||||||
|
if ((_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node) {
|
||||||
|
return manifest.engines.node;
|
||||||
|
}
|
||||||
|
// Support Volta workspaces.
|
||||||
|
// See https://docs.volta.sh/advanced/workspaces
|
||||||
|
if ((_c = manifest.volta) === null || _c === void 0 ? void 0 : _c.extends) {
|
||||||
|
const extendedFilePath = path_1.default.resolve(path_1.default.dirname(versionFilePath), manifest.volta.extends);
|
||||||
|
core.info('Resolving node version from ' + extendedFilePath);
|
||||||
|
return getNodeVersionFromFile(extendedFilePath);
|
||||||
|
}
|
||||||
|
// If contents are an object, we parsed JSON
|
||||||
|
// this can happen if node-version-file is a package.json
|
||||||
|
// yet contains no volta.node or engines.node
|
||||||
|
//
|
||||||
|
// If node-version file is _not_ JSON, control flow
|
||||||
|
// will not have reached these lines.
|
||||||
|
//
|
||||||
|
// And because we've reached here, we know the contents
|
||||||
|
// *are* JSON, so no further string parsing makes sense.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (_d) {
|
catch (_f) {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
if (!nodeVersion) {
|
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
return (_e = (_d = found === null || found === void 0 ? void 0 : found.groups) === null || _d === void 0 ? void 0 : _d.version) !== null && _e !== void 0 ? _e : contents.trim();
|
||||||
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
|
||||||
}
|
|
||||||
// In the case of an unknown format,
|
|
||||||
// return as is and evaluate the version separately.
|
|
||||||
if (!nodeVersion)
|
|
||||||
nodeVersion = contents.trim();
|
|
||||||
return nodeVersion;
|
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
exports.getNodeVersionFromFile = getNodeVersionFromFile;
|
||||||
function printEnvDetailsAndSetOutput() {
|
function printEnvDetailsAndSetOutput() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
|
|||||||
73
dist/setup/index.js
vendored
73
dist/setup/index.js
vendored
@@ -93650,7 +93650,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.run = void 0;
|
exports.run = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const auth = __importStar(__nccwpck_require__(7573));
|
const auth = __importStar(__nccwpck_require__(7573));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
@@ -93725,10 +93724,13 @@ function resolveVersionInput() {
|
|||||||
}
|
}
|
||||||
if (versionFileInput) {
|
if (versionFileInput) {
|
||||||
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
|
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
|
||||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
const parsedVersion = (0, util_1.getNodeVersionFromFile)(versionFilePath);
|
||||||
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
if (parsedVersion) {
|
||||||
|
version = parsedVersion;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.warning(`Could not determine node version from ${versionFilePath}. Falling back`);
|
||||||
}
|
}
|
||||||
version = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
@@ -93774,33 +93776,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
function parseNodeVersionFile(contents) {
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
var _a, _b, _c;
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
let nodeVersion;
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
|
var _a, _b, _c, _d, _e;
|
||||||
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
||||||
|
}
|
||||||
|
const contents = fs_1.default.readFileSync(versionFilePath, 'utf8');
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
const manifest = JSON.parse(contents);
|
||||||
if (!nodeVersion)
|
// Presume package.json file.
|
||||||
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
if (typeof manifest === 'object' && !!manifest) {
|
||||||
|
// Support Volta.
|
||||||
|
// See https://docs.volta.sh/guide/understanding#managing-your-project
|
||||||
|
if ((_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node) {
|
||||||
|
return manifest.volta.node;
|
||||||
|
}
|
||||||
|
if ((_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node) {
|
||||||
|
return manifest.engines.node;
|
||||||
|
}
|
||||||
|
// Support Volta workspaces.
|
||||||
|
// See https://docs.volta.sh/advanced/workspaces
|
||||||
|
if ((_c = manifest.volta) === null || _c === void 0 ? void 0 : _c.extends) {
|
||||||
|
const extendedFilePath = path_1.default.resolve(path_1.default.dirname(versionFilePath), manifest.volta.extends);
|
||||||
|
core.info('Resolving node version from ' + extendedFilePath);
|
||||||
|
return getNodeVersionFromFile(extendedFilePath);
|
||||||
|
}
|
||||||
|
// If contents are an object, we parsed JSON
|
||||||
|
// this can happen if node-version-file is a package.json
|
||||||
|
// yet contains no volta.node or engines.node
|
||||||
|
//
|
||||||
|
// If node-version file is _not_ JSON, control flow
|
||||||
|
// will not have reached these lines.
|
||||||
|
//
|
||||||
|
// And because we've reached here, we know the contents
|
||||||
|
// *are* JSON, so no further string parsing makes sense.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (_d) {
|
catch (_f) {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
if (!nodeVersion) {
|
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
return (_e = (_d = found === null || found === void 0 ? void 0 : found.groups) === null || _d === void 0 ? void 0 : _d.version) !== null && _e !== void 0 ? _e : contents.trim();
|
||||||
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
|
||||||
}
|
|
||||||
// In the case of an unknown format,
|
|
||||||
// return as is and evaluate the version separately.
|
|
||||||
if (!nodeVersion)
|
|
||||||
nodeVersion = contents.trim();
|
|
||||||
return nodeVersion;
|
|
||||||
}
|
}
|
||||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
exports.getNodeVersionFromFile = getNodeVersionFromFile;
|
||||||
function printEnvDetailsAndSetOutput() {
|
function printEnvDetailsAndSetOutput() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
check-latest: true
|
check-latest: true
|
||||||
@@ -64,7 +64,7 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -84,6 +84,8 @@ When using the `package.json` input, the action will look for `volta.node` first
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Otherwise, when [`volta.extends`](https://docs.volta.sh/advanced/workspaces) is defined, then it will resolve the corresponding file and look for `volta.node` or `engines.node` recursively.
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
|
||||||
@@ -96,7 +98,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
|
||||||
@@ -117,7 +119,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20.0.0-v8-canary' # it will install the latest v8 canary release for node 20.0.0
|
node-version: '20.0.0-v8-canary' # it will install the latest v8 canary release for node 20.0.0
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -132,7 +134,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20-v8-canary' # it will install the latest v8 canary release for node 20
|
node-version: '20-v8-canary' # it will install the latest v8 canary release for node 20
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -148,7 +150,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 'v20.1.1-v8-canary20221103f7e2421e91'
|
node-version: 'v20.1.1-v8-canary20221103f7e2421e91'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -168,7 +170,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16-nightly' # it will install the latest nightly release for node 16
|
node-version: '16-nightly' # it will install the latest nightly release for node 16
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -184,7 +186,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16.0.0-nightly' # it will install the latest nightly release for node 16.0.0
|
node-version: '16.0.0-nightly' # it will install the latest nightly release for node 16.0.0
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -200,7 +202,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16.0.0-nightly20210420a0261d231c'
|
node-version: '16.0.0-nightly20210420a0261d231c'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -218,7 +220,7 @@ jobs:
|
|||||||
name: Node sample
|
name: Node sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16.0.0-rc.1'
|
node-version: '16.0.0-rc.1'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -235,7 +237,7 @@ Yarn caching handles both yarn versions: 1 or 2.
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
@@ -257,7 +259,7 @@ steps:
|
|||||||
- uses: pnpm/action-setup@v2
|
- uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 6.32.9
|
version: 6.32.9
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'pnpm'
|
cache: 'pnpm'
|
||||||
@@ -273,7 +275,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -286,7 +288,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14'
|
node-version: '14'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -324,7 +326,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node
|
- name: Setup node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node_version }}
|
node-version: ${{ matrix.node_version }}
|
||||||
architecture: ${{ matrix.architecture }}
|
architecture: ${{ matrix.architecture }}
|
||||||
@@ -336,7 +338,7 @@ jobs:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
@@ -344,7 +346,7 @@ steps:
|
|||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: npm publish
|
- run: npm publish
|
||||||
@@ -356,7 +358,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: <registry url>
|
registry-url: <registry url>
|
||||||
@@ -364,7 +366,7 @@ steps:
|
|||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
registry-url: 'https://npm.pkg.github.com'
|
registry-url: 'https://npm.pkg.github.com'
|
||||||
- run: yarn publish
|
- run: yarn publish
|
||||||
@@ -376,7 +378,7 @@ steps:
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
@@ -396,7 +398,7 @@ Below you can find a sample "Setup .yarnrc.yml" step, that is going to allow you
|
|||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '14.x'
|
node-version: '14.x'
|
||||||
- name: Setup .yarnrc.yml
|
- name: Setup .yarnrc.yml
|
||||||
|
|||||||
@@ -12,10 +12,20 @@ process.on('uncaughtException', e => {
|
|||||||
core.info(`${warningPrefix}${e.message}`);
|
core.info(`${warningPrefix}${e.message}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function run() {
|
// Added early exit to resolve issue with slow post action step:
|
||||||
|
export async function run(earlyExit?: boolean) {
|
||||||
try {
|
try {
|
||||||
const cacheLock = core.getState(State.CachePackageManager);
|
const cacheLock = core.getState(State.CachePackageManager);
|
||||||
await cachePackages(cacheLock);
|
|
||||||
|
if (cacheLock) {
|
||||||
|
await cachePackages(cacheLock);
|
||||||
|
|
||||||
|
if (earlyExit) {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.debug(`Caching for '${cacheLock}' is not supported`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed((error as Error).message);
|
||||||
}
|
}
|
||||||
@@ -58,4 +68,4 @@ const cachePackages = async (packageManager: string) => {
|
|||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
run();
|
run(true);
|
||||||
|
|||||||
15
src/main.ts
15
src/main.ts
@@ -1,6 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
@@ -8,7 +7,7 @@ import * as path from 'path';
|
|||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isCacheFeatureAvailable} from './cache-utils';
|
import {isCacheFeatureAvailable} from './cache-utils';
|
||||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||||
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
|
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@@ -99,14 +98,16 @@ function resolveVersionInput(): string {
|
|||||||
versionFileInput
|
versionFileInput
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
const parsedVersion = getNodeVersionFromFile(versionFilePath);
|
||||||
throw new Error(
|
|
||||||
`The specified node version file at: ${versionFilePath} does not exist`
|
if (parsedVersion) {
|
||||||
|
version = parsedVersion;
|
||||||
|
} else {
|
||||||
|
core.warning(
|
||||||
|
`Could not determine node version from ${versionFilePath}. Falling back`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
|
|
||||||
|
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
63
src/util.ts
63
src/util.ts
@@ -1,27 +1,62 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export function parseNodeVersionFile(contents: string): string {
|
import fs from 'fs';
|
||||||
let nodeVersion: string | undefined;
|
import path from 'path';
|
||||||
|
|
||||||
|
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||||
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(
|
||||||
|
`The specified node version file at: ${versionFilePath} does not exist`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const contents = fs.readFileSync(versionFilePath, 'utf8');
|
||||||
|
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
nodeVersion = JSON.parse(contents).volta?.node;
|
const manifest = JSON.parse(contents);
|
||||||
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
|
|
||||||
|
// Presume package.json file.
|
||||||
|
if (typeof manifest === 'object' && !!manifest) {
|
||||||
|
// Support Volta.
|
||||||
|
// See https://docs.volta.sh/guide/understanding#managing-your-project
|
||||||
|
if (manifest.volta?.node) {
|
||||||
|
return manifest.volta.node;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (manifest.engines?.node) {
|
||||||
|
return manifest.engines.node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Support Volta workspaces.
|
||||||
|
// See https://docs.volta.sh/advanced/workspaces
|
||||||
|
if (manifest.volta?.extends) {
|
||||||
|
const extendedFilePath = path.resolve(
|
||||||
|
path.dirname(versionFilePath),
|
||||||
|
manifest.volta.extends
|
||||||
|
);
|
||||||
|
core.info('Resolving node version from ' + extendedFilePath);
|
||||||
|
return getNodeVersionFromFile(extendedFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If contents are an object, we parsed JSON
|
||||||
|
// this can happen if node-version-file is a package.json
|
||||||
|
// yet contains no volta.node or engines.node
|
||||||
|
//
|
||||||
|
// If node-version file is _not_ JSON, control flow
|
||||||
|
// will not have reached these lines.
|
||||||
|
//
|
||||||
|
// And because we've reached here, we know the contents
|
||||||
|
// *are* JSON, so no further string parsing makes sense.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeVersion) {
|
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
return found?.groups?.version ?? contents.trim();
|
||||||
nodeVersion = found?.groups?.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In the case of an unknown format,
|
|
||||||
// return as is and evaluate the version separately.
|
|
||||||
if (!nodeVersion) nodeVersion = contents.trim();
|
|
||||||
|
|
||||||
return nodeVersion as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function printEnvDetailsAndSetOutput() {
|
export async function printEnvDetailsAndSetOutput() {
|
||||||
|
|||||||
Reference in New Issue
Block a user