mirror of
				https://kkgithub.com/actions/setup-node.git
				synced 2025-11-04 04:31:55 +08:00 
			
		
		
		
	Compare commits
	
		
			46 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c46424eee2 | |||
| 1d846de8c0 | |||
| d06286dee6 | |||
| d8c1b596a6 | |||
| 2bfa943ffb | |||
| 6c8a6e529a | |||
| 27082cecf3 | |||
| 05e7d6cc23 | |||
| d6fea3c137 | |||
| 4667755142 | |||
| 2bbfc7698a | |||
| 5984462aaa | |||
| aabe026707 | |||
| b7cfa22539 | |||
| 70b9252472 | |||
| 7d147e85af | |||
| 66dfac5328 | |||
| 312bbeecfd | |||
| 26a6dcb73b | |||
| f4215cc0e0 | |||
| 14e150d2b1 | |||
| 5da2d61209 | |||
| a600caf7cc | |||
| 8dde5bc004 | |||
| 2f532cef8f | |||
| 99d584aa06 | |||
| 2a5c060ce2 | |||
| 2801f51f90 | |||
| 0a161fe2f9 | |||
| 63fffe4411 | |||
| a83bf51129 | |||
| 922f2f9468 | |||
| 7a3669aa8a | |||
| 66f3e9f7ce | |||
| 82271389a6 | |||
| 2e40994c28 | |||
| c7e4d38541 | |||
| 3eb4bc9d68 | |||
| bf47decdc2 | |||
| 6afbfca452 | |||
| 3e84c3523b | |||
| 6668516d2a | |||
| f27ebaf08b | |||
| 42d59fbc36 | |||
| 2d8887128d | |||
| 0635b31a61 | 
							
								
								
									
										4
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							@ -1 +1,5 @@
 | 
			
		||||
# Set default behavior to automatically normalize line endings, and force everything to be LF, except for Windows batch files that require CRLF, so that if a repo is accessed in Unix via a file share from Windows, the scripts will work.
 | 
			
		||||
* text=auto eol=lf
 | 
			
		||||
*.{cmd,[cC][mM][dD]} text eol=crlf
 | 
			
		||||
*.{bat,[bB][aA][tT]} text eol=crlf
 | 
			
		||||
.licenses/** -diff linguist-generated=true
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								.github/workflows/build-test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/build-test.yml
									
									
									
									
										vendored
									
									
								
							@ -20,7 +20,7 @@ jobs:
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - name: Setup node 12
 | 
			
		||||
        uses: actions/setup-node@v1
 | 
			
		||||
        uses: actions/setup-node@v2
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: 12.x
 | 
			
		||||
      - run: npm ci
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							@ -97,3 +97,16 @@ jobs:
 | 
			
		||||
      - name: Verify node
 | 
			
		||||
        run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
 | 
			
		||||
        shell: bash
 | 
			
		||||
 | 
			
		||||
  arch:
 | 
			
		||||
    runs-on: windows-latest
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - name: Setup node 12 x86 from dist
 | 
			
		||||
        uses: ./
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: '12'
 | 
			
		||||
          architecture: 'x86'
 | 
			
		||||
      - name: Verify node
 | 
			
		||||
        run: __tests__/verify-arch.sh "ia32"
 | 
			
		||||
        shell: bash
 | 
			
		||||
							
								
								
									
										1
									
								
								CODEOWNERS
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								CODEOWNERS
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
* @actions/spark
 | 
			
		||||
							
								
								
									
										75
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								README.md
									
									
									
									
									
								
							@ -10,14 +10,14 @@ This action sets by node environment for use in actions by:
 | 
			
		||||
- registering problem matchers for error output
 | 
			
		||||
- configuring authentication for GPR or npm
 | 
			
		||||
 | 
			
		||||
# v2-beta
 | 
			
		||||
# v2
 | 
			
		||||
 | 
			
		||||
A beta release which adds reliability for pulling node distributions from a cache of node releases is available by referencing the `v2-beta` tag.
 | 
			
		||||
This release adds reliability for pulling node distributions from a cache of node releases.
 | 
			
		||||
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-node@v2-beta
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    node-version: '12'
 | 
			
		||||
```
 | 
			
		||||
@ -34,7 +34,7 @@ Basic:
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    node-version: '12'
 | 
			
		||||
- run: npm install
 | 
			
		||||
@ -67,18 +67,73 @@ jobs:
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - name: Setup node
 | 
			
		||||
        uses: actions/setup-node@v1
 | 
			
		||||
        uses: actions/setup-node@v2
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: ${{ matrix.node }}
 | 
			
		||||
      - run: npm install
 | 
			
		||||
      - run: npm test
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Architecture:
 | 
			
		||||
 | 
			
		||||
You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-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).
 | 
			
		||||
 | 
			
		||||
When using `architecture`, `node-version` must be provided as well.
 | 
			
		||||
```yaml
 | 
			
		||||
jobs:
 | 
			
		||||
  build:
 | 
			
		||||
    runs-on: windows-latest
 | 
			
		||||
    name: Node sample
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - uses: actions/setup-node@v2
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: '12'
 | 
			
		||||
          architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
 | 
			
		||||
      - run: npm install
 | 
			
		||||
      - run: npm test
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Multiple Operating Systems and Architectures:
 | 
			
		||||
 | 
			
		||||
```yaml
 | 
			
		||||
jobs:
 | 
			
		||||
  build:
 | 
			
		||||
    runs-on: ${{ matrix.os }}
 | 
			
		||||
    strategy:
 | 
			
		||||
      matrix:
 | 
			
		||||
        os:
 | 
			
		||||
          - ubuntu-latest
 | 
			
		||||
          - macos-latest
 | 
			
		||||
          - windows-latest
 | 
			
		||||
        node_version:
 | 
			
		||||
          - 10
 | 
			
		||||
          - 12
 | 
			
		||||
          - 14
 | 
			
		||||
        architecture:
 | 
			
		||||
          - x64
 | 
			
		||||
        # an extra windows-x86 run:
 | 
			
		||||
        include:
 | 
			
		||||
          - os: windows-2016
 | 
			
		||||
            node_version: 12
 | 
			
		||||
            architecture: x86
 | 
			
		||||
    name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - name: Setup node
 | 
			
		||||
        uses: actions/setup-node@v2
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: ${{ matrix.node_version }}
 | 
			
		||||
          architecture: ${{ matrix.architecture }}
 | 
			
		||||
      - run: npm install
 | 
			
		||||
      - run: npm test
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Publish to npmjs and GPR with npm:
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    node-version: '10.x'
 | 
			
		||||
    registry-url: 'https://registry.npmjs.org'
 | 
			
		||||
@ -86,7 +141,7 @@ steps:
 | 
			
		||||
- run: npm publish
 | 
			
		||||
  env:
 | 
			
		||||
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    registry-url: 'https://npm.pkg.github.com'
 | 
			
		||||
- run: npm publish
 | 
			
		||||
@ -98,7 +153,7 @@ Publish to npmjs and GPR with yarn:
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    node-version: '10.x'
 | 
			
		||||
    registry-url: <registry url>
 | 
			
		||||
@ -106,7 +161,7 @@ steps:
 | 
			
		||||
- run: yarn publish
 | 
			
		||||
  env:
 | 
			
		||||
    NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }}
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    registry-url: 'https://npm.pkg.github.com'
 | 
			
		||||
- run: yarn publish
 | 
			
		||||
@ -118,7 +173,7 @@ Use private packages:
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-node@v1
 | 
			
		||||
- uses: actions/setup-node@v2
 | 
			
		||||
  with:
 | 
			
		||||
    node-version: '10.x'
 | 
			
		||||
    registry-url: 'https://registry.npmjs.org'
 | 
			
		||||
 | 
			
		||||
@ -123,4 +123,13 @@ describe('authutil tests', () => {
 | 
			
		||||
    expect(rc['registry']).toBe('https://registry.npmjs.org/');
 | 
			
		||||
    expect(rc['always-auth']).toBe('true');
 | 
			
		||||
  });
 | 
			
		||||
  it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
 | 
			
		||||
    process.env.NODE_AUTH_TOKEN = 'foobar';
 | 
			
		||||
    await auth.configAuthentication('npm.pkg.github.com', 'false');
 | 
			
		||||
    expect(fs.statSync(rcFile)).toBeDefined();
 | 
			
		||||
    let rc = readRcFile(rcFile);
 | 
			
		||||
    expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
 | 
			
		||||
    expect(rc['always-auth']).toBe('false');
 | 
			
		||||
    expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -252,7 +252,7 @@ describe('setup-node', () => {
 | 
			
		||||
    expect(dlSpy).toHaveBeenCalled();
 | 
			
		||||
    expect(exSpy).toHaveBeenCalled();
 | 
			
		||||
    expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `Acquiring ${resolvedVersion} from ${expectedUrl}`
 | 
			
		||||
      `Acquiring ${resolvedVersion} - ${os.arch} from ${expectedUrl}`
 | 
			
		||||
    );
 | 
			
		||||
    expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
      `Attempting to download ${versionSpec}...`
 | 
			
		||||
@ -341,6 +341,46 @@ describe('setup-node', () => {
 | 
			
		||||
    expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('Acquires specified architecture of node', async () => {
 | 
			
		||||
    for (const {arch, version, osSpec} of [
 | 
			
		||||
      {arch: 'x86', version: '12.16.2', osSpec: 'win32'},
 | 
			
		||||
      {arch: 'x86', version: '14.0.0', osSpec: 'win32'}
 | 
			
		||||
    ]) {
 | 
			
		||||
      os.platform = osSpec;
 | 
			
		||||
      os.arch = arch;
 | 
			
		||||
      const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz';
 | 
			
		||||
      const platform = {
 | 
			
		||||
        linux: 'linux',
 | 
			
		||||
        darwin: 'darwin',
 | 
			
		||||
        win32: 'win'
 | 
			
		||||
      }[os.platform];
 | 
			
		||||
 | 
			
		||||
      inputs['node-version'] = version;
 | 
			
		||||
      inputs['architecture'] = arch;
 | 
			
		||||
      inputs['always-auth'] = false;
 | 
			
		||||
      inputs['token'] = 'faketoken';
 | 
			
		||||
 | 
			
		||||
      let expectedUrl =
 | 
			
		||||
        arch === 'x64'
 | 
			
		||||
          ? `https://github.com/actions/node-versions/releases/download/${version}/node-${version}-${platform}-${arch}.zip`
 | 
			
		||||
          : `https://nodejs.org/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;
 | 
			
		||||
 | 
			
		||||
      // ... but not in the local cache
 | 
			
		||||
      findSpy.mockImplementation(() => '');
 | 
			
		||||
 | 
			
		||||
      dlSpy.mockImplementation(async () => '/some/temp/path');
 | 
			
		||||
      let toolPath = path.normalize(`/cache/node/${version}/${arch}`);
 | 
			
		||||
      exSpy.mockImplementation(async () => '/some/other/temp/path');
 | 
			
		||||
      cacheSpy.mockImplementation(async () => toolPath);
 | 
			
		||||
 | 
			
		||||
      await main.run();
 | 
			
		||||
      expect(dlSpy).toHaveBeenCalled();
 | 
			
		||||
      expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
        `Acquiring ${version} - ${arch} from ${expectedUrl}`
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }, 100000);
 | 
			
		||||
 | 
			
		||||
  describe('check-latest flag', () => {
 | 
			
		||||
    it('use local version and dont check manifest if check-latest is not specified', async () => {
 | 
			
		||||
      os.platform = 'linux';
 | 
			
		||||
@ -403,7 +443,7 @@ describe('setup-node', () => {
 | 
			
		||||
      );
 | 
			
		||||
      expect(logSpy).toHaveBeenCalledWith("Resolved as '12.16.2'");
 | 
			
		||||
      expect(logSpy).toHaveBeenCalledWith(
 | 
			
		||||
        `Acquiring 12.16.2 from ${expectedUrl}`
 | 
			
		||||
        `Acquiring 12.16.2 - ${os.arch} from ${expectedUrl}`
 | 
			
		||||
      );
 | 
			
		||||
      expect(logSpy).toHaveBeenCalledWith('Extracting ...');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								__tests__/verify-arch.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								__tests__/verify-arch.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
if [ -n "$1" ]; then
 | 
			
		||||
  architecture="$(node -e 'console.log(process.arch)')"
 | 
			
		||||
  if [ -z "$(echo $architecture | grep --fixed-strings $1)" ]; then
 | 
			
		||||
    echo "Unexpected architecture"
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
else
 | 
			
		||||
  echo "Skip testing architecture"
 | 
			
		||||
fi
 | 
			
		||||
@ -7,6 +7,8 @@ inputs:
 | 
			
		||||
    default: 'false'
 | 
			
		||||
  node-version:
 | 
			
		||||
    description: 'Version Spec of the version to use.  Examples: 12.x, 10.15.1, >=10.15.0'
 | 
			
		||||
  architecture:
 | 
			
		||||
    description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
 | 
			
		||||
  check-latest:
 | 
			
		||||
    description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
 | 
			
		||||
    default: false
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										62
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										62
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							@ -4694,6 +4694,7 @@ const installer = __importStar(__webpack_require__(749));
 | 
			
		||||
const auth = __importStar(__webpack_require__(202));
 | 
			
		||||
const path = __importStar(__webpack_require__(622));
 | 
			
		||||
const url_1 = __webpack_require__(835);
 | 
			
		||||
const os = __webpack_require__(87);
 | 
			
		||||
function run() {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        try {
 | 
			
		||||
@ -4705,12 +4706,21 @@ function run() {
 | 
			
		||||
            if (!version) {
 | 
			
		||||
                version = core.getInput('version');
 | 
			
		||||
            }
 | 
			
		||||
            let arch = core.getInput('architecture');
 | 
			
		||||
            // if architecture supplied but node-version is not
 | 
			
		||||
            // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
 | 
			
		||||
            if (arch && !version) {
 | 
			
		||||
                core.warning('`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`');
 | 
			
		||||
            }
 | 
			
		||||
            if (!arch) {
 | 
			
		||||
                arch = os.arch();
 | 
			
		||||
            }
 | 
			
		||||
            if (version) {
 | 
			
		||||
                let token = core.getInput('token');
 | 
			
		||||
                let auth = !token || isGhes() ? undefined : `token ${token}`;
 | 
			
		||||
                let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
 | 
			
		||||
                const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
 | 
			
		||||
                yield installer.getNode(version, stable, checkLatest, auth);
 | 
			
		||||
                yield installer.getNode(version, stable, checkLatest, auth, arch);
 | 
			
		||||
            }
 | 
			
		||||
            const registryUrl = core.getInput('registry-url');
 | 
			
		||||
            const alwaysAuth = core.getInput('always-auth');
 | 
			
		||||
@ -4793,8 +4803,8 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
 | 
			
		||||
    newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
 | 
			
		||||
    fs.writeFileSync(fileLocation, newContents);
 | 
			
		||||
    core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
 | 
			
		||||
    // Export empty node_auth_token so npm doesn't complain about not being able to find it
 | 
			
		||||
    core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
 | 
			
		||||
    // Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
 | 
			
		||||
    core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
 | 
			
		||||
}
 | 
			
		||||
//# sourceMappingURL=authutil.js.map
 | 
			
		||||
 | 
			
		||||
@ -13093,13 +13103,13 @@ const tc = __importStar(__webpack_require__(533));
 | 
			
		||||
const path = __importStar(__webpack_require__(622));
 | 
			
		||||
const semver = __importStar(__webpack_require__(280));
 | 
			
		||||
const fs = __webpack_require__(747);
 | 
			
		||||
function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let osPlat = os.platform();
 | 
			
		||||
        let osArch = translateArchToDistUrl(os.arch());
 | 
			
		||||
        let osArch = translateArchToDistUrl(arch);
 | 
			
		||||
        if (checkLatest) {
 | 
			
		||||
            core.info('Attempt to resolve the latest version from manifest...');
 | 
			
		||||
            const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth);
 | 
			
		||||
            const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch);
 | 
			
		||||
            if (resolvedVersion) {
 | 
			
		||||
                versionSpec = resolvedVersion;
 | 
			
		||||
                core.info(`Resolved as '${versionSpec}'`);
 | 
			
		||||
@ -13110,7 +13120,7 @@ function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
        }
 | 
			
		||||
        // check cache
 | 
			
		||||
        let toolPath;
 | 
			
		||||
        toolPath = tc.find('node', versionSpec);
 | 
			
		||||
        toolPath = tc.find('node', versionSpec, osArch);
 | 
			
		||||
        // If not found in cache, download
 | 
			
		||||
        if (toolPath) {
 | 
			
		||||
            core.info(`Found in cache @ ${toolPath}`);
 | 
			
		||||
@ -13123,9 +13133,9 @@ function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
            // Try download from internal distribution (popular versions only)
 | 
			
		||||
            //
 | 
			
		||||
            try {
 | 
			
		||||
                info = yield getInfoFromManifest(versionSpec, stable, auth);
 | 
			
		||||
                info = yield getInfoFromManifest(versionSpec, stable, auth, osArch);
 | 
			
		||||
                if (info) {
 | 
			
		||||
                    core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
 | 
			
		||||
                    core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
 | 
			
		||||
                    downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
@ -13148,17 +13158,17 @@ function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
            // Download from nodejs.org
 | 
			
		||||
            //
 | 
			
		||||
            if (!downloadPath) {
 | 
			
		||||
                info = yield getInfoFromDist(versionSpec);
 | 
			
		||||
                info = yield getInfoFromDist(versionSpec, arch);
 | 
			
		||||
                if (!info) {
 | 
			
		||||
                    throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
 | 
			
		||||
                }
 | 
			
		||||
                core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
 | 
			
		||||
                core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
 | 
			
		||||
                try {
 | 
			
		||||
                    downloadPath = yield tc.downloadTool(info.downloadUrl);
 | 
			
		||||
                }
 | 
			
		||||
                catch (err) {
 | 
			
		||||
                    if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
			
		||||
                        return yield acquireNodeFromFallbackLocation(info.resolvedVersion);
 | 
			
		||||
                        return yield acquireNodeFromFallbackLocation(info.resolvedVersion, info.arch);
 | 
			
		||||
                    }
 | 
			
		||||
                    throw err;
 | 
			
		||||
                }
 | 
			
		||||
@ -13189,7 +13199,7 @@ function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
            // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
 | 
			
		||||
            //
 | 
			
		||||
            core.info('Adding to the cache ...');
 | 
			
		||||
            toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion);
 | 
			
		||||
            toolPath = yield tc.cacheDir(extPath, 'node', info.resolvedVersion, info.arch);
 | 
			
		||||
            core.info('Done');
 | 
			
		||||
        }
 | 
			
		||||
        //
 | 
			
		||||
@ -13206,26 +13216,27 @@ function getNode(versionSpec, stable, checkLatest, auth) {
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
exports.getNode = getNode;
 | 
			
		||||
function getInfoFromManifest(versionSpec, stable, auth) {
 | 
			
		||||
function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let info = null;
 | 
			
		||||
        const releases = yield tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
 | 
			
		||||
        const rel = yield tc.findFromManifest(versionSpec, stable, releases);
 | 
			
		||||
        const rel = yield tc.findFromManifest(versionSpec, stable, releases, osArch);
 | 
			
		||||
        if (rel && rel.files.length > 0) {
 | 
			
		||||
            info = {};
 | 
			
		||||
            info.resolvedVersion = rel.version;
 | 
			
		||||
            info.arch = rel.files[0].arch;
 | 
			
		||||
            info.downloadUrl = rel.files[0].download_url;
 | 
			
		||||
            info.fileName = rel.files[0].filename;
 | 
			
		||||
        }
 | 
			
		||||
        return info;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
function getInfoFromDist(versionSpec) {
 | 
			
		||||
function getInfoFromDist(versionSpec, arch = os.arch()) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let osPlat = os.platform();
 | 
			
		||||
        let osArch = translateArchToDistUrl(os.arch());
 | 
			
		||||
        let osArch = translateArchToDistUrl(arch);
 | 
			
		||||
        let version;
 | 
			
		||||
        version = yield queryDistForMatch(versionSpec);
 | 
			
		||||
        version = yield queryDistForMatch(versionSpec, arch);
 | 
			
		||||
        if (!version) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
@ -13241,14 +13252,15 @@ function getInfoFromDist(versionSpec) {
 | 
			
		||||
        return {
 | 
			
		||||
            downloadUrl: url,
 | 
			
		||||
            resolvedVersion: version,
 | 
			
		||||
            arch: arch,
 | 
			
		||||
            fileName: fileName
 | 
			
		||||
        };
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
function resolveVersionFromManifest(versionSpec, stable, auth) {
 | 
			
		||||
function resolveVersionFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch())) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        try {
 | 
			
		||||
            const info = yield getInfoFromManifest(versionSpec, stable, auth);
 | 
			
		||||
            const info = yield getInfoFromManifest(versionSpec, stable, auth, osArch);
 | 
			
		||||
            return info === null || info === void 0 ? void 0 : info.resolvedVersion;
 | 
			
		||||
        }
 | 
			
		||||
        catch (err) {
 | 
			
		||||
@ -13283,10 +13295,10 @@ function evaluateVersions(versions, versionSpec) {
 | 
			
		||||
    }
 | 
			
		||||
    return version;
 | 
			
		||||
}
 | 
			
		||||
function queryDistForMatch(versionSpec) {
 | 
			
		||||
function queryDistForMatch(versionSpec, arch = os.arch()) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let osPlat = os.platform();
 | 
			
		||||
        let osArch = translateArchToDistUrl(os.arch());
 | 
			
		||||
        let osArch = translateArchToDistUrl(arch);
 | 
			
		||||
        // node offers a json list of versions
 | 
			
		||||
        let dataFileName;
 | 
			
		||||
        switch (osPlat) {
 | 
			
		||||
@ -13339,10 +13351,10 @@ exports.getVersionsFromDist = getVersionsFromDist;
 | 
			
		||||
// This method attempts to download and cache the resources from these alternative locations.
 | 
			
		||||
// Note also that the files are normally zipped but in this case they are just an exe
 | 
			
		||||
// and lib file in a folder, not zipped.
 | 
			
		||||
function acquireNodeFromFallbackLocation(version) {
 | 
			
		||||
function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let osPlat = os.platform();
 | 
			
		||||
        let osArch = translateArchToDistUrl(os.arch());
 | 
			
		||||
        let osArch = translateArchToDistUrl(arch);
 | 
			
		||||
        // Create temporary folder to download in to
 | 
			
		||||
        const tempDownloadFolder = 'temp_' + Math.floor(Math.random() * 2000000000);
 | 
			
		||||
        const tempDirectory = process.env['RUNNER_TEMP'] || '';
 | 
			
		||||
@ -13373,7 +13385,7 @@ function acquireNodeFromFallbackLocation(version) {
 | 
			
		||||
                throw err;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        let toolPath = yield tc.cacheDir(tempDir, 'node', version);
 | 
			
		||||
        let toolPath = yield tc.cacheDir(tempDir, 'node', version, arch);
 | 
			
		||||
        core.addPath(toolPath);
 | 
			
		||||
        return toolPath;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -53,6 +53,9 @@ function writeRegistryToFile(
 | 
			
		||||
  newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
 | 
			
		||||
  fs.writeFileSync(fileLocation, newContents);
 | 
			
		||||
  core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
 | 
			
		||||
  // Export empty node_auth_token so npm doesn't complain about not being able to find it
 | 
			
		||||
  core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
 | 
			
		||||
  // Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
 | 
			
		||||
  core.exportVariable(
 | 
			
		||||
    'NODE_AUTH_TOKEN',
 | 
			
		||||
    process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@ export interface INodeVersion {
 | 
			
		||||
interface INodeVersionInfo {
 | 
			
		||||
  downloadUrl: string;
 | 
			
		||||
  resolvedVersion: string;
 | 
			
		||||
  arch: string;
 | 
			
		||||
  fileName: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -27,17 +28,19 @@ export async function getNode(
 | 
			
		||||
  versionSpec: string,
 | 
			
		||||
  stable: boolean,
 | 
			
		||||
  checkLatest: boolean,
 | 
			
		||||
  auth: string | undefined
 | 
			
		||||
  auth: string | undefined,
 | 
			
		||||
  arch: string = os.arch()
 | 
			
		||||
) {
 | 
			
		||||
  let osPlat: string = os.platform();
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(os.arch());
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
			
		||||
 | 
			
		||||
  if (checkLatest) {
 | 
			
		||||
    core.info('Attempt to resolve the latest version from manifest...');
 | 
			
		||||
    const resolvedVersion = await resolveVersionFromManifest(
 | 
			
		||||
      versionSpec,
 | 
			
		||||
      stable,
 | 
			
		||||
      auth
 | 
			
		||||
      auth,
 | 
			
		||||
      osArch
 | 
			
		||||
    );
 | 
			
		||||
    if (resolvedVersion) {
 | 
			
		||||
      versionSpec = resolvedVersion;
 | 
			
		||||
@ -49,7 +52,7 @@ export async function getNode(
 | 
			
		||||
 | 
			
		||||
  // check cache
 | 
			
		||||
  let toolPath: string;
 | 
			
		||||
  toolPath = tc.find('node', versionSpec);
 | 
			
		||||
  toolPath = tc.find('node', versionSpec, osArch);
 | 
			
		||||
 | 
			
		||||
  // If not found in cache, download
 | 
			
		||||
  if (toolPath) {
 | 
			
		||||
@ -63,9 +66,11 @@ export async function getNode(
 | 
			
		||||
    // Try download from internal distribution (popular versions only)
 | 
			
		||||
    //
 | 
			
		||||
    try {
 | 
			
		||||
      info = await getInfoFromManifest(versionSpec, stable, auth);
 | 
			
		||||
      info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
 | 
			
		||||
      if (info) {
 | 
			
		||||
        core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
 | 
			
		||||
        core.info(
 | 
			
		||||
          `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
 | 
			
		||||
        );
 | 
			
		||||
        downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
 | 
			
		||||
      } else {
 | 
			
		||||
        core.info(
 | 
			
		||||
@ -92,19 +97,24 @@ export async function getNode(
 | 
			
		||||
    // Download from nodejs.org
 | 
			
		||||
    //
 | 
			
		||||
    if (!downloadPath) {
 | 
			
		||||
      info = await getInfoFromDist(versionSpec);
 | 
			
		||||
      info = await getInfoFromDist(versionSpec, arch);
 | 
			
		||||
      if (!info) {
 | 
			
		||||
        throw new Error(
 | 
			
		||||
          `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
 | 
			
		||||
        );
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
 | 
			
		||||
      core.info(
 | 
			
		||||
        `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
 | 
			
		||||
      );
 | 
			
		||||
      try {
 | 
			
		||||
        downloadPath = await tc.downloadTool(info.downloadUrl);
 | 
			
		||||
      } catch (err) {
 | 
			
		||||
        if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
 | 
			
		||||
          return await acquireNodeFromFallbackLocation(info.resolvedVersion);
 | 
			
		||||
          return await acquireNodeFromFallbackLocation(
 | 
			
		||||
            info.resolvedVersion,
 | 
			
		||||
            info.arch
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw err;
 | 
			
		||||
@ -137,7 +147,12 @@ export async function getNode(
 | 
			
		||||
    // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
 | 
			
		||||
    //
 | 
			
		||||
    core.info('Adding to the cache ...');
 | 
			
		||||
    toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion);
 | 
			
		||||
    toolPath = await tc.cacheDir(
 | 
			
		||||
      extPath,
 | 
			
		||||
      'node',
 | 
			
		||||
      info.resolvedVersion,
 | 
			
		||||
      info.arch
 | 
			
		||||
    );
 | 
			
		||||
    core.info('Done');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -158,7 +173,8 @@ export async function getNode(
 | 
			
		||||
async function getInfoFromManifest(
 | 
			
		||||
  versionSpec: string,
 | 
			
		||||
  stable: boolean,
 | 
			
		||||
  auth: string | undefined
 | 
			
		||||
  auth: string | undefined,
 | 
			
		||||
  osArch: string = translateArchToDistUrl(os.arch())
 | 
			
		||||
): Promise<INodeVersionInfo | null> {
 | 
			
		||||
  let info: INodeVersionInfo | null = null;
 | 
			
		||||
  const releases = await tc.getManifestFromRepo(
 | 
			
		||||
@ -167,11 +183,12 @@ async function getInfoFromManifest(
 | 
			
		||||
    auth,
 | 
			
		||||
    'main'
 | 
			
		||||
  );
 | 
			
		||||
  const rel = await tc.findFromManifest(versionSpec, stable, releases);
 | 
			
		||||
  const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch);
 | 
			
		||||
 | 
			
		||||
  if (rel && rel.files.length > 0) {
 | 
			
		||||
    info = <INodeVersionInfo>{};
 | 
			
		||||
    info.resolvedVersion = rel.version;
 | 
			
		||||
    info.arch = rel.files[0].arch;
 | 
			
		||||
    info.downloadUrl = rel.files[0].download_url;
 | 
			
		||||
    info.fileName = rel.files[0].filename;
 | 
			
		||||
  }
 | 
			
		||||
@ -180,14 +197,15 @@ async function getInfoFromManifest(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getInfoFromDist(
 | 
			
		||||
  versionSpec: string
 | 
			
		||||
  versionSpec: string,
 | 
			
		||||
  arch: string = os.arch()
 | 
			
		||||
): Promise<INodeVersionInfo | null> {
 | 
			
		||||
  let osPlat: string = os.platform();
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(os.arch());
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
			
		||||
 | 
			
		||||
  let version: string;
 | 
			
		||||
 | 
			
		||||
  version = await queryDistForMatch(versionSpec);
 | 
			
		||||
  version = await queryDistForMatch(versionSpec, arch);
 | 
			
		||||
  if (!version) {
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
@ -207,6 +225,7 @@ async function getInfoFromDist(
 | 
			
		||||
  return <INodeVersionInfo>{
 | 
			
		||||
    downloadUrl: url,
 | 
			
		||||
    resolvedVersion: version,
 | 
			
		||||
    arch: arch,
 | 
			
		||||
    fileName: fileName
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@ -214,10 +233,11 @@ async function getInfoFromDist(
 | 
			
		||||
async function resolveVersionFromManifest(
 | 
			
		||||
  versionSpec: string,
 | 
			
		||||
  stable: boolean,
 | 
			
		||||
  auth: string | undefined
 | 
			
		||||
  auth: string | undefined,
 | 
			
		||||
  osArch: string = translateArchToDistUrl(os.arch())
 | 
			
		||||
): Promise<string | undefined> {
 | 
			
		||||
  try {
 | 
			
		||||
    const info = await getInfoFromManifest(versionSpec, stable, auth);
 | 
			
		||||
    const info = await getInfoFromManifest(versionSpec, stable, auth, osArch);
 | 
			
		||||
    return info?.resolvedVersion;
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    core.info('Unable to resolve version from manifest...');
 | 
			
		||||
@ -253,9 +273,12 @@ function evaluateVersions(versions: string[], versionSpec: string): string {
 | 
			
		||||
  return version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function queryDistForMatch(versionSpec: string): Promise<string> {
 | 
			
		||||
async function queryDistForMatch(
 | 
			
		||||
  versionSpec: string,
 | 
			
		||||
  arch: string = os.arch()
 | 
			
		||||
): Promise<string> {
 | 
			
		||||
  let osPlat: string = os.platform();
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(os.arch());
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
			
		||||
 | 
			
		||||
  // node offers a json list of versions
 | 
			
		||||
  let dataFileName: string;
 | 
			
		||||
@ -311,10 +334,11 @@ export async function getVersionsFromDist(): Promise<INodeVersion[]> {
 | 
			
		||||
// Note also that the files are normally zipped but in this case they are just an exe
 | 
			
		||||
// and lib file in a folder, not zipped.
 | 
			
		||||
async function acquireNodeFromFallbackLocation(
 | 
			
		||||
  version: string
 | 
			
		||||
  version: string,
 | 
			
		||||
  arch: string = os.arch()
 | 
			
		||||
): Promise<string> {
 | 
			
		||||
  let osPlat: string = os.platform();
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(os.arch());
 | 
			
		||||
  let osArch: string = translateArchToDistUrl(arch);
 | 
			
		||||
 | 
			
		||||
  // Create temporary folder to download in to
 | 
			
		||||
  const tempDownloadFolder: string =
 | 
			
		||||
@ -348,7 +372,7 @@ async function acquireNodeFromFallbackLocation(
 | 
			
		||||
      throw err;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  let toolPath = await tc.cacheDir(tempDir, 'node', version);
 | 
			
		||||
  let toolPath = await tc.cacheDir(tempDir, 'node', version, arch);
 | 
			
		||||
  core.addPath(toolPath);
 | 
			
		||||
  return toolPath;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/main.ts
									
									
									
									
									
								
							@ -3,6 +3,7 @@ import * as installer from './installer';
 | 
			
		||||
import * as auth from './authutil';
 | 
			
		||||
import * as path from 'path';
 | 
			
		||||
import {URL} from 'url';
 | 
			
		||||
import os = require('os');
 | 
			
		||||
 | 
			
		||||
export async function run() {
 | 
			
		||||
  try {
 | 
			
		||||
@ -15,13 +16,27 @@ export async function run() {
 | 
			
		||||
      version = core.getInput('version');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let arch = core.getInput('architecture');
 | 
			
		||||
 | 
			
		||||
    // if architecture supplied but node-version is not
 | 
			
		||||
    // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
 | 
			
		||||
    if (arch && !version) {
 | 
			
		||||
      core.warning(
 | 
			
		||||
        '`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`'
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!arch) {
 | 
			
		||||
      arch = os.arch();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (version) {
 | 
			
		||||
      let token = core.getInput('token');
 | 
			
		||||
      let auth = !token || isGhes() ? undefined : `token ${token}`;
 | 
			
		||||
      let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
 | 
			
		||||
      const checkLatest =
 | 
			
		||||
        (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
 | 
			
		||||
      await installer.getNode(version, stable, checkLatest, auth);
 | 
			
		||||
      await installer.getNode(version, stable, checkLatest, auth, arch);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const registryUrl: string = core.getInput('registry-url');
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user