mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-09-27 04:20:00 +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
+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) {
|
||||
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`);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
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
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user