mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-09-28 16:58:44 +00:00
fix: Hugo package naming fix (#688)
## Summary Rebases the Hugo package naming fix from #609 on top of the current `main` branch, including the installer flow added in #687. - Derive Hugo release asset OS and architecture naming conventions from the requested Hugo version. - Apply those conventions when selecting OS and architecture segments, including the 0.102.x macOS universal boundary, 0.103+ downcased OS names, Windows zip assets, and Linux ARM assets. - Add table-driven tests for pre-0.102, 0.102.x, and 0.103+ naming behavior, plus URL coverage for the corrected release asset names. ## Changes - Add `getConventions` to centralize version-based release asset naming decisions. - Update `getOS` and `getArch` to use convention flags for macOS, lower-case OS names, standardized architecture names, and the Windows ARM support boundary. - Update `getURL` to generate candidate URLs for downcased Windows and Linux assets, and for darwin universal archives. - Wire convention detection into `installer` before generating candidate Hugo release asset URLs. - Expand unit coverage for OS, architecture, convention, and URL behavior. ## Checklist - [x] I have read the latest README and followed the instructions. - [x] I have added or updated tests for behavior changes. - [x] README.md and action.yml updates are not needed because inputs and action metadata are unchanged. - [x] I have run the relevant verification commands. ## References - Rebased follow-up for https://github.com/peaceiris/actions-hugo/pull/609 - References https://github.com/peaceiris/actions-hugo/issues/605 and https://github.com/peaceiris/actions-hugo/issues/608 - Based on `main` after https://github.com/peaceiris/actions-hugo/pull/687 ## Verification - [x] `RUNNER_TEMP=/private/tmp npm run all` - [ ] `npm run build` was not run because this branch does not update bundled output and current `main` removed `lib/index.js`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Version-aware conventions control OS and architecture naming, including macOS universal asset support and expanded darwin/macOS patterns. * **Refactor** * Conventions centralized and applied across installer and URL generation; OS/arch inputs accept varied casing and naming variants. * **Tests** * Expanded, data-driven parameterized tests for conventions, OS/arch mappings, URL variants, and error cases. * Replaced network stubs with deterministic fetch-mock helpers for test isolation. [](https://app.coderabbit.ai/change-stack/peaceiris/actions-hugo/pull/688) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Michael T Lombardi <michael.t.lombardi@gmail.com> Co-authored-by: codefactor-io <support@codefactor.io> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
co-authored by
Michael T Lombardi
codefactor-io
Codex
parent
189731ef00
commit
b1937e141c
+129
-9
@@ -1,15 +1,135 @@
|
|||||||
import getArch from '../src/get-arch';
|
import getArch from '../src/get-arch';
|
||||||
|
|
||||||
describe('getArch', () => {
|
describe('getArch', () => {
|
||||||
test('processor architecture', () => {
|
const groups = [
|
||||||
expect(getArch('x64')).toBe('64bit');
|
{
|
||||||
expect(getArch('arm')).toBe('ARM');
|
condition: 'when hugo version < 0.102.0',
|
||||||
expect(getArch('arm64')).toBe('ARM64');
|
conventions: {
|
||||||
});
|
arch: {
|
||||||
|
darwinUniversal: false,
|
||||||
|
droppedWindowsArmSupport: false,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tests: [
|
||||||
|
{arch: 'x64', os: 'linux', expected: '64bit'},
|
||||||
|
{arch: 'x64', os: 'darwin', expected: '64bit'},
|
||||||
|
{arch: 'x64', os: 'macOS', expected: '64bit'},
|
||||||
|
{arch: 'x64', os: 'windows', expected: '64bit'},
|
||||||
|
{arch: 'arm', os: 'linux', expected: 'ARM'},
|
||||||
|
{arch: 'arm', os: 'darwin', expected: 'ARM'},
|
||||||
|
{arch: 'arm', os: 'macOS', expected: 'ARM'},
|
||||||
|
{arch: 'arm', os: 'windows', expected: 'ARM'},
|
||||||
|
{arch: 'arm64', os: 'linux', expected: 'ARM64'},
|
||||||
|
{arch: 'arm64', os: 'darwin', expected: 'ARM64'},
|
||||||
|
{arch: 'arm64', os: 'macOS', expected: 'ARM64'},
|
||||||
|
{arch: 'arm64', os: 'windows', expected: 'ARM64'}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version === 0.102.z',
|
||||||
|
conventions: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
droppedWindowsArmSupport: true,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
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', expected: 'ARM'},
|
||||||
|
{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 hugo version >= 0.103.0',
|
||||||
|
conventions: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
droppedWindowsArmSupport: 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', expected: 'arm'},
|
||||||
|
{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,
|
||||||
|
droppedWindowsArmSupport: false,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tests: [{arch: 'mips', os: 'linux', throws: true}]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
test('exception', () => {
|
const passingTests = groups.flatMap(group =>
|
||||||
|
group.tests
|
||||||
|
.filter(example => !example.throws)
|
||||||
|
.map(example => ({
|
||||||
|
...example,
|
||||||
|
condition: group.condition,
|
||||||
|
conventions: group.conventions
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
const throwingTests = groups.flatMap(group =>
|
||||||
|
group.tests
|
||||||
|
.filter(example => example.throws)
|
||||||
|
.map(example => ({
|
||||||
|
...example,
|
||||||
|
condition: group.condition,
|
||||||
|
conventions: group.conventions
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each(passingTests)(
|
||||||
|
'$condition: $os on $arch returns $expected',
|
||||||
|
({arch, os, conventions, expected}) => {
|
||||||
|
expect(getArch(arch, os, conventions)).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each(throwingTests)(
|
||||||
|
'$condition: $os on $arch throws as not supported',
|
||||||
|
({arch, os, conventions}) => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getArch('mips');
|
getArch(arch, os, conventions);
|
||||||
}).toThrow('mips is not supported');
|
}).toThrow(`${arch} is not supported`);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
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,
|
||||||
|
droppedWindowsArmSupport: false,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version === 0.102.z',
|
||||||
|
version: '0.102.0',
|
||||||
|
expected: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
droppedWindowsArmSupport: true,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version >= 0.103.0',
|
||||||
|
version: '0.103.0',
|
||||||
|
expected: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
droppedWindowsArmSupport: 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import {getURL, getLatestVersion} from '../src/get-latest-version';
|
import {getURL, getLatestVersion} from '../src/get-latest-version';
|
||||||
import nock from 'nock';
|
|
||||||
import {FetchError} from 'node-fetch';
|
import {FetchError} from 'node-fetch';
|
||||||
|
import {clearMockFetchResponses, mockFetchResponse} from './mocks/node-fetch';
|
||||||
import {Tool} from '../src/constants';
|
import {Tool} from '../src/constants';
|
||||||
import jsonTestBrew from './data/brew.json';
|
import jsonTestBrew from './data/brew.json';
|
||||||
import jsonTestGithub from './data/github.json';
|
import jsonTestGithub from './data/github.json';
|
||||||
@@ -10,7 +10,7 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nock.cleanAll();
|
clearMockFetchResponses();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getURL()', () => {
|
describe('getURL()', () => {
|
||||||
@@ -27,23 +27,25 @@ describe('getURL()', () => {
|
|||||||
|
|
||||||
describe('getLatestVersion()', () => {
|
describe('getLatestVersion()', () => {
|
||||||
test('return latest version via brew', async () => {
|
test('return latest version via brew', async () => {
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 200, jsonTestBrew);
|
||||||
|
|
||||||
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'brew');
|
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'brew');
|
||||||
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('return latest version via GitHub', async () => {
|
test('return latest version via GitHub', async () => {
|
||||||
nock('https://api.github.com')
|
mockFetchResponse(
|
||||||
.get(`/repos/${Tool.Org}/${Tool.Repo}/releases/latest`)
|
`https://api.github.com/repos/${Tool.Org}/${Tool.Repo}/releases/latest`,
|
||||||
.reply(200, jsonTestGithub);
|
200,
|
||||||
|
jsonTestGithub
|
||||||
|
);
|
||||||
|
|
||||||
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'github');
|
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'github');
|
||||||
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
expect(versionLatest).toMatch(Tool.TestVersionLatest);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('return exception 404', async () => {
|
test('return exception 404', async () => {
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 404);
|
||||||
|
|
||||||
await expect(getLatestVersion(Tool.Org, Tool.Repo, 'brew')).rejects.toThrow(FetchError);
|
await expect(getLatestVersion(Tool.Org, Tool.Repo, 'brew')).rejects.toThrow(FetchError);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,100 @@
|
|||||||
import getOS from '../src/get-os';
|
import getOS from '../src/get-os';
|
||||||
|
|
||||||
describe('getOS', () => {
|
describe('getOS', () => {
|
||||||
test('os type', () => {
|
const groups = [
|
||||||
expect(getOS('linux')).toBe('Linux');
|
{
|
||||||
expect(getOS('darwin')).toBe('macOS');
|
condition: 'when hugo version < 0.102.0',
|
||||||
expect(getOS('win32')).toBe('Windows');
|
conventions: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: false,
|
||||||
|
droppedWindowsArmSupport: 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,
|
||||||
|
droppedWindowsArmSupport: true,
|
||||||
|
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.103.0',
|
||||||
|
conventions: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
droppedWindowsArmSupport: 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', () => {
|
test('exception', () => {
|
||||||
|
const conventions = {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: false,
|
||||||
|
droppedWindowsArmSupport: false,
|
||||||
|
standardizedNaming: false
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getOS('centos');
|
getOS('centos', conventions);
|
||||||
}).toThrow('centos is not supported');
|
}).toThrow('centos is not supported');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,6 +49,32 @@ describe('getURL()', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get URLs to macOS 0.102 universal assets', () => {
|
||||||
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.102.0';
|
||||||
|
expect(getURL('macOS', 'universal', 'false', '0.102.0')).toEqual([
|
||||||
|
`${baseURL}/hugo_0.102.0_macOS-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.102.0_macOS-universal.zip`,
|
||||||
|
`${baseURL}/hugo_0.102.0_macOS-all.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.102.0_darwin-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.102.0_darwin-universal.pkg`,
|
||||||
|
`${baseURL}/hugo_v0.102.0_macOS-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.102.0_macOS-universal.zip`,
|
||||||
|
`${baseURL}/hugo_v0.102.0_macOS-all.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.102.0_darwin-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.102.0_darwin-universal.pkg`
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('get URLs to darwin assets', () => {
|
||||||
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.103.0';
|
||||||
|
expect(getURL('darwin', 'universal', 'false', '0.103.0')).toEqual([
|
||||||
|
`${baseURL}/hugo_0.103.0_darwin-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.103.0_darwin-universal.pkg`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_darwin-universal.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_darwin-universal.pkg`
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('get URLs to legacy macOS assets', () => {
|
test('get URLs to legacy macOS assets', () => {
|
||||||
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.2';
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.2';
|
||||||
expect(getURL('macOS', '64bit', 'false', '0.20.2')).toEqual([
|
expect(getURL('macOS', '64bit', 'false', '0.20.2')).toEqual([
|
||||||
@@ -81,6 +107,16 @@ describe('getURL()', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get URLs to downcased Windows assets', () => {
|
||||||
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.103.0';
|
||||||
|
expect(getURL('windows', 'amd64', 'false', '0.103.0')).toEqual([
|
||||||
|
`${baseURL}/hugo_0.103.0_windows-amd64.zip`,
|
||||||
|
`${baseURL}/hugo_0.103.0_Windows-amd64.zip`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_windows-amd64.zip`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_Windows-amd64.zip`
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('get URLs to legacy Windows assets', () => {
|
test('get URLs to legacy Windows assets', () => {
|
||||||
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.3';
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.3';
|
||||||
expect(getURL('Windows', '64bit', 'false', '0.20.3')).toEqual([
|
expect(getURL('Windows', '64bit', 'false', '0.20.3')).toEqual([
|
||||||
@@ -91,6 +127,18 @@ describe('getURL()', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get URLs to downcased Linux assets', () => {
|
||||||
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.103.0';
|
||||||
|
expect(getURL('linux', 'arm', 'false', '0.103.0')).toEqual([
|
||||||
|
`${baseURL}/hugo_0.103.0_linux-arm.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.103.0_Linux-arm.tar.gz`,
|
||||||
|
`${baseURL}/hugo_0.103.0_Linux_arm.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_linux-arm.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_Linux-arm.tar.gz`,
|
||||||
|
`${baseURL}/hugo_v0.103.0_Linux_arm.tar.gz`
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('get a fallback URL to an unknown OS asset', () => {
|
test('get a fallback URL to an unknown OS asset', () => {
|
||||||
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
|
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
|
||||||
expect(getURL('MyOS', '64bit', 'false', '0.58.2')).toEqual([
|
expect(getURL('MyOS', '64bit', 'false', '0.58.2')).toEqual([
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import nock from 'nock';
|
|
||||||
import {Tool, Action} from '../src/constants';
|
import {Tool, Action} from '../src/constants';
|
||||||
import {FetchError} from 'node-fetch';
|
import {FetchError} from 'node-fetch';
|
||||||
|
import {clearMockFetchResponses, mockFetchResponse} from './mocks/node-fetch';
|
||||||
import jsonTestBrew from './data/brew.json';
|
import jsonTestBrew from './data/brew.json';
|
||||||
// import jsonTestGithub from './data/github.json';
|
// import jsonTestGithub from './data/github.json';
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ describe('Integration testing run()', () => {
|
|||||||
|
|
||||||
delete process.env['INPUT_HUGO-VERSION'];
|
delete process.env['INPUT_HUGO-VERSION'];
|
||||||
delete process.env['INPUT_EXTENDED'];
|
delete process.env['INPUT_EXTENDED'];
|
||||||
nock.cleanAll();
|
clearMockFetchResponses();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('succeed in installing a custom version', async () => {
|
test('succeed in installing a custom version', async () => {
|
||||||
@@ -44,7 +44,7 @@ describe('Integration testing run()', () => {
|
|||||||
test('succeed in installing the latest version', async () => {
|
test('succeed in installing the latest version', async () => {
|
||||||
const testVersion = 'latest';
|
const testVersion = 'latest';
|
||||||
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 200, jsonTestBrew);
|
||||||
const result: main.ActionResult = await main.run();
|
const result: main.ActionResult = await main.run();
|
||||||
expect(result.exitcode).toBe(0);
|
expect(result.exitcode).toBe(0);
|
||||||
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
||||||
@@ -54,7 +54,7 @@ describe('Integration testing run()', () => {
|
|||||||
const testVersion = 'latest';
|
const testVersion = 'latest';
|
||||||
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
||||||
process.env['INPUT_EXTENDED'] = 'true';
|
process.env['INPUT_EXTENDED'] = 'true';
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(200, jsonTestBrew);
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 200, jsonTestBrew);
|
||||||
const result: main.ActionResult = await main.run();
|
const result: main.ActionResult = await main.run();
|
||||||
expect(result.exitcode).toBe(0);
|
expect(result.exitcode).toBe(0);
|
||||||
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
|
||||||
@@ -63,7 +63,7 @@ describe('Integration testing run()', () => {
|
|||||||
|
|
||||||
test('fail to install the latest version due to 404 of brew', async () => {
|
test('fail to install the latest version due to 404 of brew', async () => {
|
||||||
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
||||||
nock('https://formulae.brew.sh').get(`/api/formula/${Tool.Repo}.json`).reply(404);
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 404);
|
||||||
|
|
||||||
await expect(main.run()).rejects.toThrow(FetchError);
|
await expect(main.run()).rejects.toThrow(FetchError);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,8 +22,35 @@ interface ResponseLike {
|
|||||||
json: () => Promise<unknown>;
|
json: () => Promise<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MockResponse {
|
||||||
|
body?: unknown;
|
||||||
|
status: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockResponses = new Map<string, MockResponse>();
|
||||||
|
|
||||||
|
export function mockFetchResponse(url: string, status: number, body?: unknown): void {
|
||||||
|
mockResponses.set(url, {
|
||||||
|
body,
|
||||||
|
status
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearMockFetchResponses(): void {
|
||||||
|
mockResponses.clear();
|
||||||
|
}
|
||||||
|
|
||||||
export default async function fetch(url: string | URL): Promise<ResponseLike> {
|
export default async function fetch(url: string | URL): Promise<ResponseLike> {
|
||||||
const target = url.toString();
|
const target = url.toString();
|
||||||
|
const mockResponse = mockResponses.get(target);
|
||||||
|
if (mockResponse) {
|
||||||
|
return {
|
||||||
|
ok: mockResponse.status >= 200 && mockResponse.status < 300,
|
||||||
|
status: mockResponse.status,
|
||||||
|
json: async () => mockResponse.body as unknown
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const client = target.startsWith('https:') ? https : http;
|
const client = target.startsWith('https:') ? https : http;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
+14
-4
@@ -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 (conventions.arch.darwinUniversal && (os === 'darwin' || os === 'macOS')) {
|
||||||
|
return 'universal';
|
||||||
|
}
|
||||||
|
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
return '64bit';
|
return conventions.arch.standardizedNaming ? 'amd64' : '64bit';
|
||||||
case 'arm':
|
case 'arm':
|
||||||
return 'ARM';
|
if (conventions.arch.droppedWindowsArmSupport && (os === 'Windows' || os === 'windows')) {
|
||||||
|
throw new Error(`${arch} is not supported`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return conventions.arch.standardizedNaming ? 'arm' : 'ARM';
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
return 'ARM64';
|
return conventions.arch.standardizedNaming ? 'arm64' : 'ARM64';
|
||||||
default:
|
default:
|
||||||
throw new Error(`${arch} is not supported`);
|
throw new Error(`${arch} is not supported`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
export interface conventions {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: boolean;
|
||||||
|
droppedWindowsArmSupport: boolean;
|
||||||
|
standardizedNaming: boolean;
|
||||||
|
};
|
||||||
|
os: {
|
||||||
|
renamedMacOS: boolean;
|
||||||
|
downcasedAll: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export 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,
|
||||||
|
droppedWindowsArmSupport: newerThan102,
|
||||||
|
standardizedNaming: newerThan103
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: newerThan103,
|
||||||
|
downcasedAll: newerThan103
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
+6
-4
@@ -1,11 +1,13 @@
|
|||||||
export default function getOS(platform: string): string {
|
import {conventions} from './get-conventions';
|
||||||
|
|
||||||
|
export default function getOS(platform: string, conventions: conventions): string {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
return 'Linux';
|
return conventions.os.downcasedAll ? 'linux' : 'Linux';
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return 'macOS';
|
return conventions.os.renamedMacOS ? 'darwin' : 'macOS';
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return 'Windows';
|
return conventions.os.downcasedAll ? 'windows' : 'Windows';
|
||||||
default:
|
default:
|
||||||
throw new Error(`${platform} is not supported`);
|
throw new Error(`${platform} is not supported`);
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-9
@@ -49,22 +49,34 @@ export default function getURL(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os === 'Windows') {
|
if (os === 'darwin') {
|
||||||
return assetURLs(
|
return assetURLs(
|
||||||
assetBases.flatMap(assetBase => [
|
assetBases.flatMap(assetBase => [
|
||||||
`${assetBase}Windows-${arch}.zip`,
|
`${assetBase}darwin-${arch}.tar.gz`,
|
||||||
`${assetBase}windows-${lowerArch(arch)}.zip`
|
`${assetBase}darwin-${arch}.pkg`
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os === 'Linux') {
|
if (os === 'Windows' || os === 'windows') {
|
||||||
|
const assetPatterns =
|
||||||
|
os === 'windows'
|
||||||
|
? [`windows-${lowerArch(arch)}.zip`, `Windows-${arch}.zip`]
|
||||||
|
: [`Windows-${arch}.zip`, `windows-${lowerArch(arch)}.zip`];
|
||||||
|
|
||||||
return assetURLs(
|
return assetURLs(
|
||||||
assetBases.flatMap(assetBase => [
|
assetBases.flatMap(assetBase => assetPatterns.map(asset => `${assetBase}${asset}`))
|
||||||
`${assetBase}Linux-${arch}.tar.gz`,
|
);
|
||||||
`${assetBase}Linux_${arch}.tar.gz`,
|
}
|
||||||
`${assetBase}linux-${lowerArch(arch)}.tar.gz`
|
|
||||||
])
|
if (os === 'Linux' || os === 'linux') {
|
||||||
|
const assetPatterns =
|
||||||
|
os === 'linux'
|
||||||
|
? [`linux-${lowerArch(arch)}.tar.gz`, `Linux-${arch}.tar.gz`, `Linux_${arch}.tar.gz`]
|
||||||
|
: [`Linux-${arch}.tar.gz`, `Linux_${arch}.tar.gz`, `linux-${lowerArch(arch)}.tar.gz`];
|
||||||
|
|
||||||
|
return assetURLs(
|
||||||
|
assetBases.flatMap(assetBase => assetPatterns.map(asset => `${assetBase}${asset}`))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import {getConventions} from './get-conventions';
|
||||||
import getOS from './get-os';
|
import getOS from './get-os';
|
||||||
import getArch from './get-arch';
|
import getArch from './get-arch';
|
||||||
import getURL from './get-url';
|
import getURL from './get-url';
|
||||||
@@ -113,10 +114,12 @@ export async function installer(version: string): Promise<void> {
|
|||||||
const extended: string = core.getInput('extended');
|
const extended: string = core.getInput('extended');
|
||||||
core.debug(`Hugo extended: ${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}`);
|
core.debug(`Operating System: ${osName}`);
|
||||||
|
|
||||||
const archName: string = getArch(process.arch);
|
const archName: string = getArch(process.arch, osName, conventions);
|
||||||
core.debug(`Processor Architecture: ${archName}`);
|
core.debug(`Processor Architecture: ${archName}`);
|
||||||
|
|
||||||
const toolURLs: string[] = getURL(osName, archName, extended, version);
|
const toolURLs: string[] = getURL(osName, archName, extended, version);
|
||||||
|
|||||||
Reference in New Issue
Block a user