Skip to content

Commit

Permalink
work with dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Shibanov committed Jun 23, 2020
1 parent 6ccd4da commit a4e03e3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
46 changes: 24 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6926,7 +6926,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeSemver = exports.getVersionsDist = exports.getInfoFromManifest = exports.findMatch = exports.extractGoArchive = exports.getGo = void 0;
exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.extractGoArchive = exports.getGo = void 0;
const tc = __importStar(__webpack_require__(533));
const core = __importStar(__webpack_require__(470));
const path = __importStar(__webpack_require__(622));
Expand Down Expand Up @@ -6955,7 +6955,7 @@ function getGo(versionSpec, stable, auth) {
try {
info = yield getInfoFromManifest(versionSpec, stable, auth);
if (info) {
downloadPath = yield installGoVersion(info, auth, undefined);
downloadPath = yield installGoVersion(info, auth);
}
else {
console.log('Not found in manifest. Falling back to download directly from Go');
Expand All @@ -6981,7 +6981,7 @@ function getGo(versionSpec, stable, auth) {
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
}
try {
downloadPath = yield installGoVersion(info, undefined, 'go');
downloadPath = yield installGoVersion(info, undefined);
}
catch (err) {
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
Expand All @@ -6991,14 +6991,14 @@ function getGo(versionSpec, stable, auth) {
});
}
exports.getGo = getGo;
function installGoVersion(info, auth, subDir) {
function installGoVersion(info, auth) {
return __awaiter(this, void 0, void 0, function* () {
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
console.log('Extracting Go...');
let extPath = yield extractGoArchive(downloadPath);
if (subDir) {
extPath = path.join(extPath, subDir);
if (info.type === "dist") {
extPath = path.join(extPath, "go");
}
console.log('Adding to the cache ...');
return yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion));
Expand All @@ -7018,6 +7018,23 @@ function extractGoArchive(archivePath) {
});
}
exports.extractGoArchive = extractGoArchive;
function getInfoFromManifest(versionSpec, stable, auth) {
return __awaiter(this, void 0, void 0, function* () {
let info = null;
const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`);
const rel = yield tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) {
info = {};
info.type = "manifest";
info.resolvedVersion = rel.version;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}
return info;
});
}
exports.getInfoFromManifest = getInfoFromManifest;
function getInfoFromDist(versionSpec, stable) {
return __awaiter(this, void 0, void 0, function* () {
let version;
Expand All @@ -7030,6 +7047,7 @@ function getInfoFromDist(versionSpec, stable) {
}
let downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
return {
type: "dist",
downloadUrl: downloadUrl,
resolvedVersion: version.version,
fileName: version.files[0].filename
Expand Down Expand Up @@ -7080,22 +7098,6 @@ function findMatch(versionSpec, stable) {
});
}
exports.findMatch = findMatch;
function getInfoFromManifest(versionSpec, stable, auth) {
return __awaiter(this, void 0, void 0, function* () {
let info = null;
const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`);
const rel = yield tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) {
info = {};
info.resolvedVersion = rel.version;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}
return info;
});
}
exports.getInfoFromManifest = getInfoFromManifest;
function getVersionsDist(dlUrl) {
return __awaiter(this, void 0, void 0, function* () {
// this returns versions descending so latest is first
Expand Down
56 changes: 30 additions & 26 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as httpm from '@actions/http-client';
import * as sys from './system';
import os from 'os';

type InstallationType = 'dist' | 'manifest';

export interface IGoVersionFile {
filename: string;
// darwin, linux, windows
Expand All @@ -20,6 +22,7 @@ export interface IGoVersion {
}

export interface IGoVersionInfo {
type: InstallationType;
downloadUrl: string;
resolvedVersion: string;
fileName: string;
Expand Down Expand Up @@ -52,7 +55,7 @@ export async function getGo(
try {
info = await getInfoFromManifest(versionSpec, stable, auth);
if (info) {
downloadPath = await installGoVersion(info, auth, undefined);
downloadPath = await installGoVersion(info, auth);
} else {
console.log(
'Not found in manifest. Falling back to download directly from Go'
Expand Down Expand Up @@ -85,7 +88,7 @@ export async function getGo(
}

try {
downloadPath = await installGoVersion(info, undefined, 'go');
downloadPath = await installGoVersion(info, undefined);
} catch (err) {
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
}
Expand All @@ -96,16 +99,15 @@ export async function getGo(

async function installGoVersion(
info: IGoVersionInfo,
auth: string | undefined,
subDir: string | undefined
auth: string | undefined
): Promise<string> {
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);

console.log('Extracting Go...');
let extPath = await extractGoArchive(downloadPath);
if (subDir) {
extPath = path.join(extPath, subDir);
if (info.type === 'dist') {
extPath = path.join(extPath, 'go');
}

console.log('Adding to the cache ...');
Expand All @@ -125,6 +127,27 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
return extPath;
}

export async function getInfoFromManifest(
versionSpec: string,
stable: boolean,
auth: string | undefined
): Promise<IGoVersionInfo | null> {
let info: IGoVersionInfo | null = null;
const releases = await tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`);
const rel = await tc.findFromManifest(versionSpec, stable, releases);

if (rel && rel.files.length > 0) {
info = <IGoVersionInfo>{};
info.type = 'manifest';
info.resolvedVersion = rel.version;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}

return info;
}

async function getInfoFromDist(
versionSpec: string,
stable: boolean
Expand All @@ -141,6 +164,7 @@ async function getInfoFromDist(
let downloadUrl: string = `https://storage.googleapis.com/golang/${version.files[0].filename}`;

return <IGoVersionInfo>{
type: 'dist',
downloadUrl: downloadUrl,
resolvedVersion: version.version,
fileName: version.files[0].filename
Expand Down Expand Up @@ -204,26 +228,6 @@ export async function findMatch(
return result;
}

export async function getInfoFromManifest(
versionSpec: string,
stable: boolean,
auth: string | undefined
): Promise<IGoVersionInfo | null> {
let info: IGoVersionInfo | null = null;
const releases = await tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`);
const rel = await tc.findFromManifest(versionSpec, stable, releases);

if (rel && rel.files.length > 0) {
info = <IGoVersionInfo>{};
info.resolvedVersion = rel.version;
info.downloadUrl = rel.files[0].download_url;
info.fileName = rel.files[0].filename;
}

return info;
}

export async function getVersionsDist(
dlUrl: string
): Promise<IGoVersion[] | null> {
Expand Down

0 comments on commit a4e03e3

Please sign in to comment.