From 2c62681dc97398844ab86571ae9414d21c6be68d Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 11:05:52 +0200 Subject: [PATCH 01/14] Add support for arm32 go arch --- __tests__/setup-go.test.ts | 54 ++++++++++++++++++++++++++++++++------ action.yml | 2 ++ dist/setup/index.js | 43 +++++++++++++++++------------- src/installer.ts | 52 +++++++++++++++++++++++------------- 4 files changed, 107 insertions(+), 44 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 9e390755d..05f4eb55b 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -7,6 +7,7 @@ import osm from 'os'; import path from 'path'; import * as main from '../src/main'; import * as im from '../src/installer'; +import * as sys from '../src/system'; let goJsonData = require('./data/golang-dl.json'); let matchers = require('../matchers.json'); @@ -41,6 +42,7 @@ describe('setup-go', () => { let mkdirpSpy: jest.SpyInstance; let execSpy: jest.SpyInstance; let getManifestSpy: jest.SpyInstance; + let sysGetArchSpy: jest.SpyInstance; beforeAll(async () => { process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible) @@ -64,6 +66,7 @@ describe('setup-go', () => { archSpy = jest.spyOn(osm, 'arch'); archSpy.mockImplementation(() => os['arch']); execSpy = jest.spyOn(cp, 'execSync'); + sysGetArchSpy = jest.spyOn(sys, 'getArch'); // switch path join behaviour based on set os.platform joinSpy = jest.spyOn(path, 'join'); @@ -129,7 +132,7 @@ describe('setup-go', () => { it('can find 1.9.7 from manifest on osx', async () => { os.platform = 'darwin'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -142,7 +145,7 @@ describe('setup-go', () => { it('can find 1.9 from manifest on linux', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -155,7 +158,7 @@ describe('setup-go', () => { it('can find 1.9 from manifest on windows', async () => { os.platform = 'win32'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -367,7 +370,7 @@ describe('setup-go', () => { it('does not find a version that does not exist', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); inputs['go-version'] = '9.99.9'; @@ -381,7 +384,7 @@ describe('setup-go', () => { it('downloads a version from a manifest match', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); let versionSpec = '1.12.16'; @@ -418,7 +421,7 @@ describe('setup-go', () => { it('downloads a major and minor from a manifest match', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); let versionSpec = '1.12'; @@ -453,7 +456,7 @@ describe('setup-go', () => { expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); }); - it('falls back to a version from node dist', async () => { + it('falls back to a version from go dist', async () => { os.platform = 'linux'; os.arch = 'x64'; @@ -694,7 +697,7 @@ describe('setup-go', () => { it('check latest version and install it from manifest', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'x64'); const versionSpec = '1.17'; const patchVersion = '1.17.6'; @@ -879,5 +882,40 @@ exclude example.com/thismodule v1.3.0 `::error::The specified go version file at: go.mod does not exist${osm.EOL}` ); }); + + it('acquires specified architecture of go', async () => { + for (const {arch, version, osSpec} of [ + {arch: 'amd64', version: '1.13.7', osSpec: 'linux'}, + {arch: 'armv6l', version: '1.12.2', osSpec: 'linux'} + ]) { + os.platform = osSpec; + os.arch = arch; + + const fileExtension = os.platform === 'win32' ? 'zip' : 'tar.gz'; + + const platform = os.platform === 'win32' ? 'win' : os.platform; + + inputs['go-version'] = version; + inputs['architecture'] = arch; + + let expectedUrl = + platform === 'win32' + ? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}` + : `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`; + + // ... but not in the local cache + findSpy.mockImplementation(() => ''); + + dlSpy.mockImplementation(async () => '/some/temp/path'); + let toolPath = path.normalize(`/cache/go/${version}/${arch}`); + cacheSpy.mockImplementation(async () => toolPath); + + await main.run(); + + expect(logSpy).toHaveBeenCalledWith( + `Acquiring go${version} from ${expectedUrl}` + ); + } + }, 100000); }); }); diff --git a/action.yml b/action.yml index a8d7548f1..5310a111f 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,8 @@ inputs: default: false cache-dependency-path: description: 'Used to specify the path to a dependency file - go.sum' + architecture: + description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.' outputs: go-version: description: 'The installed Go version. Useful when given a version range as input.' diff --git a/dist/setup/index.js b/dist/setup/index.js index f598dfd96..bac12fd75 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62858,13 +62858,12 @@ const httpm = __importStar(__nccwpck_require__(6255)); const sys = __importStar(__nccwpck_require__(4300)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); -function getGo(versionSpec, checkLatest, auth) { +function getGo(versionSpec, checkLatest, auth, arch = sys.getArch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os_1.default.platform(); - let osArch = os_1.default.arch(); if (checkLatest) { core.info('Attempting to resolve the latest version from the manifest...'); - const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth); + const resolvedVersion = yield resolveVersionFromManifest(versionSpec, true, auth, arch); if (resolvedVersion) { versionSpec = resolvedVersion; core.info(`Resolved as '${versionSpec}'`); @@ -62888,9 +62887,9 @@ function getGo(versionSpec, checkLatest, auth) { // Try download from internal distribution (popular versions only) // try { - info = yield getInfoFromManifest(versionSpec, true, auth); + info = yield getInfoFromManifest(versionSpec, true, auth, arch); if (info) { - downloadPath = yield installGoVersion(info, auth); + downloadPath = yield installGoVersion(info, auth, arch); } else { core.info('Not found in manifest. Falling back to download directly from Go'); @@ -62911,13 +62910,13 @@ function getGo(versionSpec, checkLatest, auth) { // Download from storage.googleapis.com // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec); + info = yield getInfoFromDist(versionSpec, arch); if (!info) { - throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); + throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); } try { core.info('Install from dist'); - downloadPath = yield installGoVersion(info, undefined); + downloadPath = yield installGoVersion(info, undefined, arch); } catch (err) { throw new Error(`Failed to download version ${versionSpec}: ${err}`); @@ -62927,10 +62926,10 @@ function getGo(versionSpec, checkLatest, auth) { }); } exports.getGo = getGo; -function resolveVersionFromManifest(versionSpec, stable, auth) { +function resolveVersionFromManifest(versionSpec, stable, auth, arch) { return __awaiter(this, void 0, void 0, function* () { try { - const info = yield getInfoFromManifest(versionSpec, stable, auth); + const info = yield getInfoFromManifest(versionSpec, stable, auth, arch); return info === null || info === void 0 ? void 0 : info.resolvedVersion; } catch (err) { @@ -62939,7 +62938,7 @@ function resolveVersionFromManifest(versionSpec, stable, auth) { } }); } -function installGoVersion(info, auth) { +function installGoVersion(info, auth, arch) { return __awaiter(this, void 0, void 0, function* () { core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); // Windows requires that we keep the extension (.zip) for extraction @@ -62954,7 +62953,7 @@ function installGoVersion(info, auth) { extPath = path.join(extPath, 'go'); } core.info('Adding to the cache ...'); - const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion)); + const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch); core.info(`Successfully cached go to ${cachedDir}`); return cachedDir; }); @@ -62973,12 +62972,12 @@ function extractGoArchive(archivePath) { }); } exports.extractGoArchive = extractGoArchive; -function getInfoFromManifest(versionSpec, stable, auth) { +function getInfoFromManifest(versionSpec, stable, auth, arch = sys.getArch()) { return __awaiter(this, void 0, void 0, function* () { let info = null; const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth, 'main'); core.info(`matching ${versionSpec}...`); - const rel = yield tc.findFromManifest(versionSpec, stable, releases); + const rel = yield tc.findFromManifest(versionSpec, stable, releases, arch); if (rel && rel.files.length > 0) { info = {}; info.type = 'manifest'; @@ -62990,10 +62989,10 @@ function getInfoFromManifest(versionSpec, stable, auth) { }); } exports.getInfoFromManifest = getInfoFromManifest; -function getInfoFromDist(versionSpec) { +function getInfoFromDist(versionSpec, arch) { return __awaiter(this, void 0, void 0, function* () { let version; - version = yield findMatch(versionSpec); + version = yield findMatch(versionSpec, arch); if (!version) { return null; } @@ -63006,9 +63005,9 @@ function getInfoFromDist(versionSpec) { }; }); } -function findMatch(versionSpec) { +function findMatch(versionSpec, arch = sys.getArch()) { return __awaiter(this, void 0, void 0, function* () { - let archFilter = sys.getArch(); + let archFilter = translateArchToDistUrl(arch); let platFilter = sys.getPlatform(); let result; let match; @@ -63088,6 +63087,14 @@ function parseGoVersionFile(versionFilePath) { return contents.trim(); } exports.parseGoVersionFile = parseGoVersionFile; +function translateArchToDistUrl(arch) { + switch (arch) { + case 'arm': + return 'armv6l'; + default: + return arch; + } +} /***/ }), diff --git a/src/installer.ts b/src/installer.ts index 58c94285e..4e69bd9d4 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -32,17 +32,18 @@ export interface IGoVersionInfo { export async function getGo( versionSpec: string, checkLatest: boolean, - auth: string | undefined + auth: string | undefined, + arch = sys.getArch() ) { 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; @@ -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 { 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 { 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 { export async function getInfoFromManifest( versionSpec: string, stable: boolean, - auth: string | undefined + auth: string | undefined, + arch = sys.getArch() ): Promise { 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 = {}; @@ -197,10 +202,11 @@ export async function getInfoFromManifest( } async function getInfoFromDist( - versionSpec: string + versionSpec: string, + arch: string ): Promise { 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 = sys.getArch() ): Promise { - let archFilter = sys.getArch(); + let archFilter = translateArchToDistUrl(arch); let platFilter = sys.getPlatform(); let result: IGoVersion | undefined; @@ -316,3 +323,12 @@ export function parseGoVersionFile(versionFilePath: string): string { return contents.trim(); } + +function translateArchToDistUrl(arch: string): string { + switch (arch) { + case 'arm': + return 'armv6l'; + default: + return arch; + } +} From 2f5755bd367420833d742d4b375cd102442ba4db Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 12:22:05 +0200 Subject: [PATCH 02/14] Expand advanced documentation --- docs/adrs/0001-architecture.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docs/adrs/0001-architecture.md diff --git a/docs/adrs/0001-architecture.md b/docs/adrs/0001-architecture.md new file mode 100644 index 000000000..74e03a71e --- /dev/null +++ b/docs/adrs/0001-architecture.md @@ -0,0 +1,16 @@ +## Architecture + +You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm`, `arm64`, `amd64` (not all of the architectures are available on all platforms). + +```yaml +jobs: + build: + runs-on: ubuntu-latest + name: Go sample + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '18' + architecture: 'amd64' # optional, x64 or x86. If not specified, x64 will be used by default +``` \ No newline at end of file From c5cf47b1d59fcdc392ea5e9f4cf338f1b39db33a Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 12:57:22 +0200 Subject: [PATCH 03/14] Default to os.arch when no arch provided --- __tests__/setup-go.test.ts | 38 +++++++++++++++++++------------------- dist/setup/index.js | 4 ++-- src/installer.ts | 4 ++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 05f4eb55b..ffe17e25a 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -132,7 +132,7 @@ describe('setup-go', () => { it('can find 1.9.7 from manifest on osx', async () => { os.platform = 'darwin'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -145,7 +145,7 @@ describe('setup-go', () => { it('can find 1.9 from manifest on linux', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -158,7 +158,7 @@ describe('setup-go', () => { it('can find 1.9 from manifest on windows', async () => { os.platform = 'win32'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken'); expect(match).toBeDefined(); @@ -325,13 +325,13 @@ describe('setup-go', () => { it('downloads a version not in the cache', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); inputs['go-version'] = '1.13.1'; findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(() => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.0/x64'); + let toolPath = path.normalize('/cache/go/1.13.0/amd64'); extractTarSpy.mockImplementation(() => '/some/other/temp/path'); cacheSpy.mockImplementation(() => toolPath); await main.run(); @@ -345,7 +345,7 @@ describe('setup-go', () => { it('downloads a version not in the cache (windows)', async () => { os.platform = 'win32'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); inputs['go-version'] = '1.13.1'; process.env['RUNNER_TEMP'] = 'C:\\temp\\'; @@ -354,7 +354,7 @@ describe('setup-go', () => { dlSpy.mockImplementation(() => 'C:\\temp\\some\\path'); extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path'); - let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64'); + let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\amd64'); cacheSpy.mockImplementation(() => toolPath); await main.run(); @@ -370,7 +370,7 @@ describe('setup-go', () => { it('does not find a version that does not exist', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; inputs['go-version'] = '9.99.9'; @@ -384,7 +384,7 @@ describe('setup-go', () => { it('downloads a version from a manifest match', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; let versionSpec = '1.12.16'; @@ -421,7 +421,7 @@ describe('setup-go', () => { it('downloads a major and minor from a manifest match', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; let versionSpec = '1.12'; @@ -458,7 +458,7 @@ describe('setup-go', () => { it('falls back to a version from go dist', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); let versionSpec = '1.12.14'; @@ -466,13 +466,13 @@ describe('setup-go', () => { inputs['token'] = 'faketoken'; let expectedUrl = - 'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz'; + 'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-amd64.tar.gz'; // ... but not in the local cache findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.12.14/x64'); + let toolPath = path.normalize('/cache/go/1.12.14/amd64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); @@ -496,7 +496,7 @@ describe('setup-go', () => { it('reports a failed download', async () => { let errMsg = 'unhandled download message'; os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); inputs['go-version'] = '1.13.1'; @@ -697,7 +697,7 @@ describe('setup-go', () => { it('check latest version and install it from manifest', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'x64'); + os.arch = 'x64'; const versionSpec = '1.17'; const patchVersion = '1.17.6'; @@ -735,7 +735,7 @@ describe('setup-go', () => { it('fallback to dist if version is not found in manifest', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); let versionSpec = '1.13'; @@ -748,7 +748,7 @@ describe('setup-go', () => { findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.7/x64'); + let toolPath = path.normalize('/cache/go/1.13.7/amd64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); @@ -772,7 +772,7 @@ describe('setup-go', () => { it('fallback to dist if manifest is not available', async () => { os.platform = 'linux'; - os.arch = 'x64'; + sysGetArchSpy.mockImplementationOnce(() => 'amd64'); let versionSpec = '1.13'; @@ -790,7 +790,7 @@ describe('setup-go', () => { }); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.7/x64'); + let toolPath = path.normalize('/cache/go/1.13.7/amd64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); diff --git a/dist/setup/index.js b/dist/setup/index.js index bac12fd75..1d12b40d1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62858,7 +62858,7 @@ const httpm = __importStar(__nccwpck_require__(6255)); const sys = __importStar(__nccwpck_require__(4300)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); -function getGo(versionSpec, checkLatest, auth, arch = sys.getArch()) { +function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os_1.default.platform(); if (checkLatest) { @@ -62972,7 +62972,7 @@ function extractGoArchive(archivePath) { }); } exports.extractGoArchive = extractGoArchive; -function getInfoFromManifest(versionSpec, stable, auth, arch = sys.getArch()) { +function getInfoFromManifest(versionSpec, stable, auth, arch = os_1.default.arch()) { return __awaiter(this, void 0, void 0, function* () { let info = null; const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth, 'main'); diff --git a/src/installer.ts b/src/installer.ts index 4e69bd9d4..58e33dba6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -33,7 +33,7 @@ export async function getGo( versionSpec: string, checkLatest: boolean, auth: string | undefined, - arch = sys.getArch() + arch = os.arch() ) { let osPlat: string = os.platform(); @@ -178,7 +178,7 @@ export async function getInfoFromManifest( versionSpec: string, stable: boolean, auth: string | undefined, - arch = sys.getArch() + arch = os.arch() ): Promise { let info: IGoVersionInfo | null = null; const releases = await tc.getManifestFromRepo( From 93cf84c15c48867d5fbf0050a43880b20a4149db Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 14:13:08 +0200 Subject: [PATCH 04/14] Fix arch conversion --- dist/setup/index.js | 18 ++++++------------ src/installer.ts | 13 ++----------- src/system.ts | 6 ++++-- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 1d12b40d1..dfbf3b3af 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63005,9 +63005,9 @@ function getInfoFromDist(versionSpec, arch) { }; }); } -function findMatch(versionSpec, arch = sys.getArch()) { +function findMatch(versionSpec, arch = os_1.default.arch()) { return __awaiter(this, void 0, void 0, function* () { - let archFilter = translateArchToDistUrl(arch); + let archFilter = sys.getArch(arch); let platFilter = sys.getPlatform(); let result; let match; @@ -63087,14 +63087,6 @@ function parseGoVersionFile(versionFilePath) { return contents.trim(); } exports.parseGoVersionFile = parseGoVersionFile; -function translateArchToDistUrl(arch) { - switch (arch) { - case 'arm': - return 'armv6l'; - default: - return arch; - } -} /***/ }), @@ -63293,9 +63285,8 @@ function getPlatform() { return plat; } exports.getPlatform = getPlatform; -function getArch() { +function getArch(arch) { // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'. - let arch = os.arch(); // wants amd64, 386, arm64, armv61, ppc641e, s390x // currently not supported by runner but future proofed mapping switch (arch) { @@ -63308,6 +63299,9 @@ function getArch() { case 'x32': arch = '386'; break; + case 'arm': + arch = 'armv6l'; + break; } return arch; } diff --git a/src/installer.ts b/src/installer.ts index 58e33dba6..112ba46c9 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -223,9 +223,9 @@ async function getInfoFromDist( export async function findMatch( versionSpec: string, - arch = sys.getArch() + arch = os.arch() ): Promise { - let archFilter = translateArchToDistUrl(arch); + let archFilter = sys.getArch(arch); let platFilter = sys.getPlatform(); let result: IGoVersion | undefined; @@ -323,12 +323,3 @@ export function parseGoVersionFile(versionFilePath: string): string { return contents.trim(); } - -function translateArchToDistUrl(arch: string): string { - switch (arch) { - case 'arm': - return 'armv6l'; - default: - return arch; - } -} diff --git a/src/system.ts b/src/system.ts index 6973f9998..3164a21b2 100644 --- a/src/system.ts +++ b/src/system.ts @@ -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; From 54f0af7c59ff3b36a7ceeb80ecc1b6b0231efca3 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 14:19:12 +0200 Subject: [PATCH 05/14] Revert unit tests changes --- __tests__/setup-go.test.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index ffe17e25a..9cf67c883 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -7,7 +7,6 @@ import osm from 'os'; import path from 'path'; import * as main from '../src/main'; import * as im from '../src/installer'; -import * as sys from '../src/system'; let goJsonData = require('./data/golang-dl.json'); let matchers = require('../matchers.json'); @@ -42,7 +41,6 @@ describe('setup-go', () => { let mkdirpSpy: jest.SpyInstance; let execSpy: jest.SpyInstance; let getManifestSpy: jest.SpyInstance; - let sysGetArchSpy: jest.SpyInstance; beforeAll(async () => { process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible) @@ -66,7 +64,6 @@ describe('setup-go', () => { archSpy = jest.spyOn(osm, 'arch'); archSpy.mockImplementation(() => os['arch']); execSpy = jest.spyOn(cp, 'execSync'); - sysGetArchSpy = jest.spyOn(sys, 'getArch'); // switch path join behaviour based on set os.platform joinSpy = jest.spyOn(path, 'join'); @@ -325,7 +322,7 @@ describe('setup-go', () => { it('downloads a version not in the cache', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; inputs['go-version'] = '1.13.1'; @@ -345,7 +342,7 @@ describe('setup-go', () => { it('downloads a version not in the cache (windows)', async () => { os.platform = 'win32'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; inputs['go-version'] = '1.13.1'; process.env['RUNNER_TEMP'] = 'C:\\temp\\'; @@ -458,7 +455,7 @@ describe('setup-go', () => { it('falls back to a version from go dist', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; let versionSpec = '1.12.14'; @@ -496,7 +493,7 @@ describe('setup-go', () => { it('reports a failed download', async () => { let errMsg = 'unhandled download message'; os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; inputs['go-version'] = '1.13.1'; @@ -735,7 +732,7 @@ describe('setup-go', () => { it('fallback to dist if version is not found in manifest', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; let versionSpec = '1.13'; @@ -772,7 +769,7 @@ describe('setup-go', () => { it('fallback to dist if manifest is not available', async () => { os.platform = 'linux'; - sysGetArchSpy.mockImplementationOnce(() => 'amd64'); + os.arch = 'x64'; let versionSpec = '1.13'; From 1ba131bfed2b99d0aad7f3e2e62a0b06fd9f662a Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 15:50:48 +0200 Subject: [PATCH 06/14] Update unit tests --- __tests__/setup-go.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 9cf67c883..590c78c73 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -328,7 +328,7 @@ describe('setup-go', () => { findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(() => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.0/amd64'); + let toolPath = path.normalize('/cache/go/1.13.0/x64'); extractTarSpy.mockImplementation(() => '/some/other/temp/path'); cacheSpy.mockImplementation(() => toolPath); await main.run(); @@ -351,7 +351,7 @@ describe('setup-go', () => { dlSpy.mockImplementation(() => 'C:\\temp\\some\\path'); extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path'); - let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\amd64'); + let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64'); cacheSpy.mockImplementation(() => toolPath); await main.run(); @@ -463,13 +463,13 @@ describe('setup-go', () => { inputs['token'] = 'faketoken'; let expectedUrl = - 'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-amd64.tar.gz'; + 'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz'; // ... but not in the local cache findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.12.14/amd64'); + let toolPath = path.normalize('/cache/go/1.12.14/x64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); @@ -745,7 +745,7 @@ describe('setup-go', () => { findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.7/amd64'); + let toolPath = path.normalize('/cache/go/1.13.7/x64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); From bd46f3f483ddabc1b28726231c20344c26d0de36 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 8 Aug 2022 16:24:21 +0200 Subject: [PATCH 07/14] Update e2e test local cache version --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 12c711e3f..aaa2f41c9 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, windows-latest, ubuntu-latest] - go: [1.12, 1.13, 1.14] + go: [1.17, 1.18, 1.19] steps: - name: Checkout uses: actions/checkout@v3 From 5bd17a0f4509ee2802b873170d3e0ed208e731b1 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 9 Aug 2022 14:50:33 +0200 Subject: [PATCH 08/14] Update amd64 path to x64 --- __tests__/setup-go.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 590c78c73..4378b0ec5 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -787,7 +787,7 @@ describe('setup-go', () => { }); dlSpy.mockImplementation(async () => '/some/temp/path'); - let toolPath = path.normalize('/cache/go/1.13.7/amd64'); + let toolPath = path.normalize('/cache/go/1.13.7/x64'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); cacheSpy.mockImplementation(async () => toolPath); From 36f56fdbb18b74c2c8a8bf1fba7e6a7b556a89c0 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 10 Aug 2022 11:02:49 +0200 Subject: [PATCH 09/14] Update readme --- docs/adrs/0001-architecture.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adrs/0001-architecture.md b/docs/adrs/0001-architecture.md index 74e03a71e..a8b740f3e 100644 --- a/docs/adrs/0001-architecture.md +++ b/docs/adrs/0001-architecture.md @@ -1,6 +1,6 @@ ## Architecture -You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm`, `arm64`, `amd64` (not all of the architectures are available on all platforms). +You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected by specifying a value for `architecture` input variable. Values are `x86`, `x64`, `arm`, `arm64`, `amd64` (not all of the architectures are available on all platforms). ```yaml jobs: From 1286293c40a7c8cf2efedf1e5c926d682162a37f Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 10 Aug 2022 19:29:21 +0200 Subject: [PATCH 10/14] Remove advanced docs --- docs/adrs/0001-architecture.md | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 docs/adrs/0001-architecture.md diff --git a/docs/adrs/0001-architecture.md b/docs/adrs/0001-architecture.md deleted file mode 100644 index a8b740f3e..000000000 --- a/docs/adrs/0001-architecture.md +++ /dev/null @@ -1,16 +0,0 @@ -## Architecture - -You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected by specifying a value for `architecture` input variable. Values are `x86`, `x64`, `arm`, `arm64`, `amd64` (not all of the architectures are available on all platforms). - -```yaml -jobs: - build: - runs-on: ubuntu-latest - name: Go sample - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: '18' - architecture: 'amd64' # optional, x64 or x86. If not specified, x64 will be used by default -``` \ No newline at end of file From 1776f915f896223c1e0947379df46debacdfb9b5 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 10 Aug 2022 20:01:22 +0200 Subject: [PATCH 11/14] Add get input in main --- dist/setup/index.js | 5 +++-- src/installer.ts | 2 +- src/main.ts | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index dfbf3b3af..b1434bdb4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62874,7 +62874,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { } // check cache let toolPath; - 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}`); @@ -63148,11 +63148,12 @@ function run() { const versionSpec = resolveVersionInput(); const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); + const arch = core.getInput('architecture'); if (versionSpec) { let token = core.getInput('token'); let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; const checkLatest = core.getBooleanInput('check-latest'); - const installDir = yield installer.getGo(versionSpec, checkLatest, auth); + const installDir = yield installer.getGo(versionSpec, checkLatest, auth, arch); core.addPath(path_1.default.join(installDir, 'bin')); core.info('Added go to the path'); const version = installer.makeSemver(versionSpec); diff --git a/src/installer.ts b/src/installer.ts index 112ba46c9..6335dbdc8 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -55,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}`); diff --git a/src/main.ts b/src/main.ts index 0649dec5b..b7fb133a0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,12 +19,19 @@ export async function run() { const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); + const arch = core.getInput('architecture'); + 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'); From 61dd67fbf505996f2201bbcd6e37e9b4327c56d2 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 10 Aug 2022 20:11:20 +0200 Subject: [PATCH 12/14] Add default value if arch is null --- dist/setup/index.js | 4 +++- src/main.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b1434bdb4..7b3f5dc95 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63138,6 +63138,7 @@ const cache_restore_1 = __nccwpck_require__(9517); const cache_utils_1 = __nccwpck_require__(1678); const child_process_1 = __importDefault(__nccwpck_require__(2081)); const fs_1 = __importDefault(__nccwpck_require__(7147)); +const os_1 = __importDefault(__nccwpck_require__(2037)); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -63148,7 +63149,8 @@ function run() { const versionSpec = resolveVersionInput(); const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); - const arch = core.getInput('architecture'); + let arch = core.getInput('architecture'); + arch = arch ? arch : os_1.default.arch(); if (versionSpec) { let token = core.getInput('token'); let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; diff --git a/src/main.ts b/src/main.ts index b7fb133a0..e4062df70 100644 --- a/src/main.ts +++ b/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,7 +20,8 @@ export async function run() { const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); - const arch = core.getInput('architecture'); + let arch = core.getInput('architecture'); + arch = arch ? arch : os.arch(); if (versionSpec) { let token = core.getInput('token'); From 8f4adae408b298ddfda407938e2e35063a3ef017 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 10 Aug 2022 20:44:17 +0200 Subject: [PATCH 13/14] Change condition --- dist/setup/index.js | 4 +++- src/main.ts | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 7b3f5dc95..08d77d5fd 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63150,7 +63150,9 @@ function run() { const cache = core.getBooleanInput('cache'); core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); - arch = arch ? arch : os_1.default.arch(); + if (!arch) { + arch = os_1.default.arch(); + } if (versionSpec) { let token = core.getInput('token'); let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; diff --git a/src/main.ts b/src/main.ts index e4062df70..8648d4def 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,10 @@ export async function run() { core.info(`Setup go version spec ${versionSpec}`); let arch = core.getInput('architecture'); - arch = arch ? arch : os.arch(); + + if (!arch) { + arch = os.arch(); + } if (versionSpec) { let token = core.getInput('token'); From 2105c5b196a257987df53c5ab5b2129f28d423ea Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 12 Aug 2022 09:41:24 +0200 Subject: [PATCH 14/14] Add architecture e2e --- .github/workflows/versions.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index aaa2f41c9..3c74bd41d 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -107,3 +107,20 @@ jobs: - name: verify go run: __tests__/verify-go.sh ${{ matrix.go }} shell: bash + + architecture: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + go-version: [1.16, 1.17] + steps: + - uses: actions/checkout@v3 + - name: Setup Go and check latest + uses: ./ + with: + go-version: ${{ matrix.go-version }} + architecture: x64 + - name: Verify Go + run: go version \ No newline at end of file