mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 15:50:33 +00:00 
			
		
		
		
	Compare commits
	
		
			31 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | fcdc43634a | ||
|   | 265edc1beb | ||
|   | 193b404f8a | ||
|   | 56a61c9834 | ||
|   | b46db954a1 | ||
|   | 3332358454 | ||
|   | 46eabca1ab | ||
|   | 07948221be | ||
|   | ad70bef2ef | ||
|   | 4a4352b330 | ||
|   | 115d6e6004 | ||
|   | bf7ccf173e | ||
|   | dcb4ec94ce | ||
|   | 341b20ac36 | ||
|   | a5865a93f2 | ||
|   | 13df686579 | ||
|   | 8e9a229830 | ||
|   | 0b4fbc55f6 | ||
|   | acdbc5377c | ||
|   | 3e6475c089 | ||
|   | 65771601ff | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | fcc0174ef2 | ||
|   | 75726802f3 | ||
|   | 0c03929337 | ||
|   | 229eefa42b | ||
|   | 802876f7c7 | ||
|   | 2a34c33bd7 | ||
|   | 83124a14b6 | ||
|   | 9a1626044c | ||
|   | 24c791c06c | ||
|   | ec07be593a | 
							
								
								
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							| @@ -1 +1,2 @@ | ||||
| * text=auto | ||||
| .licenses/** -diff linguist-generated=true | ||||
							
								
								
									
										6
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							| @@ -21,10 +21,10 @@ jobs: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v3 | ||||
|  | ||||
|       - name: Set Node.js 16.x | ||||
|         uses: actions/setup-node@v2 | ||||
|         uses: actions/setup-node@v3 | ||||
|         with: | ||||
|           node-version: 16.x | ||||
|  | ||||
| @@ -44,7 +44,7 @@ jobs: | ||||
|         id: diff | ||||
|  | ||||
|       # If index.js was different than expected, upload the expected version as an artifact | ||||
|       - uses: actions/upload-artifact@v2 | ||||
|       - uses: actions/upload-artifact@v3 | ||||
|         if: ${{ failure() && steps.diff.conclusion == 'failure' }} | ||||
|         with: | ||||
|           name: dist | ||||
|   | ||||
							
								
								
									
										4
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							| @@ -13,9 +13,9 @@ jobs: | ||||
|     runs-on: ubuntu-latest | ||||
|     name: Check licenses | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v3 | ||||
|       - name: Set Node.js 16.x | ||||
|         uses: actions/setup-node@v2 | ||||
|         uses: actions/setup-node@v3 | ||||
|         with: | ||||
|           node-version: 16.x | ||||
|       - run: npm ci | ||||
|   | ||||
							
								
								
									
										24
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								.github/workflows/versions.yml
									
									
									
									
										vendored
									
									
								
							| @@ -22,7 +22,7 @@ jobs: | ||||
|         go: [1.12, 1.13, 1.14] | ||||
|     steps: | ||||
|       - name: Checkout | ||||
|         uses: actions/checkout@v2 | ||||
|         uses: actions/checkout@v3 | ||||
|  | ||||
|       - name: setup-go ${{ matrix.go }} | ||||
|         uses: ./ | ||||
| @@ -41,7 +41,7 @@ jobs: | ||||
|         os: [ubuntu-latest, windows-latest, macos-latest] | ||||
|         go-version: [1.16, 1.17] | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v3 | ||||
|       - name: Setup Go and check latest | ||||
|         uses: ./ | ||||
|         with: | ||||
| @@ -50,6 +50,22 @@ jobs: | ||||
|       - name: Verify Go | ||||
|         run: go version | ||||
|  | ||||
|   go-version-file: | ||||
|     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.mod | ||||
|       - name: verify go | ||||
|         run: __tests__/verify-go.sh 1.14 | ||||
|         shell: bash | ||||
|  | ||||
|   setup-versions-from-manifest: | ||||
|     name: Setup ${{ matrix.go }} ${{ matrix.os }} | ||||
|     runs-on: ${{ matrix.os }} | ||||
| @@ -60,7 +76,7 @@ jobs: | ||||
|         go: [1.12.16, 1.13.11, 1.14.3] | ||||
|     steps: | ||||
|       - name: Checkout | ||||
|         uses: actions/checkout@v2 | ||||
|         uses: actions/checkout@v3 | ||||
|  | ||||
|       - name: setup-go ${{ matrix.go }} | ||||
|         uses: ./ | ||||
| @@ -81,7 +97,7 @@ jobs: | ||||
|         go: [1.9, 1.8.6] | ||||
|     steps: | ||||
|       - name: Checkout | ||||
|         uses: actions/checkout@v2 | ||||
|         uses: actions/checkout@v3 | ||||
|  | ||||
|       - name: setup-go ${{ matrix.go }} | ||||
|         uses: ./ | ||||
|   | ||||
							
								
								
									
										4
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							| @@ -17,10 +17,10 @@ jobs: | ||||
|         operating-system: [ubuntu-latest, windows-latest] | ||||
|     steps: | ||||
|       - name: Checkout | ||||
|         uses: actions/checkout@v2 | ||||
|         uses: actions/checkout@v3 | ||||
|  | ||||
|       - name: Setup node 16 | ||||
|         uses: actions/setup-node@v2 | ||||
|         uses: actions/setup-node@v3 | ||||
|         with: | ||||
|           node-version: 16 | ||||
|           cache: npm | ||||
|   | ||||
| @@ -1 +1 @@ | ||||
| * @actions/spark | ||||
| * @actions/actions-service | ||||
|   | ||||
| @@ -55,7 +55,7 @@ a project may be further defined and clarified by project maintainers. | ||||
| ## Enforcement | ||||
| 
 | ||||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||||
| reported by contacting the project team at opensource@github.com. All | ||||
| reported by contacting the project team at opensource+actions/setup-go@github.com. All | ||||
| complaints will be reviewed and investigated and will result in a response that | ||||
| is deemed necessary and appropriate to the circumstances. The project team is | ||||
| obligated to maintain confidentiality with regard to the reporter of an incident. | ||||
							
								
								
									
										101
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,45 +1,63 @@ | ||||
| # setup-go | ||||
|  | ||||
| <p align="left"> | ||||
|   <a href="https://github.com/actions/setup-go/actions"><img alt="GitHub Actions status" src="https://github.com/actions/setup-go/workflows/build-test/badge.svg"></a> | ||||
|  | ||||
|   <a href="https://github.com/actions/setup-go/actions"><img alt="versions status" src="https://github.com/actions/setup-go/workflows/go-versions/badge.svg"></a>   | ||||
| </p> | ||||
| [](https://github.com/actions/setup-go/actions/workflows/workflow.yml) | ||||
| [](https://github.com/actions/setup-go/actions/workflows/versions.yml) | ||||
|  | ||||
| This action sets up a go environment for use in actions by: | ||||
|  | ||||
| - optionally downloading and caching a version of Go by version and adding to PATH | ||||
| - registering problem matchers for error output | ||||
| - Optionally downloading and caching a version of Go by version and adding to `PATH`. | ||||
| - Registering problem matchers for error output. | ||||
|  | ||||
| # V2 | ||||
| # V3 | ||||
|  | ||||
| The V2 offers: | ||||
| - Adds GOBIN to the PATH | ||||
| - Proxy Support | ||||
| - `stable` input  | ||||
| The V3 edition of the action offers: | ||||
|  | ||||
| - Adds `GOBIN` to the `PATH` | ||||
| - Proxy support | ||||
| - Check latest version | ||||
| - 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). | ||||
|  | ||||
| **Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build golang from source code. | ||||
|  | ||||
| Matching by [semver spec](https://github.com/npm/node-semver): | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v2 | ||||
|   - uses: actions/setup-go@v2 | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       go-version: '^1.13.1' # The Go version to download (if necessary) and use. | ||||
|   - run: go version | ||||
| ``` | ||||
|  | ||||
| Matching an unstable pre-release: | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v2 | ||||
|   - uses: actions/setup-go@v2 | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       stable: 'false' | ||||
|       go-version: '1.14.0-rc1' # The Go version to download (if necessary) and use. | ||||
|       go-version: '>=1.17.0' | ||||
|   - run: go version | ||||
| ``` | ||||
|  | ||||
| Matching an unstable pre-release: | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       go-version: '1.18.0-rc.1' # The Go version to download (if necessary) and use. | ||||
|   - run: go version | ||||
| ``` | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       go-version: '1.16.0-beta.1' # The Go version to download (if necessary) and use. | ||||
|   - run: go version | ||||
| ``` | ||||
|  | ||||
| @@ -47,18 +65,19 @@ steps: | ||||
|  | ||||
| See [action.yml](action.yml) | ||||
|  | ||||
| ## Basic: | ||||
| ## Basic | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v2 | ||||
|   - uses: actions/setup-go@v2 | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       go-version: '1.16.1' # The Go version to download (if necessary) and use. | ||||
|   - run: go run hello.go | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ## Check latest version:   | ||||
| ## Check latest version | ||||
|  | ||||
| The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific Go version is always used. | ||||
|  | ||||
| @@ -68,15 +87,31 @@ If `check-latest` is set to `true`, the action first checks if the cached versio | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v2 | ||||
|   - uses: actions/setup-go@v2 | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/setup-go@v3 | ||||
|     with: | ||||
|       go-version: '1.14' | ||||
|       check-latest: true | ||||
|   - run: go run hello.go | ||||
| ``` | ||||
| ## 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. | ||||
|  | ||||
| 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 | ||||
|  | ||||
| ```yaml | ||||
| steps: | ||||
| - uses: actions/checkout@v3 | ||||
| - uses: actions/setup-go@v3 | ||||
|   with: | ||||
|     go-version-file: 'path/to/go.mod' | ||||
| - run: go version | ||||
| ``` | ||||
|  | ||||
| ## Matrix testing | ||||
|  | ||||
| ## Matrix Testing: | ||||
| ```yaml | ||||
| jobs: | ||||
|   build: | ||||
| @@ -86,20 +121,22 @@ jobs: | ||||
|         go: [ '1.14', '1.13' ] | ||||
|     name: Go ${{ matrix.go }} sample | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: actions/checkout@v3 | ||||
|       - name: Setup go | ||||
|         uses: actions/setup-go@v2 | ||||
|         uses: actions/setup-go@v3 | ||||
|         with: | ||||
|           go-version: ${{ matrix.go }} | ||||
|       - run: go run hello.go | ||||
| ``` | ||||
|  | ||||
| ### Supported version syntax | ||||
|  | ||||
| The `go-version` input supports the following syntax: | ||||
|  | ||||
| Specific versions: `1.15`, `1.16.1`, `1.17.0-rc2`, `1.16.0-beta1`   | ||||
| SemVer's version range syntax: `^1.13.1`   | ||||
| For more information about semantic versioning please refer [semver](https://github.com/npm/node-semver) documentation | ||||
| - Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1` | ||||
| - SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1` | ||||
|  | ||||
| For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation. | ||||
|  | ||||
| # License | ||||
|  | ||||
|   | ||||
							
								
								
									
										12
									
								
								__tests__/data/go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								__tests__/data/go.mod
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| module example.com/mymodule | ||||
|  | ||||
| go 1.14 | ||||
|  | ||||
| require ( | ||||
| 	example.com/othermodule v1.2.3 | ||||
| 	example.com/thismodule v1.2.3 | ||||
| 	example.com/thatmodule v1.2.3 | ||||
| ) | ||||
|  | ||||
| replace example.com/thatmodule => ../thatmodule | ||||
| exclude example.com/thismodule v1.3.0 | ||||
| @@ -20,6 +20,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|   let inSpy: jest.SpyInstance; | ||||
|   let getBooleanInputSpy: jest.SpyInstance; | ||||
|   let exportVarSpy: jest.SpyInstance; | ||||
|   let findSpy: jest.SpyInstance; | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let logSpy: jest.SpyInstance; | ||||
| @@ -27,11 +28,12 @@ describe('setup-go', () => { | ||||
|   let platSpy: jest.SpyInstance; | ||||
|   let archSpy: jest.SpyInstance; | ||||
|   let dlSpy: jest.SpyInstance; | ||||
|   let exSpy: jest.SpyInstance; | ||||
|   let extractTarSpy: jest.SpyInstance; | ||||
|   let cacheSpy: jest.SpyInstance; | ||||
|   let dbgSpy: jest.SpyInstance; | ||||
|   let whichSpy: jest.SpyInstance; | ||||
|   let existsSpy: jest.SpyInstance; | ||||
|   let readFileSpy: jest.SpyInstance; | ||||
|   let mkdirpSpy: jest.SpyInstance; | ||||
|   let execSpy: jest.SpyInstance; | ||||
|   let getManifestSpy: jest.SpyInstance; | ||||
| @@ -49,6 +51,7 @@ describe('setup-go', () => { | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|     getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput'); | ||||
|     getBooleanInputSpy.mockImplementation(name => inputs[name]); | ||||
|     exportVarSpy = jest.spyOn(core, 'exportVariable'); | ||||
|  | ||||
|     // node | ||||
|     os = {}; | ||||
| @@ -61,7 +64,7 @@ describe('setup-go', () => { | ||||
|     // @actions/tool-cache | ||||
|     findSpy = jest.spyOn(tc, 'find'); | ||||
|     dlSpy = jest.spyOn(tc, 'downloadTool'); | ||||
|     exSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     extractTarSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||
|     getSpy = jest.spyOn(im, 'getVersionsDist'); | ||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||
| @@ -69,6 +72,7 @@ describe('setup-go', () => { | ||||
|     // io | ||||
|     whichSpy = jest.spyOn(io, 'which'); | ||||
|     existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|     readFileSpy = jest.spyOn(fs, 'readFileSync'); | ||||
|     mkdirpSpy = jest.spyOn(io, 'mkdirP'); | ||||
|  | ||||
|     // gets | ||||
| @@ -103,6 +107,11 @@ describe('setup-go', () => { | ||||
|     jest.restoreAllMocks(); | ||||
|   }, 100000); | ||||
|  | ||||
|   it('can extract the major.minor.patch version from a given Go version string', async () => { | ||||
|     const goVersionOutput = 'go version go1.16.6 darwin/amd64'; | ||||
|     expect(main.parseGoVersion(goVersionOutput)).toBe('1.16.6'); | ||||
|   }); | ||||
|  | ||||
|   it('can find 1.9.7 from manifest on osx', async () => { | ||||
|     os.platform = 'darwin'; | ||||
|     os.arch = 'x64'; | ||||
| @@ -230,6 +239,40 @@ describe('setup-go', () => { | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`); | ||||
|   }); | ||||
|  | ||||
|   it('does not export any variables for Go versions >=1.9', async () => { | ||||
|     inputs['go-version'] = '1.13.0'; | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|  | ||||
|     let vars: {[key: string]: string} = {}; | ||||
|     exportVarSpy.mockImplementation((name: string, val: string) => { | ||||
|       vars[name] = val; | ||||
|     }); | ||||
|  | ||||
|     await main.run(); | ||||
|     expect(vars).toStrictEqual({}); | ||||
|   }); | ||||
|  | ||||
|   it('exports GOROOT for Go versions <1.9', async () => { | ||||
|     inputs['go-version'] = '1.8'; | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize('/cache/go/1.8.0/x64'); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|  | ||||
|     let vars: {[key: string]: string} = {}; | ||||
|     exportVarSpy.mockImplementation((name: string, val: string) => { | ||||
|       vars[name] = val; | ||||
|     }); | ||||
|  | ||||
|     await main.run(); | ||||
|     expect(vars).toStrictEqual({ | ||||
|       GOROOT: toolPath | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   it('finds a version of go already in the cache', async () => { | ||||
|     inputs['go-version'] = '1.13.0'; | ||||
|  | ||||
| @@ -271,14 +314,14 @@ describe('setup-go', () => { | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     dlSpy.mockImplementation(() => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/go/1.13.0/x64'); | ||||
|     exSpy.mockImplementation(() => '/some/other/temp/path'); | ||||
|     extractTarSpy.mockImplementation(() => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(() => toolPath); | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(extractTarSpy).toHaveBeenCalled(); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
| @@ -313,7 +356,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/go/1.12.16/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
| @@ -321,7 +364,7 @@ describe('setup-go', () => { | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(extractTarSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).not.toHaveBeenCalledWith( | ||||
|       'Not found in manifest.  Falling back to download directly from Go' | ||||
|     ); | ||||
| @@ -350,7 +393,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/go/1.12.17/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
| @@ -358,7 +401,7 @@ describe('setup-go', () => { | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(extractTarSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).not.toHaveBeenCalledWith( | ||||
|       'Not found in manifest.  Falling back to download directly from Go' | ||||
|     ); | ||||
| @@ -387,7 +430,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/go/1.12.14/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
| @@ -398,7 +441,7 @@ describe('setup-go', () => { | ||||
|     expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...'); | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...'); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(extractTarSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       'Not found in manifest.  Falling back to download directly from Go' | ||||
|     ); | ||||
| @@ -600,7 +643,7 @@ describe('setup-go', () => { | ||||
|       const toolPath = path.normalize('/cache/go/1.16.1/x64'); | ||||
|       findSpy.mockReturnValue(toolPath); | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
| @@ -622,7 +665,7 @@ describe('setup-go', () => { | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       const toolPath = path.normalize('/cache/go/1.17.5/x64'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       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'; | ||||
| @@ -643,7 +686,7 @@ describe('setup-go', () => { | ||||
|       expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('Added go to the path'); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Successfully setup go version ${versionSpec}` | ||||
|         `Successfully set up Go version ${versionSpec}` | ||||
|       ); | ||||
|     }); | ||||
|  | ||||
| @@ -663,7 +706,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       let toolPath = path.normalize('/cache/go/1.13.7/x64'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
| @@ -671,7 +714,7 @@ describe('setup-go', () => { | ||||
|       let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|       expect(dlSpy).toHaveBeenCalled(); | ||||
|       expect(exSpy).toHaveBeenCalled(); | ||||
|       expect(extractTarSpy).toHaveBeenCalled(); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         'Attempting to resolve the latest version from the manifest...' | ||||
|       ); | ||||
| @@ -705,7 +748,7 @@ describe('setup-go', () => { | ||||
|  | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       let toolPath = path.normalize('/cache/go/1.13.7/x64'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
| @@ -716,7 +759,7 @@ describe('setup-go', () => { | ||||
|         `Failed to resolve version ${versionSpec} from manifest` | ||||
|       ); | ||||
|       expect(dlSpy).toHaveBeenCalled(); | ||||
|       expect(exSpy).toHaveBeenCalled(); | ||||
|       expect(extractTarSpy).toHaveBeenCalled(); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         'Attempting to resolve the latest version from the manifest...' | ||||
|       ); | ||||
| @@ -733,4 +776,68 @@ describe('setup-go', () => { | ||||
|       expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   describe('go-version-file', () => { | ||||
|     const goModContents = `module example.com/mymodule | ||||
|  | ||||
| go 1.14 | ||||
|  | ||||
| require ( | ||||
| 	example.com/othermodule v1.2.3 | ||||
| 	example.com/thismodule v1.2.3 | ||||
| 	example.com/thatmodule v1.2.3 | ||||
| ) | ||||
|  | ||||
| replace example.com/thatmodule => ../thatmodule | ||||
| exclude example.com/thismodule v1.3.0 | ||||
| `; | ||||
|  | ||||
|     it('reads version from go.mod', async () => { | ||||
|       inputs['go-version-file'] = 'go.mod'; | ||||
|       existsSpy.mockImplementation(path => true); | ||||
|       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('matching 1.14...'); | ||||
|     }); | ||||
|  | ||||
|     it('reads version from .go-version', async () => { | ||||
|       inputs['go-version-file'] = '.go-version'; | ||||
|       existsSpy.mockImplementation(path => true); | ||||
|       readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`)); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.0'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.0...'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('matching 1.13.0...'); | ||||
|     }); | ||||
|  | ||||
|     it('is overwritten by go-version', async () => { | ||||
|       inputs['go-version'] = '1.13.1'; | ||||
|       inputs['go-version-file'] = 'go.mod'; | ||||
|       existsSpy.mockImplementation(path => true); | ||||
|       readFileSpy.mockImplementation(() => Buffer.from(goModContents)); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.1'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.1...'); | ||||
|       expect(logSpy).toHaveBeenCalledWith('matching 1.13.1...'); | ||||
|     }); | ||||
|  | ||||
|     it('reports a read failure', async () => { | ||||
|       inputs['go-version-file'] = 'go.mod'; | ||||
|       existsSpy.mockImplementation(path => false); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::error::The specified go version file at: go.mod does not exist${osm.EOL}` | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
|   | ||||
| @@ -4,12 +4,17 @@ author: 'GitHub' | ||||
| inputs: | ||||
|   go-version: | ||||
|     description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' | ||||
|   go-version-file: | ||||
|     description: 'Path to the go.mod file.' | ||||
|   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' | ||||
|     default: false | ||||
|   token: | ||||
|     description: Used to pull node distributions from go-versions.  Since there's a default, this is typically not supplied by the user. | ||||
|     default: ${{ github.token }} | ||||
| outputs: | ||||
|   go-version: | ||||
|     description: 'The installed Go version. Useful when given a version range as input.' | ||||
| runs: | ||||
|   using: 'node16' | ||||
|   main: 'dist/index.js' | ||||
|   | ||||
							
								
								
									
										6950
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6950
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										69
									
								
								docs/adrs/0000-caching-dependencies.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								docs/adrs/0000-caching-dependencies.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| # 0. Caching dependencies | ||||
| Date: 2022-04-13 | ||||
|  | ||||
| Status: Accepted | ||||
|  | ||||
| # Context | ||||
| `actions/setup-go` is the one of the most popular action related to Golang in GitHub Actions. Many customers use it in conjunction with [actions/cache](https://github.com/actions/cache) to speed up dependency installation process.   | ||||
| See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#go---modules). | ||||
|  | ||||
| # Goals & Anti-Goals | ||||
| Integration of caching functionality into `actions/setup-go` action will bring the following benefits for action users: | ||||
| - Decrease the entry threshold for using the cache for Go dependencies and simplify initial configuration | ||||
| - Simplify YAML pipelines because there will be no need for additional steps to enable caching | ||||
| - More users will use cache for Go so more customers will have fast builds! | ||||
|  | ||||
| We don't pursue the goal to provide wide customization of caching in scope of `actions/setup-go` action. The purpose of this integration is covering ~90% of basic use-cases. If user needs flexible customization, we should advice them to use `actions/cache` directly. | ||||
|  | ||||
| # Decision | ||||
| - Add `cache` input parameter to `actions/setup-go`. For now, input will accept the following values:  | ||||
|   - `true` - enable caching for go dependencies | ||||
|   - `false`- disable caching for go dependencies. This value will be set as default value | ||||
| - Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major releases | ||||
| - Action will try to search a go.sum files in the repository and throw error in the scenario that it was not found | ||||
| - The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules) recommends) | ||||
| - The following key cache will be used `${{ runner.os }}-go${{ go-version }}-${{ hashFiles('<go.sum-path>') }}` | ||||
| - Action will cache global cache from the `go env GOMODCACHE` and `go env GOCACHE` commands. | ||||
| - Add a `cache-dependency-path` input parameter to `actions/setup-go`. The new input will accept an array or regex of dependency files. The field will accept a path (relative to the repository root) to dependency files. If the provided path contains wildcards, the action will search all matching files and calculate a common hash like the ${{ hashFiles('**/go.sum') }} YAML construction does. | ||||
|  | ||||
| # Example of real use-cases | ||||
|  | ||||
|  - With cache | ||||
|  | ||||
| ```yml | ||||
| steps: | ||||
| - uses: actions/checkout@v3 | ||||
| - uses: actions/setup-go@v3 | ||||
|   with: | ||||
|     go-version: '18' | ||||
|     cache: true | ||||
| ``` | ||||
|  | ||||
|  - With cache-dependency-path | ||||
|  | ||||
|  ```yml | ||||
| steps: | ||||
| - uses: actions/checkout@v3 | ||||
| - uses: actions/setup-go@v3 | ||||
|   with: | ||||
|     go-version: '18' | ||||
|     cache: true | ||||
|     cache-dependency-path: **/go.sum | ||||
| ``` | ||||
|  | ||||
|  ```yml | ||||
| steps: | ||||
| - uses: actions/checkout@v3 | ||||
| - uses: actions/setup-go@v3 | ||||
|   with: | ||||
|     go-version: '18' | ||||
|     cache: true | ||||
|     cache-dependency-path: | | ||||
|         **/go.sum | ||||
|         **/go.mod | ||||
| ``` | ||||
|  | ||||
| # Release process | ||||
|  | ||||
| As soon as functionality is implemented, we will release minor update of action. No need to bump major version since there are no breaking changes for existing users. | ||||
| After that, we will update [starter-workflows](https://github.com/actions/starter-workflows/blob/main/ci/go.yml) | ||||
							
								
								
									
										312
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										312
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -19,7 +19,7 @@ | ||||
|         "@types/jest": "^27.0.2", | ||||
|         "@types/node": "^16.11.25", | ||||
|         "@types/semver": "^6.0.0", | ||||
|         "@zeit/ncc": "^0.21.0", | ||||
|         "@vercel/ncc": "^0.33.4", | ||||
|         "jest": "^27.2.5", | ||||
|         "jest-circus": "^27.2.5", | ||||
|         "nock": "^10.0.6", | ||||
| @@ -1070,11 +1070,10 @@ | ||||
|       "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "node_modules/@zeit/ncc": { | ||||
|       "version": "0.21.1", | ||||
|       "resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz", | ||||
|       "integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw==", | ||||
|       "deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.", | ||||
|     "node_modules/@vercel/ncc": { | ||||
|       "version": "0.33.4", | ||||
|       "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz", | ||||
|       "integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==", | ||||
|       "dev": true, | ||||
|       "bin": { | ||||
|         "ncc": "dist/ncc/cli.js" | ||||
| @@ -3335,9 +3334,9 @@ | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/minimist": { | ||||
|       "version": "1.2.5", | ||||
|       "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", | ||||
|       "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", | ||||
|       "version": "1.2.6", | ||||
|       "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", | ||||
|       "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "node_modules/mkdirp": { | ||||
| @@ -4194,145 +4193,6 @@ | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/@jest/types": { | ||||
|       "version": "27.1.0", | ||||
|       "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.1.0.tgz", | ||||
|       "integrity": "sha512-pRP5cLIzN7I7Vp6mHKRSaZD7YpBTK7hawx5si8trMKqk4+WOdK8NEKOTO2G8PKWD1HbKMVckVB6/XHh/olhf2g==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "@types/istanbul-lib-coverage": "^2.0.0", | ||||
|         "@types/istanbul-reports": "^3.0.0", | ||||
|         "@types/node": "*", | ||||
|         "@types/yargs": "^16.0.0", | ||||
|         "chalk": "^4.0.0" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/@types/istanbul-reports": { | ||||
|       "version": "3.0.1", | ||||
|       "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", | ||||
|       "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "@types/istanbul-lib-report": "*" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/@types/yargs": { | ||||
|       "version": "16.0.4", | ||||
|       "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", | ||||
|       "integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "@types/yargs-parser": "*" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/ansi-styles": { | ||||
|       "version": "4.3.0", | ||||
|       "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", | ||||
|       "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "color-convert": "^2.0.1" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": ">=8" | ||||
|       }, | ||||
|       "funding": { | ||||
|         "url": "https://github.com/chalk/ansi-styles?sponsor=1" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/chalk": { | ||||
|       "version": "4.1.2", | ||||
|       "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | ||||
|       "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "ansi-styles": "^4.1.0", | ||||
|         "supports-color": "^7.1.0" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": ">=10" | ||||
|       }, | ||||
|       "funding": { | ||||
|         "url": "https://github.com/chalk/chalk?sponsor=1" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/ci-info": { | ||||
|       "version": "3.2.0", | ||||
|       "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.2.0.tgz", | ||||
|       "integrity": "sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/color-convert": { | ||||
|       "version": "2.0.1", | ||||
|       "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", | ||||
|       "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "color-name": "~1.1.4" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": ">=7.0.0" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/color-name": { | ||||
|       "version": "1.1.4", | ||||
|       "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", | ||||
|       "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/has-flag": { | ||||
|       "version": "4.0.0", | ||||
|       "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", | ||||
|       "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", | ||||
|       "dev": true, | ||||
|       "engines": { | ||||
|         "node": ">=8" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/is-ci": { | ||||
|       "version": "3.0.0", | ||||
|       "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.0.tgz", | ||||
|       "integrity": "sha512-kDXyttuLeslKAHYL/K28F2YkM3x5jvFPEw3yXbRptXydjD9rpLEz+C5K5iutY9ZiUu6AP41JdvRQwF4Iqs4ZCQ==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "ci-info": "^3.1.1" | ||||
|       }, | ||||
|       "bin": { | ||||
|         "is-ci": "bin.js" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/jest-util": { | ||||
|       "version": "27.1.0", | ||||
|       "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-27.1.0.tgz", | ||||
|       "integrity": "sha512-edSLD2OneYDKC6gZM1yc+wY/877s/fuJNoM1k3sOEpzFyeptSmke3SLnk1dDHk9CgTA+58mnfx3ew3J11Kes/w==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "@jest/types": "^27.1.0", | ||||
|         "@types/node": "*", | ||||
|         "chalk": "^4.0.0", | ||||
|         "graceful-fs": "^4.2.4", | ||||
|         "is-ci": "^3.0.0", | ||||
|         "picomatch": "^2.2.3" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/picomatch": { | ||||
|       "version": "2.3.0", | ||||
|       "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", | ||||
|       "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", | ||||
|       "dev": true, | ||||
|       "engines": { | ||||
|         "node": ">=8.6" | ||||
|       }, | ||||
|       "funding": { | ||||
|         "url": "https://github.com/sponsors/jonschlinkert" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/semver": { | ||||
|       "version": "7.3.5", | ||||
|       "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", | ||||
| @@ -4348,27 +4208,6 @@ | ||||
|         "node": ">=10" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/supports-color": { | ||||
|       "version": "7.2.0", | ||||
|       "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", | ||||
|       "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", | ||||
|       "dev": true, | ||||
|       "dependencies": { | ||||
|         "has-flag": "^4.0.0" | ||||
|       }, | ||||
|       "engines": { | ||||
|         "node": ">=8" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/ts-jest/node_modules/yargs-parser": { | ||||
|       "version": "20.2.9", | ||||
|       "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", | ||||
|       "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", | ||||
|       "dev": true, | ||||
|       "engines": { | ||||
|         "node": ">=10" | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/tunnel": { | ||||
|       "version": "0.0.6", | ||||
|       "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", | ||||
| @@ -5524,10 +5363,10 @@ | ||||
|       "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "@zeit/ncc": { | ||||
|       "version": "0.21.1", | ||||
|       "resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz", | ||||
|       "integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw==", | ||||
|     "@vercel/ncc": { | ||||
|       "version": "0.33.4", | ||||
|       "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.33.4.tgz", | ||||
|       "integrity": "sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "abab": { | ||||
| @@ -7241,9 +7080,9 @@ | ||||
|       } | ||||
|     }, | ||||
|     "minimist": { | ||||
|       "version": "1.2.5", | ||||
|       "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", | ||||
|       "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", | ||||
|       "version": "1.2.6", | ||||
|       "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", | ||||
|       "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "mkdirp": { | ||||
| @@ -7878,112 +7717,6 @@ | ||||
|         "yargs-parser": "20.x" | ||||
|       }, | ||||
|       "dependencies": { | ||||
|         "@jest/types": { | ||||
|           "version": "27.1.0", | ||||
|           "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.1.0.tgz", | ||||
|           "integrity": "sha512-pRP5cLIzN7I7Vp6mHKRSaZD7YpBTK7hawx5si8trMKqk4+WOdK8NEKOTO2G8PKWD1HbKMVckVB6/XHh/olhf2g==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "@types/istanbul-lib-coverage": "^2.0.0", | ||||
|             "@types/istanbul-reports": "^3.0.0", | ||||
|             "@types/node": "*", | ||||
|             "@types/yargs": "^16.0.0", | ||||
|             "chalk": "^4.0.0" | ||||
|           } | ||||
|         }, | ||||
|         "@types/istanbul-reports": { | ||||
|           "version": "3.0.1", | ||||
|           "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", | ||||
|           "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "@types/istanbul-lib-report": "*" | ||||
|           } | ||||
|         }, | ||||
|         "@types/yargs": { | ||||
|           "version": "16.0.4", | ||||
|           "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", | ||||
|           "integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "@types/yargs-parser": "*" | ||||
|           } | ||||
|         }, | ||||
|         "ansi-styles": { | ||||
|           "version": "4.3.0", | ||||
|           "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", | ||||
|           "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "color-convert": "^2.0.1" | ||||
|           } | ||||
|         }, | ||||
|         "chalk": { | ||||
|           "version": "4.1.2", | ||||
|           "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | ||||
|           "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "ansi-styles": "^4.1.0", | ||||
|             "supports-color": "^7.1.0" | ||||
|           } | ||||
|         }, | ||||
|         "ci-info": { | ||||
|           "version": "3.2.0", | ||||
|           "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.2.0.tgz", | ||||
|           "integrity": "sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A==", | ||||
|           "dev": true | ||||
|         }, | ||||
|         "color-convert": { | ||||
|           "version": "2.0.1", | ||||
|           "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", | ||||
|           "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "color-name": "~1.1.4" | ||||
|           } | ||||
|         }, | ||||
|         "color-name": { | ||||
|           "version": "1.1.4", | ||||
|           "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", | ||||
|           "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", | ||||
|           "dev": true | ||||
|         }, | ||||
|         "has-flag": { | ||||
|           "version": "4.0.0", | ||||
|           "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", | ||||
|           "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", | ||||
|           "dev": true | ||||
|         }, | ||||
|         "is-ci": { | ||||
|           "version": "3.0.0", | ||||
|           "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.0.tgz", | ||||
|           "integrity": "sha512-kDXyttuLeslKAHYL/K28F2YkM3x5jvFPEw3yXbRptXydjD9rpLEz+C5K5iutY9ZiUu6AP41JdvRQwF4Iqs4ZCQ==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "ci-info": "^3.1.1" | ||||
|           } | ||||
|         }, | ||||
|         "jest-util": { | ||||
|           "version": "27.1.0", | ||||
|           "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-27.1.0.tgz", | ||||
|           "integrity": "sha512-edSLD2OneYDKC6gZM1yc+wY/877s/fuJNoM1k3sOEpzFyeptSmke3SLnk1dDHk9CgTA+58mnfx3ew3J11Kes/w==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "@jest/types": "^27.1.0", | ||||
|             "@types/node": "*", | ||||
|             "chalk": "^4.0.0", | ||||
|             "graceful-fs": "^4.2.4", | ||||
|             "is-ci": "^3.0.0", | ||||
|             "picomatch": "^2.2.3" | ||||
|           } | ||||
|         }, | ||||
|         "picomatch": { | ||||
|           "version": "2.3.0", | ||||
|           "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", | ||||
|           "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", | ||||
|           "dev": true | ||||
|         }, | ||||
|         "semver": { | ||||
|           "version": "7.3.5", | ||||
|           "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", | ||||
| @@ -7992,21 +7725,6 @@ | ||||
|           "requires": { | ||||
|             "lru-cache": "^6.0.0" | ||||
|           } | ||||
|         }, | ||||
|         "supports-color": { | ||||
|           "version": "7.2.0", | ||||
|           "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", | ||||
|           "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", | ||||
|           "dev": true, | ||||
|           "requires": { | ||||
|             "has-flag": "^4.0.0" | ||||
|           } | ||||
|         }, | ||||
|         "yargs-parser": { | ||||
|           "version": "20.2.9", | ||||
|           "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", | ||||
|           "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", | ||||
|           "dev": true | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|   | ||||
| @@ -33,7 +33,7 @@ | ||||
|     "@types/jest": "^27.0.2", | ||||
|     "@types/node": "^16.11.25", | ||||
|     "@types/semver": "^6.0.0", | ||||
|     "@zeit/ncc": "^0.21.0", | ||||
|     "@vercel/ncc": "^0.33.4", | ||||
|     "jest": "^27.2.5", | ||||
|     "jest-circus": "^27.2.5", | ||||
|     "nock": "^10.0.6", | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import * as path from 'path'; | ||||
| import * as semver from 'semver'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as sys from './system'; | ||||
| import fs from 'fs'; | ||||
| import os from 'os'; | ||||
|  | ||||
| type InstallationType = 'dist' | 'manifest'; | ||||
| @@ -298,3 +299,14 @@ export function makeSemver(version: string): string { | ||||
|   } | ||||
|   return fullVersion; | ||||
| } | ||||
|  | ||||
| export function parseGoVersionFile(versionFilePath: string): string { | ||||
|   const contents = fs.readFileSync(versionFilePath).toString(); | ||||
|  | ||||
|   if (path.basename(versionFilePath) === 'go.mod') { | ||||
|     const match = contents.match(/^go (\d+(\.\d+)*)/m); | ||||
|     return match ? match[1] : ''; | ||||
|   } | ||||
|  | ||||
|   return contents.trim(); | ||||
| } | ||||
|   | ||||
							
								
								
									
										55
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as installer from './installer'; | ||||
| import * as semver from 'semver'; | ||||
| import path from 'path'; | ||||
| import cp from 'child_process'; | ||||
| import fs from 'fs'; | ||||
| @@ -12,7 +13,7 @@ export async function run() { | ||||
|     // versionSpec is optional.  If supplied, install / use from the tool cache | ||||
|     // If not supplied then problem matchers will still be setup.  Useful for self-hosted. | ||||
|     // | ||||
|     let versionSpec = core.getInput('go-version'); | ||||
|     const versionSpec = resolveVersionInput(); | ||||
|  | ||||
|     core.info(`Setup go version spec ${versionSpec}`); | ||||
|  | ||||
| @@ -23,13 +24,19 @@ export async function run() { | ||||
|       const checkLatest = core.getBooleanInput('check-latest'); | ||||
|       const installDir = await installer.getGo(versionSpec, checkLatest, auth); | ||||
|  | ||||
|       core.exportVariable('GOROOT', installDir); | ||||
|       core.addPath(path.join(installDir, 'bin')); | ||||
|       core.info('Added go to the path'); | ||||
|  | ||||
|       const version = installer.makeSemver(versionSpec); | ||||
|       // Go versions less than 1.9 require GOROOT to be set | ||||
|       if (semver.lt(version, '1.9.0')) { | ||||
|         core.info('Setting GOROOT for Go version < 1.9'); | ||||
|         core.exportVariable('GOROOT', installDir); | ||||
|       } | ||||
|  | ||||
|       let added = await addBinToPath(); | ||||
|       core.debug(`add bin ${added}`); | ||||
|       core.info(`Successfully setup go version ${versionSpec}`); | ||||
|       core.info(`Successfully set up Go version ${versionSpec}`); | ||||
|     } | ||||
|  | ||||
|     // add problem matchers | ||||
| @@ -41,6 +48,8 @@ export async function run() { | ||||
|     let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); | ||||
|     core.info(goVersion); | ||||
|  | ||||
|     core.setOutput('go-version', parseGoVersion(goVersion)); | ||||
|  | ||||
|     core.startGroup('go env'); | ||||
|     let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); | ||||
|     core.info(goEnv); | ||||
| @@ -60,19 +69,19 @@ export async function addBinToPath(): Promise<boolean> { | ||||
|   } | ||||
|  | ||||
|   let buf = cp.execSync('go env GOPATH'); | ||||
|   if (buf) { | ||||
|   if (buf.length > 1) { | ||||
|     let gp = buf.toString().trim(); | ||||
|     core.debug(`go env GOPATH :${gp}:`); | ||||
|     if (!fs.existsSync(gp)) { | ||||
|       // some of the hosted images have go install but not profile dir | ||||
|       core.debug(`creating ${gp}`); | ||||
|       io.mkdirP(gp); | ||||
|       await io.mkdirP(gp); | ||||
|     } | ||||
|  | ||||
|     let bp = path.join(gp, 'bin'); | ||||
|     if (!fs.existsSync(bp)) { | ||||
|       core.debug(`creating ${bp}`); | ||||
|       io.mkdirP(bp); | ||||
|       await io.mkdirP(bp); | ||||
|     } | ||||
|  | ||||
|     core.addPath(bp); | ||||
| @@ -87,3 +96,37 @@ function isGhes(): boolean { | ||||
|   ); | ||||
|   return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; | ||||
| } | ||||
|  | ||||
| export function parseGoVersion(versionString: string): string { | ||||
|   // get the installed version as an Action output | ||||
|   // based on go/src/cmd/go/internal/version/version.go: | ||||
|   // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH) | ||||
|   // expecting go<version> for runtime.Version() | ||||
|   return versionString.split(' ')[2].slice('go'.length); | ||||
| } | ||||
|  | ||||
| function resolveVersionInput(): string { | ||||
|   let version = core.getInput('go-version'); | ||||
|   const versionFilePath = core.getInput('go-version-file'); | ||||
|  | ||||
|   if (version && versionFilePath) { | ||||
|     core.warning( | ||||
|       'Both go-version and go-version-file inputs are specified, only go-version will be used' | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   if (version) { | ||||
|     return version; | ||||
|   } | ||||
|  | ||||
|   if (versionFilePath) { | ||||
|     if (!fs.existsSync(versionFilePath)) { | ||||
|       throw new Error( | ||||
|         `The specified go version file at: ${versionFilePath} does not exist` | ||||
|       ); | ||||
|     } | ||||
|     version = installer.parseGoVersionFile(versionFilePath); | ||||
|   } | ||||
|  | ||||
|   return version; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user