Skip to content

Commit cd176c6

Browse files
author
Danny McCormick
committed
Add setup-go
0 parents  commit cd176c6

File tree

196 files changed

+19403
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+19403
-0
lines changed

.github/main.workflow

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on: push
2+
jobs:
3+
build:
4+
runs-on:
5+
pool: ${{ matrix.operating-system }}
6+
strategy:
7+
matrix:
8+
operating-system: [Linux, macOS, Windows]
9+
actions:
10+
- name: Set Node.js 10.x
11+
uses: bryanmacfarlane/node-config@master
12+
with:
13+
version: 10.x
14+
15+
- name: npm install
16+
# Explicitly uninstall husky so that we avoid issues with git hooks/node versioning.
17+
# Should switch to clean checkout instead when supported.
18+
run: npm prune --production && npm install && npm uninstall husky
19+
20+
- name: Lint
21+
run: npm run format-check
22+
23+
- name: npm test
24+
run: npm test

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# runtime dependencies are checked in
2+
# dev dependencies are *not* checked in
3+
node_modules/.bin
4+
node_modules/typescript
5+
node_modules/@types
6+
node_modules/prettier
7+
__tests__/runner/*

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid",
10+
"parser": "typescript"
11+
}

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018 GitHub, Inc. and contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# @actions/setup-go
2+
3+
This action sets by Go environment for use in actions by:
4+
5+
- optionally downloading and caching a version of Go
6+
- TODO: registering problem matchers for error output
7+
- TODO: configuring proxy if the runner is configured to use a proxy (coming with private runners)
8+
9+
# License
10+
11+
The scripts and documentation in this project are released under the [MIT License](LICENSE)
12+
13+
# Contributions
14+
15+
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)

__tests__/installer.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import io = require('@actions/io');
2+
import fs = require('fs');
3+
import os = require('os');
4+
import path = require('path');
5+
6+
const toolDir = path.join(__dirname, 'runner', 'tools');
7+
const tempDir = path.join(__dirname, 'runner', 'temp');
8+
9+
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
10+
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
11+
import * as installer from '../src/installer';
12+
13+
describe('installer tests', () => {
14+
beforeAll(() => {});
15+
beforeAll(async () => {
16+
await io.rmRF(toolDir);
17+
await io.rmRF(tempDir);
18+
});
19+
20+
it('TODO - Add tests', async () => {});
21+
});

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Setup Node.js for use with actions'
2+
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
3+
author: 'GitHub'
4+
inputs:
5+
version:
6+
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
7+
default: '10.x'
8+
runs:
9+
using: 'node'
10+
main: 'lib/setup-node.js'

docs/contributors.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Contributors
2+
3+
4+
# Checkin
5+
6+
- Do checkin source (src)
7+
- Do checkin build output (lib)
8+
- Do checkin runtime node_modules
9+
- Do not checkin
10+
11+
# Adding a dev dependency
12+
13+
Remember to update .gitignore.
14+
15+
# Updating toolkit dependency
16+
17+
Until released publically, update tgz packages in toolkit

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
clearMocks: true,
3+
moduleFileExtensions: ['js', 'ts'],
4+
testEnvironment: 'node',
5+
testMatch: ['**/*.test.ts'],
6+
testRunner: 'jest-circus/runner',
7+
transform: {
8+
'^.+\\.ts$': 'ts-jest'
9+
},
10+
verbose: true
11+
}

lib/installer.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
var __importStar = (this && this.__importStar) || function (mod) {
11+
if (mod && mod.__esModule) return mod;
12+
var result = {};
13+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
14+
result["default"] = mod;
15+
return result;
16+
};
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
// Load tempDirectory before it gets wiped by tool-cache
19+
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
20+
const core = __importStar(require("@actions/core"));
21+
const tc = __importStar(require("@actions/tool-cache"));
22+
const os = __importStar(require("os"));
23+
const path = __importStar(require("path"));
24+
const util = __importStar(require("util"));
25+
let osPlat = os.platform();
26+
let osArch = os.arch();
27+
if (!tempDirectory) {
28+
let baseLocation;
29+
if (process.platform === 'win32') {
30+
// On windows use the USERPROFILE env variable
31+
baseLocation = process.env['USERPROFILE'] || 'C:\\';
32+
}
33+
else {
34+
if (process.platform === 'darwin') {
35+
baseLocation = '/Users';
36+
}
37+
else {
38+
baseLocation = '/home';
39+
}
40+
}
41+
tempDirectory = path.join(baseLocation, 'actions', 'temp');
42+
}
43+
function getGo(version) {
44+
return __awaiter(this, void 0, void 0, function* () {
45+
// check cache
46+
let toolPath;
47+
toolPath = tc.find('go', normalizeVersion(version));
48+
if (!toolPath) {
49+
// download, extract, cache
50+
toolPath = yield acquireGo(version);
51+
core.debug("Go tool is cached under " + toolPath);
52+
}
53+
setGoEnvironmentVariables(toolPath);
54+
toolPath = path.join(toolPath, 'bin');
55+
//
56+
// prepend the tools path. instructs the agent to prepend for future tasks
57+
//
58+
core.addPath(toolPath);
59+
});
60+
}
61+
exports.getGo = getGo;
62+
function acquireGo(version) {
63+
return __awaiter(this, void 0, void 0, function* () {
64+
//
65+
// Download - a tool installer intimately knows how to get the tool (and construct urls)
66+
//
67+
let fileName = getFileName(version);
68+
let downloadUrl = getDownloadUrl(fileName);
69+
let downloadPath = null;
70+
try {
71+
downloadPath = yield tc.downloadTool(downloadUrl);
72+
}
73+
catch (error) {
74+
core.debug(error);
75+
throw (`Failed to download version ${version}: ${error}`);
76+
}
77+
//
78+
// Extract
79+
//
80+
let extPath = tempDirectory;
81+
if (!extPath) {
82+
throw new Error('Temp directory not set');
83+
}
84+
if (osPlat == 'win32') {
85+
extPath = yield tc.extractZip(downloadPath);
86+
}
87+
else {
88+
extPath = yield tc.extractTar(downloadPath);
89+
}
90+
//
91+
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
92+
//
93+
const toolRoot = path.join(extPath, "go");
94+
version = normalizeVersion(version);
95+
return yield tc.cacheDir(toolRoot, 'go', version);
96+
});
97+
}
98+
function getFileName(version) {
99+
const platform = osPlat == "win32" ? "windows" : osPlat;
100+
const arch = osArch == "x64" ? "amd64" : "386";
101+
const ext = osPlat == "win32" ? "zip" : "tar.gz";
102+
const filename = util.format("go%s.%s-%s.%s", version, platform, arch, ext);
103+
return filename;
104+
}
105+
function getDownloadUrl(filename) {
106+
return util.format("https://storage.googleapis.com/golang/%s", filename);
107+
}
108+
function setGoEnvironmentVariables(goRoot) {
109+
core.exportVariable('GOROOT', goRoot);
110+
const goPath = process.env['GOPATH'] || '';
111+
const goBin = process.env['GOBIN'] || '';
112+
// set GOPATH and GOBIN as user value
113+
if (!util.isNullOrUndefined(goPath)) {
114+
core.exportVariable("GOPATH", goPath);
115+
}
116+
if (!util.isNullOrUndefined(goBin)) {
117+
core.exportVariable("GOBIN", goBin);
118+
}
119+
}
120+
// This function is required to convert the version 1.10 to 1.10.0.
121+
// Because caching utility accept only sementic version,
122+
// which have patch number as well.
123+
function normalizeVersion(version) {
124+
const versionPart = version.split(".");
125+
if (versionPart[1] == null) {
126+
//append minor and patch version if not available
127+
return version.concat(".0.0");
128+
}
129+
else if (versionPart[2] == null) {
130+
//append patch version if not available
131+
return version.concat(".0");
132+
}
133+
return version;
134+
}

0 commit comments

Comments
 (0)