mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 15:50:33 +00:00 
			
		
		
		
	Compare commits
	
		
			24 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 6edd4406fa | ||
|   | 38dbe75f81 | ||
|   | 30c39bfe0c | ||
|   | 8377b69a56 | ||
|   | d0a58c1c4d | ||
|   | 3dcd9d6eb3 | ||
|   | e983b65a44 | ||
|   | 27b43e1b0d | ||
|   | 7678c83214 | ||
|   | c4a742cab1 | ||
|   | f556e5b7e0 | ||
|   | 514ae57904 | ||
|   | 30b9ddff11 | ||
|   | c4e169859f | ||
|   | db58e98a43 | ||
|   | 2905db4069 | ||
|   | 57452eb902 | ||
|   | 5547b9ed8d | ||
|   | be45b2722d | ||
|   | 4c32251b06 | ||
|   | e68a999c97 | ||
|   | b855b20887 | ||
|   | bf059911e8 | ||
|   | 884d2909a6 | 
							
								
								
									
										1
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							| @@ -27,6 +27,7 @@ jobs: | |||||||
|         uses: actions/setup-node@v3 |         uses: actions/setup-node@v3 | ||||||
|         with: |         with: | ||||||
|           node-version: 16.x |           node-version: 16.x | ||||||
|  |           cache: npm | ||||||
|  |  | ||||||
|       - name: Install dependencies |       - name: Install dependencies | ||||||
|         run: npm ci |         run: npm ci | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ jobs: | |||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     steps: |     steps: | ||||||
|       - name: Update the ${{ env.TAG_NAME }} tag |       - name: Update the ${{ env.TAG_NAME }} tag | ||||||
|         uses: actions/publish-action@v0.1.0 |         uses: actions/publish-action@v0.2.1 | ||||||
|         with: |         with: | ||||||
|           source-tag: ${{ env.TAG_NAME }} |           source-tag: ${{ env.TAG_NAME }} | ||||||
|           slack-webhook: ${{ secrets.SLACK_WEBHOOK }} |           slack-webhook: ${{ secrets.SLACK_WEBHOOK }} | ||||||
|   | |||||||
							
								
								
									
										67
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										67
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							| @@ -12,6 +12,57 @@ on: | |||||||
|     - cron: 0 0 * * * |     - cron: 0 0 * * * | ||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|  |   stable: | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: [ubuntu-latest, windows-latest, macos-latest] | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v3 | ||||||
|  |       - name: Setup Go Stable | ||||||
|  |         uses: ./ | ||||||
|  |         with: | ||||||
|  |           go-version: stable | ||||||
|  |       - name: Verify Go | ||||||
|  |         run: go version | ||||||
|  |  | ||||||
|  |   oldstable: | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: [ubuntu-latest, windows-latest, macos-latest] | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v3 | ||||||
|  |       - name: Setup Go oldStable | ||||||
|  |         uses: ./ | ||||||
|  |         with: | ||||||
|  |           go-version: oldstable | ||||||
|  |       - name: Verify Go | ||||||
|  |         run: go version | ||||||
|  |    | ||||||
|  |   aliases-arch: | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: [ubuntu-latest, windows-latest, macos-latest] | ||||||
|  |         version: [stable, oldstable] | ||||||
|  |         architecture: [x64, x32] | ||||||
|  |         exclude: | ||||||
|  |         - os: macos-latest | ||||||
|  |           architecture: x32 | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v3 | ||||||
|  |       - name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }} | ||||||
|  |         uses: ./ | ||||||
|  |         with: | ||||||
|  |           go-version: ${{ matrix.version }} | ||||||
|  |           architecture: ${{ matrix.architecture }} | ||||||
|  |       - name: Verify Go | ||||||
|  |         run: go version | ||||||
|  |  | ||||||
|   local-cache: |   local-cache: | ||||||
|     name: Setup local-cache version |     name: Setup local-cache version | ||||||
|     runs-on: ${{ matrix.os }} |     runs-on: ${{ matrix.os }} | ||||||
| @@ -66,6 +117,22 @@ jobs: | |||||||
|         run: __tests__/verify-go.sh 1.14 |         run: __tests__/verify-go.sh 1.14 | ||||||
|         shell: bash |         shell: bash | ||||||
|  |  | ||||||
|  |   go-version-file-with-gowork: | ||||||
|  |     runs-on: ${{ matrix.os }} | ||||||
|  |     strategy: | ||||||
|  |       fail-fast: false | ||||||
|  |       matrix: | ||||||
|  |         os: [ubuntu-latest, windows-latest, macos-latest] | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v3 | ||||||
|  |       - name: Setup Go and check latest | ||||||
|  |         uses: ./ | ||||||
|  |         with: | ||||||
|  |           go-version-file: __tests__/data/go.work | ||||||
|  |       - name: verify go | ||||||
|  |         run: __tests__/verify-go.sh 1.19 | ||||||
|  |         shell: bash | ||||||
|  |  | ||||||
|   setup-versions-from-manifest: |   setup-versions-from-manifest: | ||||||
|     name: Setup ${{ matrix.go }} ${{ matrix.os }} |     name: Setup ${{ matrix.go }} ${{ matrix.os }} | ||||||
|     runs-on: ${{ matrix.os }} |     runs-on: ${{ matrix.os }} | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								.licenses/npm/@actions/core.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.licenses/npm/@actions/core.dep.yml
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| --- | --- | ||||||
| name: "@actions/core" | name: "@actions/core" | ||||||
| version: 1.6.0 | version: 1.10.0 | ||||||
| type: npm | type: npm | ||||||
| summary: Actions core lib | summary: Actions core lib | ||||||
| homepage: https://github.com/actions/toolkit/tree/main/packages/core | homepage: https://github.com/actions/toolkit/tree/main/packages/core | ||||||
|   | |||||||
							
								
								
									
										47
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								README.md
									
									
									
									
									
								
							| @@ -16,6 +16,7 @@ The V3 edition of the action offers: | |||||||
| - Proxy support | - Proxy support | ||||||
| - Check latest version | - Check latest version | ||||||
| - Caching packages dependencies | - Caching packages dependencies | ||||||
|  | - stable and oldstable aliases | ||||||
| - Bug Fixes (including issues around version matching and semver) | - Bug Fixes (including issues around version matching and semver) | ||||||
|  |  | ||||||
| The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version). | The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version). | ||||||
| @@ -95,6 +96,33 @@ steps: | |||||||
|       check-latest: true |       check-latest: true | ||||||
|   - run: go run hello.go |   - run: go run hello.go | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  | ## Using stable/oldstable aliases | ||||||
|  |  | ||||||
|  | If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.  | ||||||
|  |  | ||||||
|  | If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release. | ||||||
|  |  | ||||||
|  | **Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true` | ||||||
|  |  | ||||||
|  | ```yaml | ||||||
|  | steps: | ||||||
|  |   - uses: actions/checkout@v3 | ||||||
|  |   - uses: actions/setup-go@v3 | ||||||
|  |     with: | ||||||
|  |       go-version: 'stable' | ||||||
|  |   - run: go run hello.go | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```yaml | ||||||
|  | steps: | ||||||
|  |   - uses: actions/checkout@v3 | ||||||
|  |   - uses: actions/setup-go@v3 | ||||||
|  |     with: | ||||||
|  |       go-version: 'oldstable' | ||||||
|  |   - run: go run hello.go | ||||||
|  | ``` | ||||||
|  |  | ||||||
| ## Caching dependency files and build outputs: | ## Caching dependency files and build outputs: | ||||||
|  |  | ||||||
| The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default. | The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default. | ||||||
| @@ -127,7 +155,7 @@ steps: | |||||||
|   ``` |   ``` | ||||||
| ## Getting go version from the go.mod file | ## Getting go version from the go.mod file | ||||||
|  |  | ||||||
| The `go-version-file` input accepts a path to a `go.mod` file containing the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers. | The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers. | ||||||
|  |  | ||||||
| If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. | If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. | ||||||
| > The action will search for the `go.mod` file relative to the repository root | > The action will search for the `go.mod` file relative to the repository root | ||||||
| @@ -169,6 +197,21 @@ The `go-version` input supports the following syntax: | |||||||
|  |  | ||||||
| For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation. | For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation. | ||||||
|  |  | ||||||
|  | ## Using `setup-go` on GHES | ||||||
|  |  | ||||||
|  | `setup-go` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Go distributions, `setup-go` downloads distributions from [`actions/go-versions`](https://github.com/actions/go-versions) on github.com (outside of the appliance). These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`. After that error the action will try to download versions directly from https://storage.googleapis.com/golang, but it also can have rate limit so it's better to put token. | ||||||
|  |  | ||||||
|  | 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 | ||||||
|  | uses: actions/setup-go@v3 | ||||||
|  | with: | ||||||
|  |   token: ${{ secrets.GH_DOTCOM_TOKEN }} | ||||||
|  |   go-version: 1.18 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information. | ||||||
|  |  | ||||||
| # License | # License | ||||||
|  |  | ||||||
| The scripts and documentation in this project are released under the [MIT License](LICENSE) | The scripts and documentation in this project are released under the [MIT License](LICENSE) | ||||||
| @@ -179,4 +222,4 @@ Contributions are welcome! See [Contributor's Guide](docs/contributors.md) | |||||||
|  |  | ||||||
| ## Code of Conduct | ## Code of Conduct | ||||||
|  |  | ||||||
| :wave: Be nice. See [our code of conduct](CONDUCT) | :wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md) | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ describe('restoreCache', () => { | |||||||
|   let infoSpy = jest.spyOn(core, 'info'); |   let infoSpy = jest.spyOn(core, 'info'); | ||||||
|   let setOutputSpy = jest.spyOn(core, 'setOutput'); |   let setOutputSpy = jest.spyOn(core, 'setOutput'); | ||||||
|  |  | ||||||
|  |   const versionSpec = '1.13.1'; | ||||||
|   const packageManager = 'default'; |   const packageManager = 'default'; | ||||||
|   const cacheDependencyPath = 'path'; |   const cacheDependencyPath = 'path'; | ||||||
|  |  | ||||||
| @@ -40,7 +41,11 @@ describe('restoreCache', () => { | |||||||
|  |  | ||||||
|     //Act + Assert |     //Act + Assert | ||||||
|     expect(async () => { |     expect(async () => { | ||||||
|       await cacheRestore.restoreCache(packageManager, cacheDependencyPath); |       await cacheRestore.restoreCache( | ||||||
|  |         versionSpec, | ||||||
|  |         packageManager, | ||||||
|  |         cacheDependencyPath | ||||||
|  |       ); | ||||||
|     }).rejects.toThrowError( |     }).rejects.toThrowError( | ||||||
|       'Some specified paths were not resolved, unable to cache dependencies.' |       'Some specified paths were not resolved, unable to cache dependencies.' | ||||||
|     ); |     ); | ||||||
| @@ -61,7 +66,11 @@ describe('restoreCache', () => { | |||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     //Act + Assert |     //Act + Assert | ||||||
|     await cacheRestore.restoreCache(packageManager, cacheDependencyPath); |     await cacheRestore.restoreCache( | ||||||
|  |       versionSpec, | ||||||
|  |       packageManager, | ||||||
|  |       cacheDependencyPath | ||||||
|  |     ); | ||||||
|     expect(infoSpy).toBeCalledWith(`Cache is not found`); |     expect(infoSpy).toBeCalledWith(`Cache is not found`); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
| @@ -80,7 +89,11 @@ describe('restoreCache', () => { | |||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     //Act + Assert |     //Act + Assert | ||||||
|     await cacheRestore.restoreCache(packageManager, cacheDependencyPath); |     await cacheRestore.restoreCache( | ||||||
|  |       versionSpec, | ||||||
|  |       packageManager, | ||||||
|  |       cacheDependencyPath | ||||||
|  |     ); | ||||||
|     expect(setOutputSpy).toBeCalledWith('cache-hit', true); |     expect(setOutputSpy).toBeCalledWith('cache-hit', true); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								__tests__/data/go.work
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								__tests__/data/go.work
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | go 1.19 | ||||||
|  |  | ||||||
|  | use . | ||||||
| @@ -41,6 +41,7 @@ describe('setup-go', () => { | |||||||
|   let mkdirpSpy: jest.SpyInstance; |   let mkdirpSpy: jest.SpyInstance; | ||||||
|   let execSpy: jest.SpyInstance; |   let execSpy: jest.SpyInstance; | ||||||
|   let getManifestSpy: jest.SpyInstance; |   let getManifestSpy: jest.SpyInstance; | ||||||
|  |   let getAllVersionsSpy: jest.SpyInstance; | ||||||
|  |  | ||||||
|   beforeAll(async () => { |   beforeAll(async () => { | ||||||
|     process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible) |     process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible) | ||||||
| @@ -83,6 +84,7 @@ describe('setup-go', () => { | |||||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); |     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||||
|     getSpy = jest.spyOn(im, 'getVersionsDist'); |     getSpy = jest.spyOn(im, 'getVersionsDist'); | ||||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); |     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||||
|  |     getAllVersionsSpy = jest.spyOn(im, 'getManifest'); | ||||||
|  |  | ||||||
|     // io |     // io | ||||||
|     whichSpy = jest.spyOn(io, 'which'); |     whichSpy = jest.spyOn(io, 'which'); | ||||||
| @@ -295,7 +297,6 @@ describe('setup-go', () => { | |||||||
|     findSpy.mockImplementation(() => toolPath); |     findSpy.mockImplementation(() => toolPath); | ||||||
|     await main.run(); |     await main.run(); | ||||||
|  |  | ||||||
|     let expPath = path.join(toolPath, 'bin'); |  | ||||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); |     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
| @@ -462,9 +463,6 @@ describe('setup-go', () => { | |||||||
|     inputs['go-version'] = versionSpec; |     inputs['go-version'] = versionSpec; | ||||||
|     inputs['token'] = 'faketoken'; |     inputs['token'] = 'faketoken'; | ||||||
|  |  | ||||||
|     let expectedUrl = |  | ||||||
|       'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz'; |  | ||||||
|  |  | ||||||
|     // ... but not in the local cache |     // ... but not in the local cache | ||||||
|     findSpy.mockImplementation(() => ''); |     findSpy.mockImplementation(() => ''); | ||||||
|  |  | ||||||
| @@ -526,7 +524,7 @@ describe('setup-go', () => { | |||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     mkdirpSpy.mockImplementation(async () => {}); |     mkdirpSpy.mockImplementation(async () => {}); | ||||||
|     existsSpy.mockImplementation(path => { |     existsSpy.mockImplementation(() => { | ||||||
|       return false; |       return false; | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -704,11 +702,9 @@ describe('setup-go', () => { | |||||||
|  |  | ||||||
|       findSpy.mockImplementation(() => ''); |       findSpy.mockImplementation(() => ''); | ||||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); |       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||||
|       const toolPath = path.normalize('/cache/go/1.17.5/x64'); |       const toolPath = path.normalize('/cache/go/1.17.6/x64'); | ||||||
|       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); |       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||||
|       cacheSpy.mockImplementation(async () => toolPath); |       cacheSpy.mockImplementation(async () => toolPath); | ||||||
|       const expectedUrl = |  | ||||||
|         'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz'; |  | ||||||
|  |  | ||||||
|       await main.run(); |       await main.run(); | ||||||
|  |  | ||||||
| @@ -785,6 +781,7 @@ describe('setup-go', () => { | |||||||
|       getManifestSpy.mockImplementation(() => { |       getManifestSpy.mockImplementation(() => { | ||||||
|         throw new Error('Unable to download manifest'); |         throw new Error('Unable to download manifest'); | ||||||
|       }); |       }); | ||||||
|  |       getAllVersionsSpy.mockImplementationOnce(() => undefined); | ||||||
|  |  | ||||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); |       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||||
|       let toolPath = path.normalize('/cache/go/1.13.7/x64'); |       let toolPath = path.normalize('/cache/go/1.13.7/x64'); | ||||||
| @@ -830,11 +827,17 @@ require ( | |||||||
|  |  | ||||||
| replace example.com/thatmodule => ../thatmodule | replace example.com/thatmodule => ../thatmodule | ||||||
| exclude example.com/thismodule v1.3.0 | exclude example.com/thismodule v1.3.0 | ||||||
|  | `; | ||||||
|  |  | ||||||
|  |     const goWorkContents = `go 1.19 | ||||||
|  |  | ||||||
|  | use . | ||||||
|  |  | ||||||
| `; | `; | ||||||
|  |  | ||||||
|     it('reads version from go.mod', async () => { |     it('reads version from go.mod', async () => { | ||||||
|       inputs['go-version-file'] = 'go.mod'; |       inputs['go-version-file'] = 'go.mod'; | ||||||
|       existsSpy.mockImplementation(path => true); |       existsSpy.mockImplementation(() => true); | ||||||
|       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); |       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); | ||||||
|  |  | ||||||
|       await main.run(); |       await main.run(); | ||||||
| @@ -844,9 +847,21 @@ exclude example.com/thismodule v1.3.0 | |||||||
|       expect(logSpy).toHaveBeenCalledWith('matching 1.14...'); |       expect(logSpy).toHaveBeenCalledWith('matching 1.14...'); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     it('reads version from go.work', async () => { | ||||||
|  |       inputs['go-version-file'] = 'go.work'; | ||||||
|  |       existsSpy.mockImplementation(() => true); | ||||||
|  |       readFileSpy.mockImplementation(() => Buffer.from(goWorkContents)); | ||||||
|  |  | ||||||
|  |       await main.run(); | ||||||
|  |  | ||||||
|  |       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.19'); | ||||||
|  |       expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.19...'); | ||||||
|  |       expect(logSpy).toHaveBeenCalledWith('matching 1.19...'); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     it('reads version from .go-version', async () => { |     it('reads version from .go-version', async () => { | ||||||
|       inputs['go-version-file'] = '.go-version'; |       inputs['go-version-file'] = '.go-version'; | ||||||
|       existsSpy.mockImplementation(path => true); |       existsSpy.mockImplementation(() => true); | ||||||
|       readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); |       readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); | ||||||
|  |  | ||||||
|       await main.run(); |       await main.run(); | ||||||
| @@ -859,7 +874,7 @@ exclude example.com/thismodule v1.3.0 | |||||||
|     it('is overwritten by go-version', async () => { |     it('is overwritten by go-version', async () => { | ||||||
|       inputs['go-version'] = '1.13.1'; |       inputs['go-version'] = '1.13.1'; | ||||||
|       inputs['go-version-file'] = 'go.mod'; |       inputs['go-version-file'] = 'go.mod'; | ||||||
|       existsSpy.mockImplementation(path => true); |       existsSpy.mockImplementation(() => true); | ||||||
|       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); |       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); | ||||||
|  |  | ||||||
|       await main.run(); |       await main.run(); | ||||||
| @@ -871,7 +886,7 @@ exclude example.com/thismodule v1.3.0 | |||||||
|  |  | ||||||
|     it('reports a read failure', async () => { |     it('reports a read failure', async () => { | ||||||
|       inputs['go-version-file'] = 'go.mod'; |       inputs['go-version-file'] = 'go.mod'; | ||||||
|       existsSpy.mockImplementation(path => false); |       existsSpy.mockImplementation(() => false); | ||||||
|  |  | ||||||
|       await main.run(); |       await main.run(); | ||||||
|  |  | ||||||
| @@ -914,5 +929,32 @@ exclude example.com/thismodule v1.3.0 | |||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|     }, 100000); |     }, 100000); | ||||||
|  |  | ||||||
|  |     it.each(['stable', 'oldstable'])( | ||||||
|  |       'acquires latest go version with %s go-version input', | ||||||
|  |       async (alias: string) => { | ||||||
|  |         const arch = 'x64'; | ||||||
|  |         os.platform = 'darwin'; | ||||||
|  |         os.arch = arch; | ||||||
|  |  | ||||||
|  |         inputs['go-version'] = alias; | ||||||
|  |         inputs['architecture'] = os.arch; | ||||||
|  |  | ||||||
|  |         // ... but not in the local cache | ||||||
|  |         findSpy.mockImplementation(() => ''); | ||||||
|  |  | ||||||
|  |         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||||
|  |         let toolPath = path.normalize(`/cache/go/${alias}/${arch}`); | ||||||
|  |         cacheSpy.mockImplementation(async () => toolPath); | ||||||
|  |  | ||||||
|  |         await main.run(); | ||||||
|  |  | ||||||
|  |         const releaseIndex = alias === 'stable' ? 0 : 1; | ||||||
|  |  | ||||||
|  |         expect(logSpy).toHaveBeenCalledWith( | ||||||
|  |           `${alias} version resolved as ${goTestManifest[releaseIndex].version}` | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -5,13 +5,13 @@ inputs: | |||||||
|   go-version: |   go-version: | ||||||
|     description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' |     description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' | ||||||
|   go-version-file: |   go-version-file: | ||||||
|     description: 'Path to the go.mod file.' |     description: 'Path to the go.mod or go.work file.' | ||||||
|   check-latest: |   check-latest: | ||||||
|     description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec' |     description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec' | ||||||
|     default: false |     default: false | ||||||
|   token: |   token: | ||||||
|     description: Used to pull node distributions from go-versions.  Since there's a default, this is typically not supplied by the user. |     description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ||||||
|     default: ${{ github.token }} |     default: ${{ github.server_url == 'https://github.com' && github.token || '' }} | ||||||
|   cache: |   cache: | ||||||
|     description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching. |     description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching. | ||||||
|     default: false |     default: false | ||||||
|   | |||||||
							
								
								
									
										1739
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1739
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1837
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1837
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										61
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										61
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,16 +1,16 @@ | |||||||
| { | { | ||||||
|   "name": "setup-go", |   "name": "setup-go", | ||||||
|   "version": "1.0.0", |   "version": "3.3.0", | ||||||
|   "lockfileVersion": 2, |   "lockfileVersion": 2, | ||||||
|   "requires": true, |   "requires": true, | ||||||
|   "packages": { |   "packages": { | ||||||
|     "": { |     "": { | ||||||
|       "name": "setup-go", |       "name": "setup-go", | ||||||
|       "version": "1.0.0", |       "version": "3.3.0", | ||||||
|       "license": "MIT", |       "license": "MIT", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@actions/cache": "^3.0.0", |         "@actions/cache": "^3.0.0", | ||||||
|         "@actions/core": "^1.6.0", |         "@actions/core": "^1.10.0", | ||||||
|         "@actions/exec": "^1.1.0", |         "@actions/exec": "^1.1.0", | ||||||
|         "@actions/glob": "^0.2.0", |         "@actions/glob": "^0.2.0", | ||||||
|         "@actions/http-client": "^2.0.1", |         "@actions/http-client": "^2.0.1", | ||||||
| @@ -28,7 +28,7 @@ | |||||||
|         "nock": "^10.0.6", |         "nock": "^10.0.6", | ||||||
|         "prettier": "^1.17.1", |         "prettier": "^1.17.1", | ||||||
|         "ts-jest": "^27.0.5", |         "ts-jest": "^27.0.5", | ||||||
|         "typescript": "^3.8.3" |         "typescript": "^4.3.3" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/@actions/cache": { |     "node_modules/@actions/cache": { | ||||||
| @@ -57,19 +57,20 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/@actions/core": { |     "node_modules/@actions/core": { | ||||||
|       "version": "1.6.0", |       "version": "1.10.0", | ||||||
|       "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", |       "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", | ||||||
|       "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", |       "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@actions/http-client": "^1.0.11" |         "@actions/http-client": "^2.0.1", | ||||||
|  |         "uuid": "^8.3.2" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/@actions/core/node_modules/@actions/http-client": { |     "node_modules/@actions/core/node_modules/uuid": { | ||||||
|       "version": "1.0.11", |       "version": "8.3.2", | ||||||
|       "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", |       "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", | ||||||
|       "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", |       "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", | ||||||
|       "dependencies": { |       "bin": { | ||||||
|         "tunnel": "0.0.6" |         "uuid": "dist/bin/uuid" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/@actions/exec": { |     "node_modules/@actions/exec": { | ||||||
| @@ -4693,9 +4694,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/typescript": { |     "node_modules/typescript": { | ||||||
|       "version": "3.9.10", |       "version": "4.3.3", | ||||||
|       "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", |       "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz", | ||||||
|       "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", |       "integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "bin": { |       "bin": { | ||||||
|         "tsc": "bin/tsc", |         "tsc": "bin/tsc", | ||||||
| @@ -4991,20 +4992,18 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "@actions/core": { |     "@actions/core": { | ||||||
|       "version": "1.6.0", |       "version": "1.10.0", | ||||||
|       "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", |       "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", | ||||||
|       "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", |       "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", | ||||||
|       "requires": { |       "requires": { | ||||||
|         "@actions/http-client": "^1.0.11" |         "@actions/http-client": "^2.0.1", | ||||||
|  |         "uuid": "^8.3.2" | ||||||
|       }, |       }, | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@actions/http-client": { |         "uuid": { | ||||||
|           "version": "1.0.11", |           "version": "8.3.2", | ||||||
|           "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", |           "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", | ||||||
|           "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", |           "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" | ||||||
|           "requires": { |  | ||||||
|             "tunnel": "0.0.6" |  | ||||||
|           } |  | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| @@ -8566,9 +8565,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "typescript": { |     "typescript": { | ||||||
|       "version": "3.9.10", |       "version": "4.3.3", | ||||||
|       "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", |       "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz", | ||||||
|       "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", |       "integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==", | ||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "universalify": { |     "universalify": { | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "setup-go", |   "name": "setup-go", | ||||||
|   "version": "1.0.0", |   "version": "3.3.0", | ||||||
|   "private": true, |   "private": true, | ||||||
|   "description": "setup go action", |   "description": "setup go action", | ||||||
|   "main": "lib/setup-go.js", |   "main": "lib/setup-go.js", | ||||||
| @@ -24,7 +24,7 @@ | |||||||
|   "license": "MIT", |   "license": "MIT", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "@actions/cache": "^3.0.0", |     "@actions/cache": "^3.0.0", | ||||||
|     "@actions/core": "^1.6.0", |     "@actions/core": "^1.10.0", | ||||||
|     "@actions/exec": "^1.1.0", |     "@actions/exec": "^1.1.0", | ||||||
|     "@actions/glob": "^0.2.0", |     "@actions/glob": "^0.2.0", | ||||||
|     "@actions/http-client": "^2.0.1", |     "@actions/http-client": "^2.0.1", | ||||||
| @@ -42,6 +42,6 @@ | |||||||
|     "nock": "^10.0.6", |     "nock": "^10.0.6", | ||||||
|     "prettier": "^1.17.1", |     "prettier": "^1.17.1", | ||||||
|     "ts-jest": "^27.0.5", |     "ts-jest": "^27.0.5", | ||||||
|     "typescript": "^3.8.3" |     "typescript": "^4.3.3" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,12 +9,12 @@ import {PackageManagerInfo} from './package-managers'; | |||||||
| import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; | import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; | ||||||
|  |  | ||||||
| export const restoreCache = async ( | export const restoreCache = async ( | ||||||
|  |   versionSpec: string, | ||||||
|   packageManager: string, |   packageManager: string, | ||||||
|   cacheDependencyPath?: string |   cacheDependencyPath?: string | ||||||
| ) => { | ) => { | ||||||
|   const packageManagerInfo = await getPackageManagerInfo(packageManager); |   const packageManagerInfo = await getPackageManagerInfo(packageManager); | ||||||
|   const platform = process.env.RUNNER_OS; |   const platform = process.env.RUNNER_OS; | ||||||
|   const versionSpec = core.getInput('go-version'); |  | ||||||
|  |  | ||||||
|   const cachePaths = await getCacheDirectoryPath(packageManagerInfo); |   const cachePaths = await getCacheDirectoryPath(packageManagerInfo); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,7 +16,14 @@ export async function run() { | |||||||
|   try { |   try { | ||||||
|     await cachePackages(); |     await cachePackages(); | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|     core.setFailed(error.message); |     let message = 'Unknown error!'; | ||||||
|  |     if (error instanceof Error) { | ||||||
|  |       message = error.message; | ||||||
|  |     } | ||||||
|  |     if (typeof error === 'string') { | ||||||
|  |       message = error; | ||||||
|  |     } | ||||||
|  |     core.setFailed(message); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -40,7 +47,8 @@ const cachePackages = async () => { | |||||||
|   ); |   ); | ||||||
|  |  | ||||||
|   if (nonExistingPaths.length === cachePaths.length) { |   if (nonExistingPaths.length === cachePaths.length) { | ||||||
|     throw new Error(`There are no cache folders on the disk`); |     core.warning('There are no cache folders on the disk'); | ||||||
|  |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (nonExistingPaths.length) { |   if (nonExistingPaths.length) { | ||||||
| @@ -65,7 +73,7 @@ const cachePackages = async () => { | |||||||
|   core.info(`Cache saved with the key: ${primaryKey}`); |   core.info(`Cache saved with the key: ${primaryKey}`); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export function logWarning(message: string): void { | function logWarning(message: string): void { | ||||||
|   const warningPrefix = '[warning]'; |   const warningPrefix = '[warning]'; | ||||||
|   core.info(`${warningPrefix}${message}`); |   core.info(`${warningPrefix}${message}`); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										132
									
								
								src/installer.ts
									
									
									
									
									
								
							
							
						
						
									
										132
									
								
								src/installer.ts
									
									
									
									
									
								
							| @@ -6,6 +6,7 @@ import * as httpm from '@actions/http-client'; | |||||||
| import * as sys from './system'; | import * as sys from './system'; | ||||||
| import fs from 'fs'; | import fs from 'fs'; | ||||||
| import os from 'os'; | import os from 'os'; | ||||||
|  | import {StableReleaseAlias} from './utils'; | ||||||
|  |  | ||||||
| type InstallationType = 'dist' | 'manifest'; | type InstallationType = 'dist' | 'manifest'; | ||||||
|  |  | ||||||
| @@ -35,15 +36,43 @@ export async function getGo( | |||||||
|   auth: string | undefined, |   auth: string | undefined, | ||||||
|   arch = os.arch() |   arch = os.arch() | ||||||
| ) { | ) { | ||||||
|  |   let manifest: tc.IToolRelease[] | undefined; | ||||||
|   let osPlat: string = os.platform(); |   let osPlat: string = os.platform(); | ||||||
|  |  | ||||||
|  |   if ( | ||||||
|  |     versionSpec === StableReleaseAlias.Stable || | ||||||
|  |     versionSpec === StableReleaseAlias.OldStable | ||||||
|  |   ) { | ||||||
|  |     manifest = await getManifest(auth); | ||||||
|  |     let stableVersion = await resolveStableVersionInput( | ||||||
|  |       versionSpec, | ||||||
|  |       arch, | ||||||
|  |       osPlat, | ||||||
|  |       manifest | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |     if (!stableVersion) { | ||||||
|  |       stableVersion = await resolveStableVersionDist(versionSpec, arch); | ||||||
|  |       if (!stableVersion) { | ||||||
|  |         throw new Error( | ||||||
|  |           `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.` | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     core.info(`${versionSpec} version resolved as ${stableVersion}`); | ||||||
|  |  | ||||||
|  |     versionSpec = stableVersion; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   if (checkLatest) { |   if (checkLatest) { | ||||||
|     core.info('Attempting to resolve the latest version from the manifest...'); |     core.info('Attempting to resolve the latest version from the manifest...'); | ||||||
|     const resolvedVersion = await resolveVersionFromManifest( |     const resolvedVersion = await resolveVersionFromManifest( | ||||||
|       versionSpec, |       versionSpec, | ||||||
|       true, |       true, | ||||||
|       auth, |       auth, | ||||||
|       arch |       arch, | ||||||
|  |       manifest | ||||||
|     ); |     ); | ||||||
|     if (resolvedVersion) { |     if (resolvedVersion) { | ||||||
|       versionSpec = resolvedVersion; |       versionSpec = resolvedVersion; | ||||||
| @@ -69,7 +98,7 @@ export async function getGo( | |||||||
|   // Try download from internal distribution (popular versions only) |   // Try download from internal distribution (popular versions only) | ||||||
|   // |   // | ||||||
|   try { |   try { | ||||||
|     info = await getInfoFromManifest(versionSpec, true, auth, arch); |     info = await getInfoFromManifest(versionSpec, true, auth, arch, manifest); | ||||||
|     if (info) { |     if (info) { | ||||||
|       downloadPath = await installGoVersion(info, auth, arch); |       downloadPath = await installGoVersion(info, auth, arch); | ||||||
|     } else { |     } else { | ||||||
| @@ -118,10 +147,17 @@ async function resolveVersionFromManifest( | |||||||
|   versionSpec: string, |   versionSpec: string, | ||||||
|   stable: boolean, |   stable: boolean, | ||||||
|   auth: string | undefined, |   auth: string | undefined, | ||||||
|   arch: string |   arch: string, | ||||||
|  |   manifest: tc.IToolRelease[] | undefined | ||||||
| ): Promise<string | undefined> { | ): Promise<string | undefined> { | ||||||
|   try { |   try { | ||||||
|     const info = await getInfoFromManifest(versionSpec, stable, auth, arch); |     const info = await getInfoFromManifest( | ||||||
|  |       versionSpec, | ||||||
|  |       stable, | ||||||
|  |       auth, | ||||||
|  |       arch, | ||||||
|  |       manifest | ||||||
|  |     ); | ||||||
|     return info?.resolvedVersion; |     return info?.resolvedVersion; | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     core.info('Unable to resolve a version from the manifest...'); |     core.info('Unable to resolve a version from the manifest...'); | ||||||
| @@ -174,21 +210,26 @@ export async function extractGoArchive(archivePath: string): Promise<string> { | |||||||
|   return extPath; |   return extPath; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export async function getManifest(auth: string | undefined) { | ||||||
|  |   return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main'); | ||||||
|  | } | ||||||
|  |  | ||||||
| export async function getInfoFromManifest( | export async function getInfoFromManifest( | ||||||
|   versionSpec: string, |   versionSpec: string, | ||||||
|   stable: boolean, |   stable: boolean, | ||||||
|   auth: string | undefined, |   auth: string | undefined, | ||||||
|   arch = os.arch() |   arch = os.arch(), | ||||||
|  |   manifest?: tc.IToolRelease[] | undefined | ||||||
| ): Promise<IGoVersionInfo | null> { | ): Promise<IGoVersionInfo | null> { | ||||||
|   let info: IGoVersionInfo | null = null; |   let info: IGoVersionInfo | null = null; | ||||||
|   const releases = await tc.getManifestFromRepo( |   if (!manifest) { | ||||||
|     'actions', |     core.debug('No manifest cached'); | ||||||
|     'go-versions', |     manifest = await getManifest(auth); | ||||||
|     auth, |   } | ||||||
|     'main' |  | ||||||
|   ); |  | ||||||
|   core.info(`matching ${versionSpec}...`); |   core.info(`matching ${versionSpec}...`); | ||||||
|   const rel = await tc.findFromManifest(versionSpec, stable, releases, arch); |  | ||||||
|  |   const rel = await tc.findFromManifest(versionSpec, stable, manifest, arch); | ||||||
|  |  | ||||||
|   if (rel && rel.files.length > 0) { |   if (rel && rel.files.length > 0) { | ||||||
|     info = <IGoVersionInfo>{}; |     info = <IGoVersionInfo>{}; | ||||||
| @@ -316,10 +357,75 @@ export function makeSemver(version: string): string { | |||||||
| export function parseGoVersionFile(versionFilePath: string): string { | export function parseGoVersionFile(versionFilePath: string): string { | ||||||
|   const contents = fs.readFileSync(versionFilePath).toString(); |   const contents = fs.readFileSync(versionFilePath).toString(); | ||||||
|  |  | ||||||
|   if (path.basename(versionFilePath) === 'go.mod') { |   if ( | ||||||
|  |     path.basename(versionFilePath) === 'go.mod' || | ||||||
|  |     path.basename(versionFilePath) === 'go.work' | ||||||
|  |   ) { | ||||||
|     const match = contents.match(/^go (\d+(\.\d+)*)/m); |     const match = contents.match(/^go (\d+(\.\d+)*)/m); | ||||||
|     return match ? match[1] : ''; |     return match ? match[1] : ''; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return contents.trim(); |   return contents.trim(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function resolveStableVersionDist(versionSpec: string, arch: string) { | ||||||
|  |   let archFilter = sys.getArch(arch); | ||||||
|  |   let platFilter = sys.getPlatform(); | ||||||
|  |   const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all'; | ||||||
|  |   let candidates: IGoVersion[] | null = await module.exports.getVersionsDist( | ||||||
|  |     dlUrl | ||||||
|  |   ); | ||||||
|  |   if (!candidates) { | ||||||
|  |     throw new Error(`golang download url did not return results`); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   const fixedCandidates = candidates.map(item => { | ||||||
|  |     return { | ||||||
|  |       ...item, | ||||||
|  |       version: makeSemver(item.version) | ||||||
|  |     }; | ||||||
|  |   }); | ||||||
|  |  | ||||||
|  |   const stableVersion = await resolveStableVersionInput( | ||||||
|  |     versionSpec, | ||||||
|  |     archFilter, | ||||||
|  |     platFilter, | ||||||
|  |     fixedCandidates | ||||||
|  |   ); | ||||||
|  |  | ||||||
|  |   return stableVersion; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export async function resolveStableVersionInput( | ||||||
|  |   versionSpec: string, | ||||||
|  |   arch: string, | ||||||
|  |   platform: string, | ||||||
|  |   manifest: tc.IToolRelease[] | IGoVersion[] | ||||||
|  | ) { | ||||||
|  |   const releases = manifest | ||||||
|  |     .map(item => { | ||||||
|  |       const index = item.files.findIndex( | ||||||
|  |         item => item.arch === arch && item.filename.includes(platform) | ||||||
|  |       ); | ||||||
|  |       if (index === -1) { | ||||||
|  |         return ''; | ||||||
|  |       } | ||||||
|  |       return item.version; | ||||||
|  |     }) | ||||||
|  |     .filter(item => !!item && !semver.prerelease(item)); | ||||||
|  |  | ||||||
|  |   if (versionSpec === StableReleaseAlias.Stable) { | ||||||
|  |     return releases[0]; | ||||||
|  |   } else { | ||||||
|  |     const versions = releases.map( | ||||||
|  |       release => `${semver.major(release)}.${semver.minor(release)}` | ||||||
|  |     ); | ||||||
|  |     const uniqueVersions = Array.from(new Set(versions)); | ||||||
|  |  | ||||||
|  |     const oldstableVersion = releases.find(item => | ||||||
|  |       item.startsWith(uniqueVersions[1]) | ||||||
|  |     ); | ||||||
|  |  | ||||||
|  |     return oldstableVersion; | ||||||
|  |   } | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -4,7 +4,7 @@ import * as installer from './installer'; | |||||||
| import * as semver from 'semver'; | import * as semver from 'semver'; | ||||||
| import path from 'path'; | import path from 'path'; | ||||||
| import {restoreCache} from './cache-restore'; | import {restoreCache} from './cache-restore'; | ||||||
| import {isGhes, isCacheFeatureAvailable} from './cache-utils'; | import {isCacheFeatureAvailable} from './cache-utils'; | ||||||
| import cp from 'child_process'; | import cp from 'child_process'; | ||||||
| import fs from 'fs'; | import fs from 'fs'; | ||||||
| import os from 'os'; | import os from 'os'; | ||||||
| @@ -28,9 +28,10 @@ export async function run() { | |||||||
|  |  | ||||||
|     if (versionSpec) { |     if (versionSpec) { | ||||||
|       let token = core.getInput('token'); |       let token = core.getInput('token'); | ||||||
|       let auth = !token || isGhes() ? undefined : `token ${token}`; |       let auth = !token ? undefined : `token ${token}`; | ||||||
|  |  | ||||||
|       const checkLatest = core.getBooleanInput('check-latest'); |       const checkLatest = core.getBooleanInput('check-latest'); | ||||||
|  |  | ||||||
|       const installDir = await installer.getGo( |       const installDir = await installer.getGo( | ||||||
|         versionSpec, |         versionSpec, | ||||||
|         checkLatest, |         checkLatest, | ||||||
| @@ -38,10 +39,12 @@ export async function run() { | |||||||
|         arch |         arch | ||||||
|       ); |       ); | ||||||
|  |  | ||||||
|  |       const installDirVersion = path.basename(path.dirname(installDir)); | ||||||
|  |  | ||||||
|       core.addPath(path.join(installDir, 'bin')); |       core.addPath(path.join(installDir, 'bin')); | ||||||
|       core.info('Added go to the path'); |       core.info('Added go to the path'); | ||||||
|  |  | ||||||
|       const version = installer.makeSemver(versionSpec); |       const version = installer.makeSemver(installDirVersion); | ||||||
|       // Go versions less than 1.9 require GOROOT to be set |       // Go versions less than 1.9 require GOROOT to be set | ||||||
|       if (semver.lt(version, '1.9.0')) { |       if (semver.lt(version, '1.9.0')) { | ||||||
|         core.info('Setting GOROOT for Go version < 1.9'); |         core.info('Setting GOROOT for Go version < 1.9'); | ||||||
| @@ -56,7 +59,7 @@ export async function run() { | |||||||
|     if (cache && isCacheFeatureAvailable()) { |     if (cache && isCacheFeatureAvailable()) { | ||||||
|       const packageManager = 'default'; |       const packageManager = 'default'; | ||||||
|       const cacheDependencyPath = core.getInput('cache-dependency-path'); |       const cacheDependencyPath = core.getInput('cache-dependency-path'); | ||||||
|       await restoreCache(packageManager, cacheDependencyPath); |       await restoreCache(versionSpec, packageManager, cacheDependencyPath); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // add problem matchers |     // add problem matchers | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								src/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/utils.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | export enum StableReleaseAlias { | ||||||
|  |   Stable = 'stable', | ||||||
|  |   OldStable = 'oldstable' | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user