Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async downloadAndInstall(versionInfo: VersionInfo, downloadUrl: string): Promise {
if (!versionInfo || !versionInfo.getVersion() || !downloadUrl || !url.parse(downloadUrl)) {
throw tl.loc("VersionCanNotBeDownloadedFromUrl", versionInfo, downloadUrl);
}
let version = versionInfo.getVersion();
try {
try {
var downloadPath = await toolLib.downloadTool(downloadUrl)
}
catch (ex) {
throw tl.loc("CouldNotDownload", downloadUrl, ex);
}
// Extract
console.log(tl.loc("ExtractingPackage", downloadPath));
try {
var extPath = tl.osType().match(/^Win/) ? await toolLib.extractZip(downloadPath) : await toolLib.extractTar(downloadPath);
}
catch (ex) {
throw tl.loc("FailedWhileExtractingPacakge", ex);
}
// Copy folders
tl.debug(tl.loc("CopyingFoldersIntoPath", this.installationPath));
async function acquireGo(version: string): Promise {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileName(version);
let downloadUrl: string = getDownloadUrl(fileName);
let downloadPath: string = null;
try {
downloadPath = await toolLib.downloadTool(downloadUrl);
} catch (error) {
tl.debug(error);
throw (util.format(tl.loc('FailedToDownload'), version, error));
}
tl.assertAgent('2.115.0');
//
// Extract
//
let extPath: string = tl.getVariable('Agent.TempDirectory');
if (!extPath) {
throw new Error(tl.loc('TempDirNotSet'));
}
async function acquireGo(version: string): Promise {
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
let fileName: string = getFileName(version);
let downloadUrl: string = getDownloadUrl(fileName);
let downloadPath: string = null;
try {
downloadPath = await toolLib.downloadTool(downloadUrl);
} catch (error) {
tl.debug(error);
// cannot localized the string here because to localize we need to set the resource file.
// which can be set only once. azure-pipelines-tool-lib/tool, is already setting it to different file.
// So left with no option but to hardcode the string. Other tasks are doing the same.
throw (util.format("Failed to download version %s. Please verify that the version is valid and resolve any other issues. %s", version, error));
}
//make sure agent version is latest then 2.115.0
tl.assertAgent('2.115.0');
//
// Extract
//
let extPath: string;
try {
const artifactToolGetUrl = await blobstoreConnection.vsoClient.getVersioningData(ApiVersion,
blobstoreAreaName, blobstoreAreaId, { toolName }, {osName, arch});
const artifactToolUri = await blobstoreConnection.rest.get(artifactToolGetUrl.requestUrl);
if (artifactToolUri.statusCode !== 200) {
tl.debug(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolUri.toString()));
throw new Error(tl.loc("Error_UnexpectedErrorFailedToGetToolMetadata", artifactToolGetUrl.requestUrl));
}
let artifactToolPath = toollib.findLocalTool(toolName, artifactToolUri.result['version']);
if (!artifactToolPath) {
tl.debug(tl.loc("Info_DownloadingArtifactTool", artifactToolUri.result['uri']));
const zippedToolsDir: string = await toollib.downloadTool(artifactToolUri.result['uri']);
tl.debug("Downloaded zipped artifact tool to " + zippedToolsDir);
const unzippedToolsDir = await extractZip(zippedToolsDir);
artifactToolPath = await toollib.cacheDir(unzippedToolsDir, "ArtifactTool", artifactToolUri.result['version']);
} else {
tl.debug(tl.loc("Info_ResolvedToolFromCache", artifactToolPath));
}
return getArtifactToolLocation(artifactToolPath);
} catch (err) {
tl.warning(err);
// TODO: Should return null?
// tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToGetArtifactTool", err));
return null;
}
}
public static async publishLogs(logLink: string) {
var logfilepath = await toolLib.downloadTool(logLink);
var readstream = fs.createReadStream(logfilepath);
console.log(tl.loc("DownloadedRunLogs"), await TaskUtil.streamToString(readstream));
}
}
console.log('yuniql/var_version: ' + version);
}
//download yuniql-cli-win-x64-{version}}.zip
let packageFileName: string = '';
switch (osPlat) {
case 'win32': packageFileName = 'yuniql-cli-win-' + osArch + '-' + version + '.zip'; break;
//case 'linux': dataFileName = 'yuniql-cli-linux-' + osArch + '-' + version + '.tar'; break;
default: throw new Error(`Unsupported Agent OS '${osPlat}'`);
}
const downloadBaseUrl = 'https://github.com/rdagumampan/yuniql/releases/download'
const downloadUrl = downloadBaseUrl + '/' + version + '/' + packageFileName;
console.log('yuniql/var_downloadUrl: ' + downloadUrl);
const temp: string = await toolLib.downloadTool(downloadUrl);
console.log('yuniql/var_temp: ' + temp);
//extract assemblies
const extractRoot: string = await toolLib.extractZip(temp);
console.log('yuniql/var_extractRoot: ' + extractRoot);
//cache assemblies
if (version != 'latest') {
toolLib.cacheDir(extractRoot, "yuniql", version);
} else {
//use v0.0.0 as placeholder for latest version
//TODO: always replace the current cached version for now
toolLib.cleanVersion('v0.0.0');
toolLib.cacheDir(extractRoot, "yuniql", 'v0.0.0');
}
export async function downloadDocker(version: string, releaseType: string): Promise {
//docker does not follow strict semversion and has leading zeros in versions <10
var cleanVersion = version.replace(/(0+)([1-9]+)/,"$2");
var cachedToolpath = toolLib.findLocalTool(dockerToolName + "-" + releaseType, cleanVersion);
if (!cachedToolpath) {
try {
var dockerDownloadPath = await toolLib.downloadTool(getDockerDownloadURL(version, releaseType), dockerToolName + "-" + uuidV4() + getArchiveExtension());
} catch (exception) {
throw new Error(tl.loc("DockerDownloadFailed", getDockerDownloadURL(version, releaseType), exception));
}
var unzipedDockerPath;
if(isWindows) {
unzipedDockerPath = await toolLib.extractZip(dockerDownloadPath);
} else {
//tgz is a tar file packaged using gzip utility
unzipedDockerPath = await toolLib.extractTar(dockerDownloadPath);
}
//contents of the extracted archive are under "docker" directory. caching only "docker(.exe)" CLI
unzipedDockerPath = path.join(unzipedDockerPath, "docker", dockerToolNameWithExtension);
cachedToolpath = await toolLib.cacheFile(unzipedDockerPath, dockerToolNameWithExtension, dockerToolName+ "-" + releaseType, cleanVersion);
}
export async function getLatestFuncToolsVersion(): Promise {
const funcToolsLatestReleaseUrl = 'https://api.github.com/repos/Azure/azure-functions-core-tools/releases/latest';
let latestVersion = stableFuncToolsVersion;
try {
const downloadPath = await toolLib.downloadTool(funcToolsLatestReleaseUrl);
const response = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
if (response.tag_name) {
latestVersion = response.tag_name;
}
} catch (error) {
tl.warning(tl.loc('ErrorFetchingLatestVersion', funcToolsLatestReleaseUrl, error, stableFuncToolsVersion));
}
return latestVersion;
}