Skip to content

Commit 268d8c0

Browse files
authored
Add support for arm32 go arch (#253)
1 parent f279813 commit 268d8c0

File tree

7 files changed

+127
-46
lines changed

7 files changed

+127
-46
lines changed

.github/workflows/versions.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
os: [macos-latest, windows-latest, ubuntu-latest]
22-
go: [1.12, 1.13, 1.14]
22+
go: [1.17, 1.18, 1.19]
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v3
@@ -107,3 +107,20 @@ jobs:
107107
- name: verify go
108108
run: __tests__/verify-go.sh ${{ matrix.go }}
109109
shell: bash
110+
111+
architecture:
112+
runs-on: ${{ matrix.os }}
113+
strategy:
114+
fail-fast: false
115+
matrix:
116+
os: [ubuntu-latest, windows-latest, macos-latest]
117+
go-version: [1.16, 1.17]
118+
steps:
119+
- uses: actions/checkout@v3
120+
- name: Setup Go and check latest
121+
uses: ./
122+
with:
123+
go-version: ${{ matrix.go-version }}
124+
architecture: x64
125+
- name: Verify Go
126+
run: go version

__tests__/setup-go.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ describe('setup-go', () => {
453453
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
454454
});
455455

456-
it('falls back to a version from node dist', async () => {
456+
it('falls back to a version from go dist', async () => {
457457
os.platform = 'linux';
458458
os.arch = 'x64';
459459

@@ -879,5 +879,40 @@ exclude example.com/thismodule v1.3.0
879879
`::error::The specified go version file at: go.mod does not exist${osm.EOL}`
880880
);
881881
});
882+
883+
it('acquires specified architecture of go', async () => {
884+
for (const {arch, version, osSpec} of [
885+
{arch: 'amd64', version: '1.13.7', osSpec: 'linux'},
886+
{arch: 'armv6l', version: '1.12.2', osSpec: 'linux'}
887+
]) {
888+
os.platform = osSpec;
889+
os.arch = arch;
890+
891+
const fileExtension = os.platform === 'win32' ? 'zip' : 'tar.gz';
892+
893+
const platform = os.platform === 'win32' ? 'win' : os.platform;
894+
895+
inputs['go-version'] = version;
896+
inputs['architecture'] = arch;
897+
898+
let expectedUrl =
899+
platform === 'win32'
900+
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
901+
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
902+
903+
// ... but not in the local cache
904+
findSpy.mockImplementation(() => '');
905+
906+
dlSpy.mockImplementation(async () => '/some/temp/path');
907+
let toolPath = path.normalize(`/cache/go/${version}/${arch}`);
908+
cacheSpy.mockImplementation(async () => toolPath);
909+
910+
await main.run();
911+
912+
expect(logSpy).toHaveBeenCalledWith(
913+
`Acquiring go${version} from ${expectedUrl}`
914+
);
915+
}
916+
}, 100000);
882917
});
883918
});

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ inputs:
1717
default: false
1818
cache-dependency-path:
1919
description: 'Used to specify the path to a dependency file - go.sum'
20+
architecture:
21+
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
2022
outputs:
2123
go-version:
2224
description: 'The installed Go version. Useful when given a version range as input.'

dist/setup/index.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62858,13 +62858,12 @@ const httpm = __importStar(__nccwpck_require__(6255));
6285862858
const sys = __importStar(__nccwpck_require__(4300));
6285962859
const fs_1 = __importDefault(__nccwpck_require__(7147));
6286062860
const os_1 = __importDefault(__nccwpck_require__(2037));
62861-
function getGo(versionSpec, checkLatest, auth) {
62861+
function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
6286262862
return __awaiter(this, void 0, void 0, function* () {
6286362863
let osPlat = os_1.default.platform();
62864-
let osArch = os_1.default.arch();
6286562864
if (checkLatest) {
6286662865
core.info('Attempting to resolve the latest version from the manifest...');
62867-
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth);
62866+
const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch);
6286862867
if (resolvedVersion) {
6286962868
versionSpec = resolvedVersion;
6287062869
core.info(`Resolved as '${versionSpec}'`);
@@ -62875,7 +62874,7 @@ function getGo(versionSpec, checkLatest, auth) {
6287562874
}
6287662875
// check cache
6287762876
let toolPath;
62878-
toolPath = tc.find('go', versionSpec);
62877+
toolPath = tc.find('go', versionSpec, arch);
6287962878
// If not found in cache, download
6288062879
if (toolPath) {
6288162880
core.info(`Found in cache @ ${toolPath}`);
@@ -62888,9 +62887,9 @@ function getGo(versionSpec, checkLatest, auth) {
6288862887
// Try download from internal distribution (popular versions only)
6288962888
//
6289062889
try {
62891-
info = yield getInfoFromManifest(versionSpec, true, auth);
62890+
info = yield getInfoFromManifest(versionSpec, true, auth, arch);
6289262891
if (info) {
62893-
downloadPath = yield installGoVersion(info, auth);
62892+
downloadPath = yield installGoVersion(info, auth, arch);
6289462893
}
6289562894
else {
6289662895
core.info('Not found in manifest. Falling back to download directly from Go');
@@ -62911,13 +62910,13 @@ function getGo(versionSpec, checkLatest, auth) {
6291162910
// Download from storage.googleapis.com
6291262911
//
6291362912
if (!downloadPath) {
62914-
info = yield getInfoFromDist(versionSpec);
62913+
info = yield getInfoFromDist(versionSpec, arch);
6291562914
if (!info) {
62916-
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
62915+
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`);
6291762916
}
6291862917
try {
6291962918
core.info('Install from dist');
62920-
downloadPath = yield installGoVersion(info, undefined);
62919+
downloadPath = yield installGoVersion(info, undefined, arch);
6292162920
}
6292262921
catch (err) {
6292362922
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
@@ -62927,10 +62926,10 @@ function getGo(versionSpec, checkLatest, auth) {
6292762926
});
6292862927
}
6292962928
exports.getGo = getGo;
62930-
function resolveVersionFromManifest(versionSpec, stable, auth) {
62929+
function resolveVersionFromManifest(versionSpec, stable, auth, arch) {
6293162930
return __awaiter(this, void 0, void 0, function* () {
6293262931
try {
62933-
const info = yield getInfoFromManifest(versionSpec, stable, auth);
62932+
const info = yield getInfoFromManifest(versionSpec, stable, auth, arch);
6293462933
return info === null || info === void 0 ? void 0 : info.resolvedVersion;
6293562934
}
6293662935
catch (err) {
@@ -62939,7 +62938,7 @@ function resolveVersionFromManifest(versionSpec, stable, auth) {
6293962938
}
6294062939
});
6294162940
}
62942-
function installGoVersion(info, auth) {
62941+
function installGoVersion(info, auth, arch) {
6294362942
return __awaiter(this, void 0, void 0, function* () {
6294462943
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
6294562944
// Windows requires that we keep the extension (.zip) for extraction
@@ -62954,7 +62953,7 @@ function installGoVersion(info, auth) {
6295462953
extPath = path.join(extPath, 'go');
6295562954
}
6295662955
core.info('Adding to the cache ...');
62957-
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion));
62956+
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch);
6295862957
core.info(`Successfully cached go to ${cachedDir}`);
6295962958
return cachedDir;
6296062959
});
@@ -62973,12 +62972,12 @@ function extractGoArchive(archivePath) {
6297362972
});
6297462973
}
6297562974
exports.extractGoArchive = extractGoArchive;
62976-
function getInfoFromManifest(versionSpec, stable, auth) {
62975+
function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch()) {
6297762976
return __awaiter(this, void 0, void 0, function* () {
6297862977
let info = null;
6297962978
const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
6298062979
core.info(`matching ${versionSpec}...`);
62981-
const rel = yield tc.findFromManifest(versionSpec, stable, releases);
62980+
const rel = yield tc.findFromManifest(versionSpec, stable, releases, arch);
6298262981
if (rel && rel.files.length > 0) {
6298362982
info = {};
6298462983
info.type = 'manifest';
@@ -62990,10 +62989,10 @@ function getInfoFromManifest(versionSpec, stable, auth) {
6299062989
});
6299162990
}
6299262991
exports.getInfoFromManifest = getInfoFromManifest;
62993-
function getInfoFromDist(versionSpec) {
62992+
function getInfoFromDist(versionSpec, arch) {
6299462993
return __awaiter(this, void 0, void 0, function* () {
6299562994
let version;
62996-
version = yield findMatch(versionSpec);
62995+
version = yield findMatch(versionSpec, arch);
6299762996
if (!version) {
6299862997
return null;
6299962998
}
@@ -63006,9 +63005,9 @@ function getInfoFromDist(versionSpec) {
6300663005
};
6300763006
});
6300863007
}
63009-
function findMatch(versionSpec) {
63008+
function findMatch(versionSpec, arch = os_1.default.arch()) {
6301063009
return __awaiter(this, void 0, void 0, function* () {
63011-
let archFilter = sys.getArch();
63010+
let archFilter = sys.getArch(arch);
6301263011
let platFilter = sys.getPlatform();
6301363012
let result;
6301463013
let match;
@@ -63139,6 +63138,7 @@ const cache_restore_1 = __nccwpck_require__(9517);
6313963138
const cache_utils_1 = __nccwpck_require__(1678);
6314063139
const child_process_1 = __importDefault(__nccwpck_require__(2081));
6314163140
const fs_1 = __importDefault(__nccwpck_require__(7147));
63141+
const os_1 = __importDefault(__nccwpck_require__(2037));
6314263142
function run() {
6314363143
return __awaiter(this, void 0, void 0, function* () {
6314463144
try {
@@ -63149,11 +63149,15 @@ function run() {
6314963149
const versionSpec = resolveVersionInput();
6315063150
const cache = core.getBooleanInput('cache');
6315163151
core.info(`Setup go version spec ${versionSpec}`);
63152+
let arch = core.getInput('architecture');
63153+
if (!arch) {
63154+
arch = os_1.default.arch();
63155+
}
6315263156
if (versionSpec) {
6315363157
let token = core.getInput('token');
6315463158
let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`;
6315563159
const checkLatest = core.getBooleanInput('check-latest');
63156-
const installDir = yield installer.getGo(versionSpec, checkLatest, auth);
63160+
const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch);
6315763161
core.addPath(path_1.default.join(installDir, 'bin'));
6315863162
core.info('Added go to the path');
6315963163
const version = installer.makeSemver(versionSpec);
@@ -63286,9 +63290,8 @@ function getPlatform() {
6328663290
return plat;
6328763291
}
6328863292
exports.getPlatform = getPlatform;
63289-
function getArch() {
63293+
function getArch(arch) {
6329063294
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
63291-
let arch = os.arch();
6329263295
// wants amd64, 386, arm64, armv61, ppc641e, s390x
6329363296
// currently not supported by runner but future proofed mapping
6329463297
switch (arch) {
@@ -63301,6 +63304,9 @@ function getArch() {
6330163304
case 'x32':
6330263305
arch = '386';
6330363306
break;
63307+
case 'arm':
63308+
arch = 'armv6l';
63309+
break;
6330463310
}
6330563311
return arch;
6330663312
}

0 commit comments

Comments
 (0)