Fixing PR comments in release

This commit is contained in:
Shivam Gupta
2021-03-30 11:33:44 +05:30
parent 6dc9231fd1
commit adf7ced229
2 changed files with 205 additions and 192 deletions

View File

@ -1,109 +1,111 @@
"use strict"; "use strict";
// Copyright (c) Microsoft Corporation. // Copyright (c) Microsoft Corporation.
// Licensed under the MIT license. // Licensed under the MIT license.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k; if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) { }) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k; if (k2 === undefined) k2 = k;
o[k2] = m[k]; o[k2] = m[k];
})); }));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v }); Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) { }) : function(o, v) {
o["default"] = v; o["default"] = v;
}); });
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod); __setModuleDefault(result, mod);
return result; return result;
}; };
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 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 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); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const util = __importStar(require("util")); const util = __importStar(require("util"));
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const toolCache = __importStar(require("@actions/tool-cache")); const toolCache = __importStar(require("@actions/tool-cache"));
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const graphql_1 = require("@octokit/graphql"); const graphql_1 = require("@octokit/graphql");
const helmToolName = 'helm'; const helmToolName = 'helm';
const stableHelmVersion = 'v3.2.1'; const stableHelmVersion = 'v3.2.1';
const LATEST_HELM2_VERSION = '2.*'; const stableHelm3Version = 'v3.5.3';
const LATEST_HELM3_VERSION = '3.*'; const stableHelm2Version = 'v2.17.0';
function getExecutableExtension() { const LATEST_HELM2_VERSION = '2.*';
if (os.type().match(/^Win/)) { const LATEST_HELM3_VERSION = '3.*';
return '.exe'; function getExecutableExtension() {
} if (os.type().match(/^Win/)) {
return ''; return '.exe';
} }
function getHelmDownloadURL(version) { return '';
switch (os.type()) { }
case 'Linux': function getHelmDownloadURL(version) {
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version); switch (os.type()) {
case 'Darwin': case 'Linux':
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
case 'Windows_NT': case 'Darwin':
default: return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version);
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version); case 'Windows_NT':
} default:
} return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
var walkSync = function (dir, filelist, fileToFind) { }
var files = fs.readdirSync(dir); }
filelist = filelist || []; var walkSync = function (dir, filelist, fileToFind) {
files.forEach(function (file) { var files = fs.readdirSync(dir);
if (fs.statSync(path.join(dir, file)).isDirectory()) { filelist = filelist || [];
filelist = walkSync(path.join(dir, file), filelist, fileToFind); files.forEach(function (file) {
} if (fs.statSync(path.join(dir, file)).isDirectory()) {
else { filelist = walkSync(path.join(dir, file), filelist, fileToFind);
core.debug(file); }
if (file == fileToFind) { else {
filelist.push(path.join(dir, file)); core.debug(file);
} if (file == fileToFind) {
} filelist.push(path.join(dir, file));
}); }
return filelist; }
}; });
function downloadHelm(version) { return filelist;
return __awaiter(this, void 0, void 0, function* () { };
if (!version) { function downloadHelm(version) {
version = yield getLatestHelmVersionFor("v3"); return __awaiter(this, void 0, void 0, function* () {
} if (!version) {
let cachedToolpath = toolCache.find(helmToolName, version); version = yield getLatestHelmVersionFor("v3");
if (!cachedToolpath) { }
let helmDownloadPath; let cachedToolpath = toolCache.find(helmToolName, version);
try { if (!cachedToolpath) {
helmDownloadPath = yield toolCache.downloadTool(getHelmDownloadURL(version)); let helmDownloadPath;
} try {
catch (exception) { helmDownloadPath = yield toolCache.downloadTool(getHelmDownloadURL(version));
throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version))); }
} catch (exception) {
fs.chmodSync(helmDownloadPath, '777'); throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version)));
const unzipedHelmPath = yield toolCache.extractZip(helmDownloadPath); }
cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, helmToolName, version); fs.chmodSync(helmDownloadPath, '777');
} const unzipedHelmPath = yield toolCache.extractZip(helmDownloadPath);
const helmpath = findHelm(cachedToolpath); cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, helmToolName, version);
if (!helmpath) { }
throw new Error(util.format("Helm executable not found in path ", cachedToolpath)); const helmpath = findHelm(cachedToolpath);
} if (!helmpath) {
fs.chmodSync(helmpath, '777'); throw new Error(util.format("Helm executable not found in path ", cachedToolpath));
return helmpath; }
}); fs.chmodSync(helmpath, '777');
} return helmpath;
function getLatestHelmVersionFor(type) { });
return __awaiter(this, void 0, void 0, function* () { }
const token = core.getInput('token', { 'required': true }); function getLatestHelmVersionFor(type) {
try { return __awaiter(this, void 0, void 0, function* () {
const token = core.getInput('token', { 'required': true });
try {
const { repository } = yield graphql_1.graphql(`{ const { repository } = yield graphql_1.graphql(`{
repository(name:"helm", owner:"helm") { repository(name:"helm", owner:"helm") {
releases(last: 100) { releases(last: 100) {
@ -112,64 +114,68 @@ function getLatestHelmVersionFor(type) {
} }
} }
} }
}`, { }`, {
headers: { headers: {
authorization: `token ${token}` authorization: `token ${token}`
} }
}); });
const releases = repository.releases.nodes.reverse(); const releases = repository.releases.nodes.reverse();
let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type)); let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type));
if (latestValidRelease) if (latestValidRelease)
return latestValidRelease.tagName; return latestValidRelease.tagName;
} }
catch (err) { catch (err) {
core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), stableHelmVersion)); core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), getStableHelmVersionFor(type)));
} return getStableHelmVersionFor(type);
core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, stableHelmVersion)); }
return stableHelmVersion; core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, getStableHelmVersionFor(type)));
}); return getStableHelmVersionFor(type);
} });
// isValidVersion checks if verison matches the specified type and is a stable release }
function isValidVersion(version, type) { function getStableHelmVersionFor(type) {
if (!version.toLocaleLowerCase().startsWith(type)) return type === "v2" ? stableHelm2Version : stableHelm3Version;
return false; }
return version.indexOf('rc') == -1; // isValidVersion checks if verison matches the specified type and is a stable release
} function isValidVersion(version, type) {
function findHelm(rootFolder) { if (!version.toLocaleLowerCase().startsWith(type))
fs.chmodSync(rootFolder, '777'); return false;
var filelist = []; return version.indexOf('rc') == -1;
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); }
if (!filelist) { function findHelm(rootFolder) {
throw new Error(util.format("Helm executable not found in path ", rootFolder)); fs.chmodSync(rootFolder, '777');
} var filelist = [];
else { walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
return filelist[0]; if (!filelist) {
} throw new Error(util.format("Helm executable not found in path ", rootFolder));
} }
function run() { else {
return __awaiter(this, void 0, void 0, function* () { return filelist[0];
let version = core.getInput('version', { 'required': true }); }
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) { }
version = yield getLatestHelmVersionFor("v3"); function run() {
} return __awaiter(this, void 0, void 0, function* () {
else if (version === LATEST_HELM2_VERSION) { let version = core.getInput('version', { 'required': true });
version = yield getLatestHelmVersionFor("v2"); if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
} version = yield getLatestHelmVersionFor("v3");
else if (!version.toLocaleLowerCase().startsWith('v')) { }
version = 'v' + version; else if (version === LATEST_HELM2_VERSION) {
} version = yield getLatestHelmVersionFor("v2");
core.debug(util.format("Downloading %s", version)); }
let cachedPath = yield downloadHelm(version); else if (!version.toLocaleLowerCase().startsWith('v')) {
try { version = 'v' + version;
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) { }
core.addPath(path.dirname(cachedPath)); core.debug(util.format("Downloading %s", version));
} let cachedPath = yield downloadHelm(version);
} try {
catch (_a) { if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
//do nothing, set as output variable core.addPath(path.dirname(cachedPath));
} }
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); }
core.setOutput('helm-path', cachedPath); catch (_a) {
}); //do nothing, set as output variable
} }
run().catch(core.setFailed); console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
core.setOutput('helm-path', cachedPath);
});
}
run().catch(core.setFailed);

View File

@ -12,6 +12,8 @@ import { graphql } from '@octokit/graphql';
const helmToolName = 'helm'; const helmToolName = 'helm';
const stableHelmVersion = 'v3.2.1'; const stableHelmVersion = 'v3.2.1';
const stableHelm3Version = 'v3.5.3';
const stableHelm2Version = 'v2.17.0';
const LATEST_HELM2_VERSION = '2.*'; const LATEST_HELM2_VERSION = '2.*';
const LATEST_HELM3_VERSION = '3.*'; const LATEST_HELM3_VERSION = '3.*';
@ -78,11 +80,11 @@ async function downloadHelm(version: string): Promise<string> {
return helmpath; return helmpath;
} }
async function getLatestHelmVersionFor(type) { async function getLatestHelmVersionFor(type: string): Promise<string> {
const token = core.getInput('token', { 'required': true }); const token = core.getInput('token', { 'required': true });
try { try {
const { repository } = await graphql( const { repository } = await graphql(
`{ `{
repository(name:"helm", owner:"helm") { repository(name:"helm", owner:"helm") {
releases(last: 100) { releases(last: 100) {
nodes { nodes {
@ -91,29 +93,34 @@ async function getLatestHelmVersionFor(type) {
} }
} }
}`, }`,
{ {
headers: { headers: {
authorization: `token ${token}` authorization: `token ${token}`
} }
} }
); );
const releases = repository.releases.nodes.reverse(); const releases = repository.releases.nodes.reverse();
let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type)); let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type));
if(latestValidRelease) if (latestValidRelease)
return latestValidRelease.tagName; return latestValidRelease.tagName;
} catch (err) { } catch (err) {
core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), stableHelmVersion)); core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), getStableHelmVersionFor(type)));
} return getStableHelmVersionFor(type);
core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, stableHelmVersion)); }
return stableHelmVersion; core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, getStableHelmVersionFor(type)));
return getStableHelmVersionFor(type);
}
function getStableHelmVersionFor(type: string) {
return type==="v2" ? stableHelm2Version : stableHelm3Version;
} }
// isValidVersion checks if verison matches the specified type and is a stable release // isValidVersion checks if verison matches the specified type and is a stable release
function isValidVersion(version, type): boolean { function isValidVersion(version: string, type: string): boolean {
if (!version.toLocaleLowerCase().startsWith(type)) if (!version.toLocaleLowerCase().startsWith(type))
return false; return false;
return version.indexOf('rc') == -1 return version.indexOf('rc') == -1
} }
function findHelm(rootFolder: string): string { function findHelm(rootFolder: string): string {