Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add setup-go
- Loading branch information
Danny McCormick
committed
Jun 19, 2019
0 parents
commit cd176c6
Showing
196 changed files
with
19,403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
on: push | ||
jobs: | ||
build: | ||
runs-on: | ||
pool: ${{ matrix.operating-system }} | ||
strategy: | ||
matrix: | ||
operating-system: [Linux, macOS, Windows] | ||
actions: | ||
- name: Set Node.js 10.x | ||
uses: bryanmacfarlane/node-config@master | ||
with: | ||
version: 10.x | ||
|
||
- name: npm install | ||
# Explicitly uninstall husky so that we avoid issues with git hooks/node versioning. | ||
# Should switch to clean checkout instead when supported. | ||
run: npm prune --production && npm install && npm uninstall husky | ||
|
||
- name: Lint | ||
run: npm run format-check | ||
|
||
- name: npm test | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# runtime dependencies are checked in | ||
# dev dependencies are *not* checked in | ||
node_modules/.bin | ||
node_modules/typescript | ||
node_modules/@types | ||
node_modules/prettier | ||
__tests__/runner/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": false, | ||
"arrowParens": "avoid", | ||
"parser": "typescript" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 GitHub, Inc. and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# @actions/setup-go | ||
|
||
This action sets by Go environment for use in actions by: | ||
|
||
- optionally downloading and caching a version of Go | ||
- TODO: registering problem matchers for error output | ||
- TODO: configuring proxy if the runner is configured to use a proxy (coming with private runners) | ||
|
||
# License | ||
|
||
The scripts and documentation in this project are released under the [MIT License](LICENSE) | ||
|
||
# Contributions | ||
|
||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import io = require('@actions/io'); | ||
import fs = require('fs'); | ||
import os = require('os'); | ||
import path = require('path'); | ||
|
||
const toolDir = path.join(__dirname, 'runner', 'tools'); | ||
const tempDir = path.join(__dirname, 'runner', 'temp'); | ||
|
||
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir; | ||
process.env['RUNNER_TEMPDIRECTORY'] = tempDir; | ||
import * as installer from '../src/installer'; | ||
|
||
describe('installer tests', () => { | ||
beforeAll(() => {}); | ||
beforeAll(async () => { | ||
await io.rmRF(toolDir); | ||
await io.rmRF(tempDir); | ||
}); | ||
|
||
it('TODO - Add tests', async () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: 'Setup Node.js for use with actions' | ||
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support' | ||
author: 'GitHub' | ||
inputs: | ||
version: | ||
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0' | ||
default: '10.x' | ||
runs: | ||
using: 'node' | ||
main: 'lib/setup-node.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Contributors | ||
|
||
|
||
# Checkin | ||
|
||
- Do checkin source (src) | ||
- Do checkin build output (lib) | ||
- Do checkin runtime node_modules | ||
- Do not checkin | ||
|
||
# Adding a dev dependency | ||
|
||
Remember to update .gitignore. | ||
|
||
# Updating toolkit dependency | ||
|
||
Until released publically, update tgz packages in toolkit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
moduleFileExtensions: ['js', 'ts'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
testRunner: 'jest-circus/runner', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
verbose: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Load tempDirectory before it gets wiped by tool-cache | ||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; | ||
const core = __importStar(require("@actions/core")); | ||
const tc = __importStar(require("@actions/tool-cache")); | ||
const os = __importStar(require("os")); | ||
const path = __importStar(require("path")); | ||
const util = __importStar(require("util")); | ||
let osPlat = os.platform(); | ||
let osArch = os.arch(); | ||
if (!tempDirectory) { | ||
let baseLocation; | ||
if (process.platform === 'win32') { | ||
// On windows use the USERPROFILE env variable | ||
baseLocation = process.env['USERPROFILE'] || 'C:\\'; | ||
} | ||
else { | ||
if (process.platform === 'darwin') { | ||
baseLocation = '/Users'; | ||
} | ||
else { | ||
baseLocation = '/home'; | ||
} | ||
} | ||
tempDirectory = path.join(baseLocation, 'actions', 'temp'); | ||
} | ||
function getGo(version) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// check cache | ||
let toolPath; | ||
toolPath = tc.find('go', normalizeVersion(version)); | ||
if (!toolPath) { | ||
// download, extract, cache | ||
toolPath = yield acquireGo(version); | ||
core.debug("Go tool is cached under " + toolPath); | ||
} | ||
setGoEnvironmentVariables(toolPath); | ||
toolPath = path.join(toolPath, 'bin'); | ||
// | ||
// prepend the tools path. instructs the agent to prepend for future tasks | ||
// | ||
core.addPath(toolPath); | ||
}); | ||
} | ||
exports.getGo = getGo; | ||
function acquireGo(version) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// | ||
// Download - a tool installer intimately knows how to get the tool (and construct urls) | ||
// | ||
let fileName = getFileName(version); | ||
let downloadUrl = getDownloadUrl(fileName); | ||
let downloadPath = null; | ||
try { | ||
downloadPath = yield tc.downloadTool(downloadUrl); | ||
} | ||
catch (error) { | ||
core.debug(error); | ||
throw (`Failed to download version ${version}: ${error}`); | ||
} | ||
// | ||
// Extract | ||
// | ||
let extPath = tempDirectory; | ||
if (!extPath) { | ||
throw new Error('Temp directory not set'); | ||
} | ||
if (osPlat == 'win32') { | ||
extPath = yield tc.extractZip(downloadPath); | ||
} | ||
else { | ||
extPath = yield tc.extractTar(downloadPath); | ||
} | ||
// | ||
// Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded | ||
// | ||
const toolRoot = path.join(extPath, "go"); | ||
version = normalizeVersion(version); | ||
return yield tc.cacheDir(toolRoot, 'go', version); | ||
}); | ||
} | ||
function getFileName(version) { | ||
const platform = osPlat == "win32" ? "windows" : osPlat; | ||
const arch = osArch == "x64" ? "amd64" : "386"; | ||
const ext = osPlat == "win32" ? "zip" : "tar.gz"; | ||
const filename = util.format("go%s.%s-%s.%s", version, platform, arch, ext); | ||
return filename; | ||
} | ||
function getDownloadUrl(filename) { | ||
return util.format("https://storage.googleapis.com/golang/%s", filename); | ||
} | ||
function setGoEnvironmentVariables(goRoot) { | ||
core.exportVariable('GOROOT', goRoot); | ||
const goPath = process.env['GOPATH'] || ''; | ||
const goBin = process.env['GOBIN'] || ''; | ||
// set GOPATH and GOBIN as user value | ||
if (!util.isNullOrUndefined(goPath)) { | ||
core.exportVariable("GOPATH", goPath); | ||
} | ||
if (!util.isNullOrUndefined(goBin)) { | ||
core.exportVariable("GOBIN", goBin); | ||
} | ||
} | ||
// This function is required to convert the version 1.10 to 1.10.0. | ||
// Because caching utility accept only sementic version, | ||
// which have patch number as well. | ||
function normalizeVersion(version) { | ||
const versionPart = version.split("."); | ||
if (versionPart[1] == null) { | ||
//append minor and patch version if not available | ||
return version.concat(".0.0"); | ||
} | ||
else if (versionPart[2] == null) { | ||
//append patch version if not available | ||
return version.concat(".0"); | ||
} | ||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const installer = __importStar(require("./installer")); | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
// | ||
// Version is optional. If supplied, install / use from the tool cache | ||
// If not supplied then task is still used to setup proxy, auth, etc... | ||
// | ||
const version = core.getInput('version'); | ||
if (version) { | ||
yield installer.getGo(version); | ||
} | ||
// TODO: setup proxy from runner proxy config | ||
// TODO: problem matchers registered | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
}); | ||
} | ||
run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.