mirror of
https://github.com/actions/setup-go.git
synced 2025-06-24 05:47:57 +02:00
Add support for arm32 go arch (#253)
This commit is contained in:
@ -32,17 +32,18 @@ export interface IGoVersionInfo {
|
||||
export async function getGo(
|
||||
versionSpec: string,
|
||||
checkLatest: boolean,
|
||||
auth: string | undefined
|
||||
auth: string | undefined,
|
||||
arch = os.arch()
|
||||
) {
|
||||
let osPlat: string = os.platform();
|
||||
let osArch: string = os.arch();
|
||||
|
||||
if (checkLatest) {
|
||||
core.info('Attempting to resolve the latest version from the manifest...');
|
||||
const resolvedVersion = await resolveVersionFromManifest(
|
||||
versionSpec,
|
||||
true,
|
||||
auth
|
||||
auth,
|
||||
arch
|
||||
);
|
||||
if (resolvedVersion) {
|
||||
versionSpec = resolvedVersion;
|
||||
@ -54,7 +55,7 @@ export async function getGo(
|
||||
|
||||
// check cache
|
||||
let toolPath: string;
|
||||
toolPath = tc.find('go', versionSpec);
|
||||
toolPath = tc.find('go', versionSpec, arch);
|
||||
// If not found in cache, download
|
||||
if (toolPath) {
|
||||
core.info(`Found in cache @ ${toolPath}`);
|
||||
@ -68,9 +69,9 @@ export async function getGo(
|
||||
// Try download from internal distribution (popular versions only)
|
||||
//
|
||||
try {
|
||||
info = await getInfoFromManifest(versionSpec, true, auth);
|
||||
info = await getInfoFromManifest(versionSpec, true, auth, arch);
|
||||
if (info) {
|
||||
downloadPath = await installGoVersion(info, auth);
|
||||
downloadPath = await installGoVersion(info, auth, arch);
|
||||
} else {
|
||||
core.info(
|
||||
'Not found in manifest. Falling back to download directly from Go'
|
||||
@ -95,16 +96,16 @@ export async function getGo(
|
||||
// Download from storage.googleapis.com
|
||||
//
|
||||
if (!downloadPath) {
|
||||
info = await getInfoFromDist(versionSpec);
|
||||
info = await getInfoFromDist(versionSpec, arch);
|
||||
if (!info) {
|
||||
throw new Error(
|
||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
core.info('Install from dist');
|
||||
downloadPath = await installGoVersion(info, undefined);
|
||||
downloadPath = await installGoVersion(info, undefined, arch);
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
||||
}
|
||||
@ -116,10 +117,11 @@ export async function getGo(
|
||||
async function resolveVersionFromManifest(
|
||||
versionSpec: string,
|
||||
stable: boolean,
|
||||
auth: string | undefined
|
||||
auth: string | undefined,
|
||||
arch: string
|
||||
): Promise<string | undefined> {
|
||||
try {
|
||||
const info = await getInfoFromManifest(versionSpec, stable, auth);
|
||||
const info = await getInfoFromManifest(versionSpec, stable, auth, arch);
|
||||
return info?.resolvedVersion;
|
||||
} catch (err) {
|
||||
core.info('Unable to resolve a version from the manifest...');
|
||||
@ -129,7 +131,8 @@ async function resolveVersionFromManifest(
|
||||
|
||||
async function installGoVersion(
|
||||
info: IGoVersionInfo,
|
||||
auth: string | undefined
|
||||
auth: string | undefined,
|
||||
arch: string
|
||||
): Promise<string> {
|
||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
||||
|
||||
@ -151,7 +154,8 @@ async function installGoVersion(
|
||||
const cachedDir = await tc.cacheDir(
|
||||
extPath,
|
||||
'go',
|
||||
makeSemver(info.resolvedVersion)
|
||||
makeSemver(info.resolvedVersion),
|
||||
arch
|
||||
);
|
||||
core.info(`Successfully cached go to ${cachedDir}`);
|
||||
return cachedDir;
|
||||
@ -173,7 +177,8 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
|
||||
export async function getInfoFromManifest(
|
||||
versionSpec: string,
|
||||
stable: boolean,
|
||||
auth: string | undefined
|
||||
auth: string | undefined,
|
||||
arch = os.arch()
|
||||
): Promise<IGoVersionInfo | null> {
|
||||
let info: IGoVersionInfo | null = null;
|
||||
const releases = await tc.getManifestFromRepo(
|
||||
@ -183,7 +188,7 @@ export async function getInfoFromManifest(
|
||||
'main'
|
||||
);
|
||||
core.info(`matching ${versionSpec}...`);
|
||||
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
||||
const rel = await tc.findFromManifest(versionSpec, stable, releases, arch);
|
||||
|
||||
if (rel && rel.files.length > 0) {
|
||||
info = <IGoVersionInfo>{};
|
||||
@ -197,10 +202,11 @@ export async function getInfoFromManifest(
|
||||
}
|
||||
|
||||
async function getInfoFromDist(
|
||||
versionSpec: string
|
||||
versionSpec: string,
|
||||
arch: string
|
||||
): Promise<IGoVersionInfo | null> {
|
||||
let version: IGoVersion | undefined;
|
||||
version = await findMatch(versionSpec);
|
||||
version = await findMatch(versionSpec, arch);
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
@ -216,9 +222,10 @@ async function getInfoFromDist(
|
||||
}
|
||||
|
||||
export async function findMatch(
|
||||
versionSpec: string
|
||||
versionSpec: string,
|
||||
arch = os.arch()
|
||||
): Promise<IGoVersion | undefined> {
|
||||
let archFilter = sys.getArch();
|
||||
let archFilter = sys.getArch(arch);
|
||||
let platFilter = sys.getPlatform();
|
||||
|
||||
let result: IGoVersion | undefined;
|
||||
|
14
src/main.ts
14
src/main.ts
@ -7,6 +7,7 @@ import {restoreCache} from './cache-restore';
|
||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
||||
import cp from 'child_process';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
@ -19,12 +20,23 @@ export async function run() {
|
||||
const cache = core.getBooleanInput('cache');
|
||||
core.info(`Setup go version spec ${versionSpec}`);
|
||||
|
||||
let arch = core.getInput('architecture');
|
||||
|
||||
if (!arch) {
|
||||
arch = os.arch();
|
||||
}
|
||||
|
||||
if (versionSpec) {
|
||||
let token = core.getInput('token');
|
||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
const installDir = await installer.getGo(versionSpec, checkLatest, auth);
|
||||
const installDir = await installer.getGo(
|
||||
versionSpec,
|
||||
checkLatest,
|
||||
auth,
|
||||
arch
|
||||
);
|
||||
|
||||
core.addPath(path.join(installDir, 'bin'));
|
||||
core.info('Added go to the path');
|
||||
|
@ -15,9 +15,8 @@ export function getPlatform(): string {
|
||||
return plat;
|
||||
}
|
||||
|
||||
export function getArch(): string {
|
||||
export function getArch(arch: string): string {
|
||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
||||
let arch: string = os.arch();
|
||||
|
||||
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
||||
// currently not supported by runner but future proofed mapping
|
||||
@ -31,6 +30,9 @@ export function getArch(): string {
|
||||
case 'x32':
|
||||
arch = '386';
|
||||
break;
|
||||
case 'arm':
|
||||
arch = 'armv6l';
|
||||
break;
|
||||
}
|
||||
|
||||
return arch;
|
||||
|
Reference in New Issue
Block a user