Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'go-version' Output #85

Merged
merged 2 commits into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/setup-go.test.ts
Expand Up @@ -105,6 +105,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';
Expand Down
5 changes: 4 additions & 1 deletion action.yml
@@ -1,7 +1,7 @@
name: 'Setup Go environment'
description: 'Setup a Go environment and add it to the PATH'
author: 'GitHub'
inputs:
inputs:
go-version:
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
check-latest:
Expand All @@ -10,6 +10,9 @@ inputs:
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'
11 changes: 10 additions & 1 deletion dist/index.js
Expand Up @@ -2058,7 +2058,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
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 io = __importStar(__webpack_require__(1));
const installer = __importStar(__webpack_require__(749));
Expand Down Expand Up @@ -2100,6 +2100,7 @@ function run() {
let goPath = yield io.which('go');
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
core.info(goVersion);
core.setOutput('go-version', parseGoVersion(goVersion));
core.startGroup('go env');
let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString();
core.info(goEnv);
Expand Down Expand Up @@ -2145,6 +2146,14 @@ function isGhes() {
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://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

/***/ }),
Expand Down
10 changes: 10 additions & 0 deletions src/main.ts
Expand Up @@ -48,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);
Expand Down Expand Up @@ -94,3 +96,11 @@ 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);
}