Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-608) Fix package url for v0.102.0 & v0.103.0 #609

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 115 additions & 9 deletions __tests__/get-arch.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,121 @@
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');
const groups = [
{
condition: 'when hugo version < 0.102.0',
conventions: {
arch: {
darwinUniversal: false,
dropped32BitSupport: false,
standardizedNaming: false,
},
os: {
renamedMacOS: false,
downcasedAll: false
}
},
tests: [
{ arch: 'x64', os: 'linux', expected: '64bit' },
{ arch: 'x64', os: 'macOS', expected: '64bit' },
{ arch: 'x64', os: 'windows', expected: '64bit' },
{ arch: 'arm', os: 'linux', expected: 'ARM' },
{ arch: 'arm', os: 'macOS', expected: 'ARM' },
{ arch: 'arm', os: 'windows', expected: 'ARM' },
{ arch: 'arm64', os: 'linux', expected: 'ARM64' },
{ arch: 'arm64', os: 'macOS', expected: 'ARM64' },
{ arch: 'arm64', os: 'windows', expected: 'ARM64' },
]
},
{
michaeltlombardi marked this conversation as resolved.
Show resolved Hide resolved
condition: 'when hugo version === 0.102.z',
conventions: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: false,
},
os: {
renamedMacOS: true,
downcasedAll: false
}
},
tests: [
{ arch: 'x64', os: 'linux', expected: '64bit' },
{ arch: 'x64', os: 'macOS', expected: 'universal' },
{ arch: 'x64', os: 'windows', expected: '64bit' },
{ arch: 'arm', os: 'linux', throws: true },
{ arch: 'arm', os: 'macOS', expected: 'universal' },
{ arch: 'arm', os: 'windows', throws: true },
{ arch: 'arm64', os: 'linux', expected: 'ARM64' },
{ arch: 'arm64', os: 'macOS', expected: 'universal' },
{ arch: 'arm64', os: 'windows', expected: 'ARM64' },
]
},
{
michaeltlombardi marked this conversation as resolved.
Show resolved Hide resolved
condition: 'when hugo version >= 0.103.0',
conventions: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: true,
},
os: {
renamedMacOS: true,
downcasedAll: true
}
},
tests: [
{ arch: 'x64', os: 'linux', expected: 'amd64' },
{ arch: 'x64', os: 'macOS', expected: 'universal' },
{ arch: 'x64', os: 'windows', expected: 'amd64' },
{ arch: 'arm', os: 'linux', throws: true },
{ arch: 'arm', os: 'macOS', expected: 'universal' },
{ arch: 'arm', os: 'windows', throws: true },
{ arch: 'arm64', os: 'linux', expected: 'arm64' },
{ arch: 'arm64', os: 'macOS', expected: 'universal' },
{ arch: 'arm64', os: 'windows', expected: 'arm64' },
]
},
{
condition: 'when the architecture is unsupported for the action',
conventions: {
arch: {
darwinUniversal: false,
dropped32BitSupport: false,
standardizedNaming: false,
},
os: {
renamedMacOS: false,
downcasedAll: false
}
},
tests: [
{ arch: 'mips', os: 'linux', throws: true}
]
}
].map(function (group) {
group.tests = group.tests.map(function (example) {
return Object.assign(example, {
toString: function () {
let name = `${example.os} on ${example.arch} `
name += example?.throws ? 'throws as not supported' : `returns ${example.expected}`
return name;
}
});
})
return Object.assign(group, { toString: function () { return group.condition } });
});

test('exception', () => {
expect(() => {
getArch('mips');
}).toThrowError('mips is not supported');
});
describe.each(groups)('%s', ({ conventions, tests }) => {
test.each(tests)('%s', ({ arch, os, throws, expected }) => {
if (throws) {
expect(() => {
getArch(arch, os, conventions)
}).toThrow(`${arch} is not supported`);
} else {
expect(getArch(arch, os, conventions)).toBe(expected);
}
})
})
});
57 changes: 57 additions & 0 deletions __tests__/get-conventions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import getConventions from "../src/get-conventions";

describe('getConventions()', () => {
const groups = [
{
condition: 'when hugo version < 0.102.0',
version: '0.101.0',
expected: {
arch: {
darwinUniversal: false,
dropped32BitSupport: false,
standardizedNaming: false,
},
os: {
renamedMacOS: false,
downcasedAll: false
}
}
},
{
michaeltlombardi marked this conversation as resolved.
Show resolved Hide resolved
condition: 'when hugo version === 0.102.z',
version: '0.102.0',
expected: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: false,
},
os: {
renamedMacOS: true,
downcasedAll: false
}
}
},
{
michaeltlombardi marked this conversation as resolved.
Show resolved Hide resolved
condition: 'when hugo version >= 0.103.0',
version: '0.103.0',
expected: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: true,
},
os: {
renamedMacOS: true,
downcasedAll: true
}
}
}
].map(function (group) {
return Object.assign(group, { toString: function () { return group.condition } });
});

test.each(groups)('%s', ({ expected, version }) => {
expect(getConventions(version)).toEqual(expected);
});
});
93 changes: 87 additions & 6 deletions __tests__/get-os.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,96 @@
import getOS from '../src/get-os';

describe('getOS', () => {
test('os type', () => {
expect(getOS('linux')).toBe('Linux');
expect(getOS('darwin')).toBe('macOS');
expect(getOS('win32')).toBe('Windows');
const groups = [
{
michaeltlombardi marked this conversation as resolved.
Show resolved Hide resolved
condition: 'when hugo version < 0.102.0',
conventions: {
arch: {
darwinUniversal: false,
dropped32BitSupport: false,
standardizedNaming: false,
},
os: {
renamedMacOS: false,
downcasedAll: false
}
},
tests: [
{ os: 'linux', expected: 'Linux' },
{ os: 'darwin', expected: 'macOS' },
{ os: 'win32', expected: 'Windows' },
],
},
{
condition: 'when hugo version === 0.102.z',
conventions: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: false,
},
os: {
renamedMacOS: true,
downcasedAll: false
}
},
tests: [
{ os: 'linux', expected: 'Linux' },
{ os: 'darwin', expected: 'darwin' },
{ os: 'win32', expected: 'Windows' },
],
},
{
condition: 'when hugo version >= 0.103.0',
conventions: {
arch: {
darwinUniversal: true,
dropped32BitSupport: true,
standardizedNaming: true,
},
os: {
renamedMacOS: true,
downcasedAll: true
}
},
tests: [
{ os: 'linux', expected: 'linux' },
{ os: 'darwin', expected: 'darwin' },
{ os: 'win32', expected: 'windows' },
],
}
].map(function (group) {
group.tests = group.tests.map(function (example) {
return Object.assign(example, {
toString: function () {
return `${example.os} returns ${example.expected}`
}
});
})
return Object.assign(group, { toString: function () { return group.condition } });
});

describe.each(groups)('%s', ({ conventions, tests }) => {
test.each(tests)('%s', ({ os, expected }) => {
expect(getOS(os, conventions)).toBe(expected);
})
});

test('exception', () => {
const conventions = {
arch: {
darwinUniversal: false,
dropped32BitSupport: false,
standardizedNaming: false,
},
os: {
renamedMacOS: false,
downcasedAll: false
}
}

expect(() => {
getOS('centos');
}).toThrowError('centos is not supported');
getOS('centos', conventions);
}).toThrow('centos is not supported');
});
});
16 changes: 13 additions & 3 deletions src/get-arch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
export default function getArch(arch: string): string {
import { conventions } from "./get-conventions";

export default function getArch(arch: string, os: string, conventions: conventions): string {
if (os == 'darwin' || os == 'macOS' && conventions.arch.darwinUniversal) {
return 'universal'
}

switch (arch) {
case 'x64':
return '64bit';
return conventions.arch.standardizedNaming ? 'amd64': '64bit' ;
case 'arm':
if (conventions.arch.dropped32BitSupport) {
throw new Error(`${arch} is not supported`);
}

return 'ARM';
case 'arm64':
return 'ARM64';
return conventions.arch.standardizedNaming ? 'arm64' : 'ARM64';
default:
throw new Error(`${arch} is not supported`);
}
Expand Down
29 changes: 29 additions & 0 deletions src/get-conventions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface conventions {
arch: {
darwinUniversal: boolean,
dropped32BitSupport: boolean,
standardizedNaming: boolean
},
os: {
renamedMacOS: boolean,
downcasedAll: boolean
}
}

export default function getConventions(version: string,): conventions {
const segments = version.split('.').map(s => parseInt(s));
const stableOrNewer = segments[0] > 0;
const newerThan103 = stableOrNewer || segments[1] >= 103
const newerThan102 = stableOrNewer || segments[1] >= 102
return {
arch: {
darwinUniversal: newerThan102,
dropped32BitSupport: newerThan102,
standardizedNaming: newerThan103
},
os: {
renamedMacOS: newerThan102,
downcasedAll: newerThan103
}
}
}
11 changes: 7 additions & 4 deletions src/get-os.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export default function getOS(platform: string): string {
import { conventions } from "./get-conventions";

export default function getOS(platform: string, conventions: conventions): string {

switch (platform) {
case 'linux':
return 'Linux';
return conventions.os.downcasedAll ? 'linux' : 'Linux'
case 'darwin':
return 'macOS';
return conventions.os.renamedMacOS ? 'darwin' : 'macOS'
case 'win32':
return 'Windows';
return conventions.os.downcasedAll ? 'windows' : 'Windows'
default:
throw new Error(`${platform} is not supported`);
}
Expand Down
7 changes: 5 additions & 2 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as io from '@actions/io';
import getConventions from './get-conventions';
import getOS from './get-os';
import getArch from './get-arch';
import getURL from './get-url';
Expand Down Expand Up @@ -47,10 +48,12 @@ export async function installer(version: string): Promise<void> {
const extended: string = core.getInput('extended');
core.debug(`Hugo extended: ${extended}`);

const osName: string = getOS(process.platform);
const conventions = getConventions(version);

const osName: string = getOS(process.platform, conventions);
core.debug(`Operating System: ${osName}`);

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

const toolURL: string = getURL(osName, archName, extended, version);
Expand Down