mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 16:23:34 +00:00 
			
		
		
		
	Merge 25df5cda4f442edb429c7dfd258206c6f29681ca into 89d709d423dc495668cd762a18dd4a070611be3f
This commit is contained in:
		
						commit
						488bfd566f
					
				
							
								
								
									
										30
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										30
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							| @ -168,6 +168,36 @@ jobs: | ||||
|       - name: Verify node | ||||
|         run: __tests__/verify-node.sh 24 | ||||
| 
 | ||||
|   version-file-dev-engines: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|       matrix: | ||||
|         os: [ubuntu-latest, windows-latest, macos-latest, macos-13] | ||||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - name: Setup node from node version file | ||||
|         uses: ./ | ||||
|         with: | ||||
|           node-version-file: '__tests__/data/package-dev-engines.json' | ||||
|       - name: Verify node | ||||
|         run: __tests__/verify-node.sh 20 | ||||
| 
 | ||||
|   version-file-dev-engines-array: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|       matrix: | ||||
|         os: [ubuntu-latest, windows-latest, macos-latest, macos-13] | ||||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - name: Setup node from node version file | ||||
|         uses: ./ | ||||
|         with: | ||||
|           node-version-file: '__tests__/data/package-dev-engines-array.json' | ||||
|       - name: Verify node | ||||
|         run: __tests__/verify-node.sh 20 | ||||
| 
 | ||||
|   version-file-volta: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     strategy: | ||||
|  | ||||
							
								
								
									
										17
									
								
								__tests__/data/package-dev-engines-array.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								__tests__/data/package-dev-engines-array.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| { | ||||
|   "engines": { | ||||
|     "node": "^19" | ||||
|   }, | ||||
|   "devEngines": { | ||||
|     "runtime": [ | ||||
|       { | ||||
|         "name": "bun", | ||||
|         "version": "^1" | ||||
|       }, | ||||
|       { | ||||
|         "name": "node", | ||||
|         "version": "^20" | ||||
|       } | ||||
|     ] | ||||
|   } | ||||
| } | ||||
							
								
								
									
										11
									
								
								__tests__/data/package-dev-engines.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								__tests__/data/package-dev-engines.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| { | ||||
|   "engines": { | ||||
|     "node": "^19" | ||||
|   }, | ||||
|   "devEngines": { | ||||
|     "runtime": { | ||||
|       "name": "node", | ||||
|       "version": "^20" | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -94,22 +94,24 @@ describe('main tests', () => { | ||||
| 
 | ||||
|   describe('getNodeVersionFromFile', () => { | ||||
|     each` | ||||
|       contents                                     | expected | ||||
|       ${'12'}                                      | ${'12'} | ||||
|       ${'12.3'}                                    | ${'12.3'} | ||||
|       ${'12.3.4'}                                  | ${'12.3.4'} | ||||
|       ${'v12.3.4'}                                 | ${'12.3.4'} | ||||
|       ${'lts/erbium'}                              | ${'lts/erbium'} | ||||
|       ${'lts/*'}                                   | ${'lts/*'} | ||||
|       ${'nodejs 12.3.4'}                           | ${'12.3.4'} | ||||
|       ${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'} | ||||
|       ${''}                                        | ${''} | ||||
|       ${'unknown format'}                          | ${'unknown format'} | ||||
|       ${'  14.1.0  '}                              | ${'14.1.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'} | ||||
|       ${'{}'}                                      | ${null} | ||||
|       contents                                                                                   | expected | ||||
|       ${'12'}                                                                                    | ${'12'} | ||||
|       ${'12.3'}                                                                                  | ${'12.3'} | ||||
|       ${'12.3.4'}                                                                                | ${'12.3.4'} | ||||
|       ${'v12.3.4'}                                                                               | ${'12.3.4'} | ||||
|       ${'lts/erbium'}                                                                            | ${'lts/erbium'} | ||||
|       ${'lts/*'}                                                                                 | ${'lts/*'} | ||||
|       ${'nodejs 12.3.4'}                                                                         | ${'12.3.4'} | ||||
|       ${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'}                                               | ${'12.3.4'} | ||||
|       ${''}                                                                                      | ${''} | ||||
|       ${'unknown format'}                                                                        | ${'unknown format'} | ||||
|       ${'  14.1.0  '}                                                                            | ${'14.1.0'} | ||||
|       ${'{}'}                                                                                    | ${null} | ||||
|       ${'{"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'} | ||||
|       ${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'}                    | ${'22.0.0'} | ||||
|       ${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'} | ||||
|     `.it('parses "$contents"', ({contents, expected}) => {
 | ||||
|       const existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|       existsSpy.mockImplementation(() => true); | ||||
|  | ||||
| @ -71,7 +71,35 @@ steps: | ||||
| - run: npm test | ||||
| ``` | ||||
| 
 | ||||
| When using the `package.json` input, the action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`. | ||||
| When using the `package.json` input, the action will look in following field for a specified Node version: | ||||
| 1. It checks `volta.node` first. | ||||
| 2. Then it checks `devEngines.runtime`. | ||||
| 3. Then it will look for `engines.node`. | ||||
| 4. Otherwise it tries to resolve the file defined by [`volta.extends`](https://docs.volta.sh/advanced/workspaces) | ||||
|    and look for `volta.node` or `engines.node` recursively. | ||||
| 
 | ||||
| ### Example with `devEngines` | ||||
| 
 | ||||
| When a runtime engine (`engines.node`) is defined but also a development engine (`devEngines.runtime`) then the `devEngine` runtime version is used. | ||||
| This example will install a Node version based on the `^20.10` pattern. | ||||
| 
 | ||||
| ```json | ||||
| { | ||||
|   "engines": { | ||||
|     "node": "^19" | ||||
|   }, | ||||
|   "devEngines": { | ||||
|     "runtime": { | ||||
|       "name": "node", | ||||
|       "version": "^20.10" | ||||
|     } | ||||
|   } | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| ### Example with volta pinned Node version | ||||
| 
 | ||||
| When both `engines.node` and `volta.node` is defined the value in `volta.node` is used. | ||||
| 
 | ||||
| ```json | ||||
| { | ||||
| @ -84,8 +112,6 @@ 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 | ||||
| 
 | ||||
| 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). | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/util.ts
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/util.ts
									
									
									
									
									
								
							| @ -26,6 +26,18 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null { | ||||
|         return manifest.volta.node; | ||||
|       } | ||||
| 
 | ||||
|       // support devEngines from npm 11
 | ||||
|       if (manifest.devEngines?.runtime) { | ||||
|         // find an entry with name set to node and having set a version.
 | ||||
|         // the devEngines.runtime can either be an object or an array of objects
 | ||||
|         const nodeEntry = [manifest.devEngines.runtime] | ||||
|           .flat() | ||||
|           .find(({name, version}) => name.toLowerCase() === 'node' && version); | ||||
|         if (nodeEntry) { | ||||
|           return nodeEntry.version; | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       if (manifest.engines?.node) { | ||||
|         return manifest.engines.node; | ||||
|       } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user