mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 15:50:33 +00:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d0a58c1c4d | ||
|   | 3dcd9d6eb3 | ||
|   | e983b65a44 | ||
|   | 27b43e1b0d | ||
|   | 7678c83214 | 
| @@ -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 }} | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							| @@ -66,6 +66,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 }} | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								README.md
									
									
									
									
									
								
							| @@ -127,7 +127,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 +169,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) | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								__tests__/data/go.work
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								__tests__/data/go.work
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | go 1.19 | ||||||
|  |  | ||||||
|  | use . | ||||||
| @@ -824,6 +824,12 @@ 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 () => { | ||||||
| @@ -838,6 +844,18 @@ 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(() => true); |       existsSpy.mockImplementation(() => true); | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -63444,7 +63444,8 @@ function makeSemver(version) { | |||||||
| exports.makeSemver = makeSemver; | exports.makeSemver = makeSemver; | ||||||
| function parseGoVersionFile(versionFilePath) { | function parseGoVersionFile(versionFilePath) { | ||||||
|     const contents = fs_1.default.readFileSync(versionFilePath).toString(); |     const contents = fs_1.default.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] : ''; | ||||||
|     } |     } | ||||||
| @@ -63519,7 +63520,7 @@ function run() { | |||||||
|             } |             } | ||||||
|             if (versionSpec) { |             if (versionSpec) { | ||||||
|                 let token = core.getInput('token'); |                 let token = core.getInput('token'); | ||||||
|                 let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; |                 let auth = !token ? undefined : `token ${token}`; | ||||||
|                 const checkLatest = core.getBooleanInput('check-latest'); |                 const checkLatest = core.getBooleanInput('check-latest'); | ||||||
|                 const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch); |                 const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch); | ||||||
|                 core.addPath(path_1.default.join(installDir, 'bin')); |                 core.addPath(path_1.default.join(installDir, 'bin')); | ||||||
|   | |||||||
| @@ -316,7 +316,10 @@ 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] : ''; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ 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( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user