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
Added setup-helm : Install helm binary #1
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,13 @@ | ||
# Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us | ||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. | ||
|
||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
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
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 @@ | ||
name: 'Helm tool installer' | ||
description: 'Install a specific version of helm binary. Acceptable values are latest or any semantic version string like 1.15.0' | ||
inputs: | ||
version: | ||
description: 'Version of helm' | ||
required: true | ||
default: 'latest' | ||
outputs: | ||
helm-path: | ||
description: 'Path to the cached helm binary' | ||
branding: | ||
color: 'blue' | ||
runs: | ||
using: 'node12' | ||
main: 'lib/run.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,126 @@ | ||
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
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) : adopt(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 os = __importStar(require("os")); | ||
const path = __importStar(require("path")); | ||
const util = __importStar(require("util")); | ||
const fs = __importStar(require("fs")); | ||
const toolCache = __importStar(require("../node_modules/@actions/tool-cache")); | ||
const core = __importStar(require("../node_modules/@actions/core")); | ||
const helmToolName = 'helm'; | ||
const stableHelmVersion = 'v2.14.1'; | ||
const helmLatestReleaseUrl = 'https://api.github.com/repos/helm/helm/releases/latest'; | ||
function getExecutableExtension() { | ||
if (os.type().match(/^Win/)) { | ||
return '.exe'; | ||
} | ||
return ''; | ||
} | ||
function getHelmDownloadURL(version) { | ||
switch (os.type()) { | ||
case 'Linux': | ||
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version); | ||
case 'Darwin': | ||
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); | ||
case 'Windows_NT': | ||
default: | ||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version); | ||
} | ||
} | ||
function getStableHelmVersion() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return toolCache.downloadTool(helmLatestReleaseUrl).then((downloadPath) => { | ||
const response = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim()); | ||
if (!response.tag_name) { | ||
return stableHelmVersion; | ||
} | ||
return response.tag_name; | ||
}, (error) => { | ||
core.debug(error); | ||
core.warning(util.format("Failed to read latest kubectl version from stable.txt. From URL %s. Using default stable version %s", helmLatestReleaseUrl, stableHelmVersion)); | ||
return stableHelmVersion; | ||
}); | ||
}); | ||
} | ||
var walkSync = function (dir, filelist, fileToFind) { | ||
var files = fs.readdirSync(dir); | ||
filelist = filelist || []; | ||
files.forEach(function (file) { | ||
if (fs.statSync(path.join(dir, file)).isDirectory()) { | ||
filelist = walkSync(path.join(dir, file), filelist, fileToFind); | ||
} | ||
else { | ||
core.debug(file); | ||
if (file == fileToFind) { | ||
filelist.push(path.join(dir, file)); | ||
} | ||
} | ||
}); | ||
return filelist; | ||
}; | ||
function downloadHelm(version) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!version) { | ||
version = yield getStableHelmVersion(); | ||
} | ||
let cachedToolpath = toolCache.find(helmToolName, version); | ||
if (!cachedToolpath) { | ||
let helmDownloadPath; | ||
try { | ||
helmDownloadPath = yield toolCache.downloadTool(getHelmDownloadURL(version)); | ||
} | ||
catch (exception) { | ||
throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version))); | ||
} | ||
fs.chmodSync(helmDownloadPath, '777'); | ||
const unzipedHelmPath = yield toolCache.extractZip(helmDownloadPath); | ||
cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, helmToolName, version); | ||
} | ||
const helmpath = findHelm(cachedToolpath); | ||
if (!helmpath) { | ||
throw new Error(util.format("Helm executable not found in path ", cachedToolpath)); | ||
} | ||
fs.chmodSync(helmpath, '777'); | ||
return helmpath; | ||
}); | ||
} | ||
function findHelm(rootFolder) { | ||
fs.chmodSync(rootFolder, '777'); | ||
var filelist = []; | ||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); | ||
if (!filelist) { | ||
throw new Error(util.format("Helm executable not found in path ", rootFolder)); | ||
} | ||
else { | ||
return filelist[0]; | ||
} | ||
} | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let version = core.getInput('version', { 'required': true }); | ||
if (version.toLocaleLowerCase() === 'latest') { | ||
version = yield getStableHelmVersion(); | ||
} | ||
let cachedPath = yield downloadHelm(version); | ||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); | ||
core.setOutput('helm-path', cachedPath); | ||
}); | ||
} | ||
run().catch(core.setFailed); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
{ | ||
"name": "setuphelm", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Setup helm", | ||
"author": "Anumita Shenoy", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@actions/tool-cache": "1.1.2", | ||
"@actions/io": "^1.0.0", | ||
"@actions/core": "^1.0.0", | ||
"@actions/exec": "^1.0.0" | ||
}, | ||
"main": "lib/run.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.0.10", | ||
"typescript": "^3.5.2" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
latest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already mentioned latest