Skip to content

Commit

Permalink
feat: Add support for different processor architectures (#518)
Browse files Browse the repository at this point in the history
ARM, ARM64
  • Loading branch information
steveteuber committed May 27, 2021
1 parent 65bdbf1 commit 6d30a88
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 311 deletions.
2 changes: 1 addition & 1 deletion __tests__/data/brew.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"hugo","full_name":"hugo","oldname":null,"aliases":[],"versioned_formulae":[],"desc":"Configurable static site generator","homepage":"https://gohugo.io/","versions":{"stable":"0.62.2","devel":null,"head":"HEAD","bottle":true},"revision":0,"version_scheme":0,"bottle":{"stable":{"rebuild":0,"cellar":":any_skip_relocation","prefix":"/usr/local","root_url":"https://homebrew.bintray.com/bottles","files":{"catalina":{"url":"https://homebrew.bintray.com/bottles/hugo-0.62.2.catalina.bottle.tar.gz","sha256":"354545c2c125e01a8860f83577fb4218d585fa8d38cd7f51e4228a149347fbcf"},"mojave":{"url":"https://homebrew.bintray.com/bottles/hugo-0.62.2.mojave.bottle.tar.gz","sha256":"9645b64fe6290c4c3b7591ef21139247f0fad6e49da1edd01665b3130a8f1d1a"},"high_sierra":{"url":"https://homebrew.bintray.com/bottles/hugo-0.62.2.high_sierra.bottle.tar.gz","sha256":"0ede4cbcc7536dd6b05107376637840356062273d734b4106be98b3d1732d50c"}}}},"keg_only":false,"bottle_disabled":false,"options":[],"build_dependencies":["go"],"dependencies":[],"recommended_dependencies":[],"optional_dependencies":[],"uses_from_macos":[],"requirements":[],"conflicts_with":[],"caveats":null,"installed":[],"linked_keg":null,"pinned":false,"outdated":false,"analytics":{"install":{"30d":{"hugo":24278,"hugo --HEAD":30},"90d":{"hugo":68639,"hugo --HEAD":80},"365d":{"hugo":223748,"hugo --HEAD":321}},"install_on_request":{"30d":{"hugo":23621,"hugo --HEAD":27},"90d":{"hugo":66676,"hugo --HEAD":74},"365d":{"hugo":215985,"hugo --HEAD":305}},"build_error":{"30d":{"hugo":0}}}}
{"name":"hugo","full_name":"hugo","tap":"homebrew/core","oldname":null,"aliases":[],"versioned_formulae":[],"desc":"Configurable static site generator","license":"Apache-2.0","homepage":"https://gohugo.io/","versions":{"stable":"0.83.1","head":"HEAD","bottle":true},"urls":{"stable":{"url":"https://github.com/gohugoio/hugo/archive/v0.83.1.tar.gz","tag":null,"revision":null}},"revision":0,"version_scheme":0,"bottle":{"stable":{"rebuild":0,"root_url":"https://ghcr.io/v2/homebrew/core","files":{"arm64_big_sur":{"cellar":":any_skip_relocation","url":"https://ghcr.io/v2/homebrew/core/hugo/blobs/sha256:f5997a1858e300787cd6e2e01ff8f87f0d3233f42af4becc040448ce06524d53","sha256":"f5997a1858e300787cd6e2e01ff8f87f0d3233f42af4becc040448ce06524d53"},"big_sur":{"cellar":":any_skip_relocation","url":"https://ghcr.io/v2/homebrew/core/hugo/blobs/sha256:32ad322954e9c2962849495c88c88e461d21a0a7d3bfa3aa4892ee34f569bf81","sha256":"32ad322954e9c2962849495c88c88e461d21a0a7d3bfa3aa4892ee34f569bf81"},"catalina":{"cellar":":any_skip_relocation","url":"https://ghcr.io/v2/homebrew/core/hugo/blobs/sha256:99078c665152420113fac08aaea7bdf2f8fe230696b724448bb9f2244cfdec55","sha256":"99078c665152420113fac08aaea7bdf2f8fe230696b724448bb9f2244cfdec55"},"mojave":{"cellar":":any_skip_relocation","url":"https://ghcr.io/v2/homebrew/core/hugo/blobs/sha256:a45ae895351a549639b40bdbb2a630e8a11ffb68d78a0aa7577faedce4c011d4","sha256":"a45ae895351a549639b40bdbb2a630e8a11ffb68d78a0aa7577faedce4c011d4"}}}},"keg_only":false,"bottle_disabled":false,"options":[],"build_dependencies":["go"],"dependencies":[],"recommended_dependencies":[],"optional_dependencies":[],"uses_from_macos":[],"requirements":[],"conflicts_with":[],"caveats":null,"installed":[],"linked_keg":null,"pinned":false,"outdated":false,"deprecated":false,"deprecation_date":null,"deprecation_reason":null,"disabled":false,"disable_date":null,"disable_reason":null,"analytics":{"install":{"30d":{"hugo":24137,"hugo --HEAD":16},"90d":{"hugo":61006,"hugo --HEAD":51},"365d":{"hugo":246915,"hugo --HEAD":273}},"install_on_request":{"30d":{"hugo":24100,"hugo --HEAD":16},"90d":{"hugo":60903,"hugo --HEAD":51},"365d":{"hugo":244317,"hugo --HEAD":266}},"build_error":{"30d":{"hugo":0}}},"generated_date":"2021-05-21"}
674 changes: 388 additions & 286 deletions __tests__/data/github.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions __tests__/get-arch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import getArch from '../src/get-arch';

describe('getArch', () => {
test('processor architecture', () => {
expect(getArch('x64')).toBe('64bit');
expect(getArch('arm')).toBe('ARM');
expect(getArch('arm64')).toBe('ARM64');
});

test('exception', () => {
expect(() => {
getArch('mips');
}).toThrowError('mips is not supported');
});
});
16 changes: 9 additions & 7 deletions __tests__/get-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ describe('getURL()', () => {
const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`;
const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`;
const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`;
const urlMacOSExtended = `${baseURL}/hugo_extended_0.58.2_macOS-64bit.tar.gz`;
const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`;
expect(getURL('Linux', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', 'true', '0.58.2')).not.toBe(urlLinux);
expect(getURL('MyOS', 'false', '0.58.2')).not.toBe(urlLinux);
expect(getURL('Linux', 'false', '0.58.1')).not.toBe(urlLinux);
expect(getURL('Linux', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('Windows', 'false', '0.58.2')).toBe(urlWindows);
expect(getURL('Linux', '64bit', 'false', '0.58.2')).toBe(urlLinux);
expect(getURL('Linux', '64bit', 'true', '0.58.2')).not.toBe(urlLinux);
expect(getURL('MyOS', '64bit', 'false', '0.58.2')).not.toBe(urlLinux);
expect(getURL('Linux', '64bit', 'false', '0.58.1')).not.toBe(urlLinux);
expect(getURL('Linux', '64bit', 'true', '0.58.2')).toBe(urlLinuxExtended);
expect(getURL('macOS', '64bit', 'false', '0.58.2')).toBe(urlMacOS);
expect(getURL('macOS', '64bit', 'true', '0.58.2')).toBe(urlMacOSExtended);
expect(getURL('Windows', '64bit', 'false', '0.58.2')).toBe(urlWindows);
});
});
8 changes: 4 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Integration testing run()', () => {
process.env['INPUT_HUGO-VERSION'] = testVersion;
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(`Hugo Static Site Generator v${testVersion}`);
expect(result.output).toMatch(`hugo v${testVersion}`);
});

test('succeed in installing a custom extended version', async () => {
Expand All @@ -36,7 +36,7 @@ describe('Integration testing run()', () => {
process.env['INPUT_EXTENDED'] = 'true';
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(`Hugo Static Site Generator v${testVersion}`);
expect(result.output).toMatch(`hugo v${testVersion}`);
expect(result.output).toMatch(`extended`);
});

Expand All @@ -46,7 +46,7 @@ describe('Integration testing run()', () => {
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(`Hugo Static Site Generator v${Tool.TestVersionLatest}`);
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
});

test('succeed in installing the latest extended version', async () => {
Expand All @@ -56,7 +56,7 @@ describe('Integration testing run()', () => {
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
const result: main.ActionResult = await main.run();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(`Hugo Static Site Generator v${Tool.TestVersionLatest}`);
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
expect(result.output).toMatch(`extended`);
});

Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export enum Tool {
Repo = 'hugo',
CmdName = 'hugo',
CmdOptVersion = 'version',
TestVersionLatest = '0.62.2',
TestVersionSpec = '0.61.0'
TestVersionLatest = '0.83.1',
TestVersionSpec = '0.82.1'
}

export enum Action {
Expand Down
12 changes: 12 additions & 0 deletions src/get-arch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function getArch(arch: string): string {
switch (arch) {
case 'x64':
return '64bit';
case 'arm':
return 'ARM';
case 'arm64':
return 'ARM64';
default:
throw new Error(`${arch} is not supported`);
}
}
17 changes: 9 additions & 8 deletions src/get-os.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export default function getOS(platform: string): string {
if (platform === 'linux') {
return 'Linux';
} else if (platform === 'darwin') {
return 'macOS';
} else if (platform === 'win32') {
return 'Windows';
} else {
throw new Error(`${platform} is not supported`);
switch (platform) {
case 'linux':
return 'Linux';
case 'darwin':
return 'macOS';
case 'win32':
return 'Windows';
default:
throw new Error(`${platform} is not supported`);
}
}
9 changes: 7 additions & 2 deletions src/get-url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default function getURL(os: string, extended: string, version: string): string {
export default function getURL(
os: string,
arch: string,
extended: string,
version: string
): string {
const extendedStr = (extended: string): string => {
if (extended === 'true') {
return 'extended_';
Expand All @@ -17,7 +22,7 @@ export default function getURL(os: string, extended: string, version: string): s
}
};

const hugoName = `hugo_${extendedStr(extended)}${version}_${os}-64bit`;
const hugoName = `hugo_${extendedStr(extended)}${version}_${os}-${arch}`;
const baseURL = 'https://github.com/gohugoio/hugo/releases/download';
const url = `${baseURL}/v${version}/${hugoName}.${ext(os)}`;

Expand Down
6 changes: 5 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as io from '@actions/io';
import getOS from './get-os';
import getArch from './get-arch';
import getURL from './get-url';
import * as path from 'path';
import {Tool, Action} from './constants';
Expand Down Expand Up @@ -49,7 +50,10 @@ export async function installer(version: string): Promise<void> {
const osName: string = getOS(process.platform);
core.debug(`Operating System: ${osName}`);

const toolURL: string = getURL(osName, extended, version);
const archName: string = getArch(process.arch);
core.debug(`Processor Architecture: ${archName}`);

const toolURL: string = getURL(osName, archName, extended, version);
core.debug(`toolURL: ${toolURL}`);

const workDir = await createWorkDir();
Expand Down

0 comments on commit 6d30a88

Please sign in to comment.