mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 23:33:42 +00:00 
			
		
		
		
	Add 'go-version' Output (#85)
* Add go-version to action outputs This provides the semver version of Go that has been installed. This is useful if only a major or minor version has been provided as the input go-version value. * Convert version extraction to a function Simplify how the version is extracted and add a simple test at the same time. Co-authored-by: Peter Mescalchin <peter@magnetikonline.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> Co-authored-by: Peter Mescalchin <peter@magnetikonline.com> Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									115d6e6004
								
							
						
					
					
						commit
						4a4352b330
					
				| @ -105,6 +105,11 @@ describe('setup-go', () => { | |||||||
|     jest.restoreAllMocks(); |     jest.restoreAllMocks(); | ||||||
|   }, 100000); |   }, 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 () => { |   it('can find 1.9.7 from manifest on osx', async () => { | ||||||
|     os.platform = 'darwin'; |     os.platform = 'darwin'; | ||||||
|     os.arch = 'x64'; |     os.arch = 'x64'; | ||||||
|  | |||||||
| @ -10,6 +10,9 @@ inputs: | |||||||
|   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. | ||||||
|     default: ${{ github.token }} |     default: ${{ github.token }} | ||||||
|  | outputs: | ||||||
|  |   go-version: | ||||||
|  |     description: 'The installed Go version. Useful when given a version range as input.' | ||||||
| runs: | runs: | ||||||
|   using: 'node16' |   using: 'node16' | ||||||
|   main: 'dist/index.js' |   main: 'dist/index.js' | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @ -2058,7 +2058,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | |||||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; |     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||||
| }; | }; | ||||||
| Object.defineProperty(exports, "__esModule", { value: true }); | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
| exports.addBinToPath = exports.run = void 0; | exports.parseGoVersion = exports.addBinToPath = exports.run = void 0; | ||||||
| const core = __importStar(__webpack_require__(470)); | const core = __importStar(__webpack_require__(470)); | ||||||
| const io = __importStar(__webpack_require__(1)); | const io = __importStar(__webpack_require__(1)); | ||||||
| const installer = __importStar(__webpack_require__(749)); | const installer = __importStar(__webpack_require__(749)); | ||||||
| @ -2100,6 +2100,7 @@ function run() { | |||||||
|             let goPath = yield io.which('go'); |             let goPath = yield io.which('go'); | ||||||
|             let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); |             let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); | ||||||
|             core.info(goVersion); |             core.info(goVersion); | ||||||
|  |             core.setOutput('go-version', parseGoVersion(goVersion)); | ||||||
|             core.startGroup('go env'); |             core.startGroup('go env'); | ||||||
|             let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); |             let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); | ||||||
|             core.info(goEnv); |             core.info(goEnv); | ||||||
| @ -2145,6 +2146,14 @@ function isGhes() { | |||||||
|     const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); |     const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); | ||||||
|     return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; |     return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; | ||||||
| } | } | ||||||
|  | function parseGoVersion(versionString) { | ||||||
|  |     // 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); | ||||||
|  | } | ||||||
|  | exports.parseGoVersion = parseGoVersion; | ||||||
| //# sourceMappingURL=main.js.map
 | //# sourceMappingURL=main.js.map
 | ||||||
| 
 | 
 | ||||||
| /***/ }), | /***/ }), | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -48,6 +48,8 @@ export async function run() { | |||||||
|     let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); |     let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); | ||||||
|     core.info(goVersion); |     core.info(goVersion); | ||||||
| 
 | 
 | ||||||
|  |     core.setOutput('go-version', parseGoVersion(goVersion)); | ||||||
|  | 
 | ||||||
|     core.startGroup('go env'); |     core.startGroup('go env'); | ||||||
|     let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); |     let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); | ||||||
|     core.info(goEnv); |     core.info(goEnv); | ||||||
| @ -94,3 +96,11 @@ function isGhes(): boolean { | |||||||
|   ); |   ); | ||||||
|   return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; |   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); | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user