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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](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:
Shohei Ueda
2026-05-11 00:23:26 +09:00
committed by GitHub
parent 189731ef00
commit b1937e141c
12 changed files with 445 additions and 46 deletions
+130 -10
View File
@@ -1,15 +1,135 @@
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,
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', () => {
expect(() => {
getArch('mips');
}).toThrow('mips is not supported');
});
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(() => {
getArch(arch, os, conventions);
}).toThrow(`${arch} is not supported`);
}
);
});
+61
View File
@@ -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);
});
});
+9 -7
View File
@@ -1,6 +1,6 @@
import {getURL, getLatestVersion} from '../src/get-latest-version';
import nock from 'nock';
import {FetchError} from 'node-fetch';
import {clearMockFetchResponses, mockFetchResponse} from './mocks/node-fetch';
import {Tool} from '../src/constants';
import jsonTestBrew from './data/brew.json';
import jsonTestGithub from './data/github.json';
@@ -10,7 +10,7 @@ beforeEach(() => {
});
afterEach(() => {
nock.cleanAll();
clearMockFetchResponses();
});
describe('getURL()', () => {
@@ -27,23 +27,25 @@ describe('getURL()', () => {
describe('getLatestVersion()', () => {
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');
expect(versionLatest).toMatch(Tool.TestVersionLatest);
});
test('return latest version via GitHub', async () => {
nock('https://api.github.com')
.get(`/repos/${Tool.Org}/${Tool.Repo}/releases/latest`)
.reply(200, jsonTestGithub);
mockFetchResponse(
`https://api.github.com/repos/${Tool.Org}/${Tool.Repo}/releases/latest`,
200,
jsonTestGithub
);
const versionLatest: string = await getLatestVersion(Tool.Org, Tool.Repo, 'github');
expect(versionLatest).toMatch(Tool.TestVersionLatest);
});
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);
});
+90 -5
View File
@@ -1,15 +1,100 @@
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 = [
{
condition: 'when hugo version < 0.102.0',
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', () => {
const conventions = {
arch: {
darwinUniversal: false,
droppedWindowsArmSupport: false,
standardizedNaming: false
},
os: {
renamedMacOS: false,
downcasedAll: false
}
};
expect(() => {
getOS('centos');
getOS('centos', conventions);
}).toThrow('centos is not supported');
});
});
+48
View File
@@ -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', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.2';
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', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.3';
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', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
expect(getURL('MyOS', '64bit', 'false', '0.58.2')).toEqual([
+5 -5
View File
@@ -1,9 +1,9 @@
import * as main from '../src/main';
import * as io from '@actions/io';
import path from 'path';
import nock from 'nock';
import {Tool, Action} from '../src/constants';
import {FetchError} from 'node-fetch';
import {clearMockFetchResponses, mockFetchResponse} from './mocks/node-fetch';
import jsonTestBrew from './data/brew.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_EXTENDED'];
nock.cleanAll();
clearMockFetchResponses();
});
test('succeed in installing a custom version', async () => {
@@ -44,7 +44,7 @@ describe('Integration testing run()', () => {
test('succeed in installing the latest version', async () => {
const testVersion = 'latest';
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();
expect(result.exitcode).toBe(0);
expect(result.output).toMatch(`hugo v${Tool.TestVersionLatest}`);
@@ -54,7 +54,7 @@ describe('Integration testing run()', () => {
const testVersion = 'latest';
process.env['INPUT_HUGO-VERSION'] = testVersion;
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();
expect(result.exitcode).toBe(0);
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 () => {
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);
});
+27
View File
@@ -22,8 +22,35 @@ interface ResponseLike {
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> {
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;
return new Promise((resolve, reject) => {
+14 -4
View File
@@ -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) {
case 'x64':
return '64bit';
return conventions.arch.standardizedNaming ? 'amd64' : '64bit';
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':
return 'ARM64';
return conventions.arch.standardizedNaming ? 'arm64' : 'ARM64';
default:
throw new Error(`${arch} is not supported`);
}
+29
View File
@@ -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
View File
@@ -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) {
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`);
}
+21 -9
View File
@@ -49,22 +49,34 @@ export default function getURL(
);
}
if (os === 'Windows') {
if (os === 'darwin') {
return assetURLs(
assetBases.flatMap(assetBase => [
`${assetBase}Windows-${arch}.zip`,
`${assetBase}windows-${lowerArch(arch)}.zip`
`${assetBase}darwin-${arch}.tar.gz`,
`${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(
assetBases.flatMap(assetBase => [
`${assetBase}Linux-${arch}.tar.gz`,
`${assetBase}Linux_${arch}.tar.gz`,
`${assetBase}linux-${lowerArch(arch)}.tar.gz`
])
assetBases.flatMap(assetBase => assetPatterns.map(asset => `${assetBase}${asset}`))
);
}
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
View File
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as io from '@actions/io';
import * as exec from '@actions/exec';
import {getConventions} from './get-conventions';
import getOS from './get-os';
import getArch from './get-arch';
import getURL from './get-url';
@@ -113,10 +114,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 toolURLs: string[] = getURL(osName, archName, extended, version);