Files
actions-hugo/__tests__/get-url.test.ts
T
Shohei Ueda 187a5efe81 feat: support renamed Hugo release assets (#687)
## Summary
- Support multiple Hugo release asset names for Linux, macOS, and
Windows so renamed upstream assets no longer fail with a plain 404.
- Preserve compatibility with legacy Hugo assets that used filename
forms such as `hugo_v0.20.3_*`, macOS `.zip` archives, and
`Linux_ARM`-style names.
- Add retry handling for missing candidate assets and macOS `.pkg`
extraction via `pkgutil --expand-full`, with focused URL and installer
tests plus the rebuilt `lib/index.js` bundle.

## References
- Fixes https://github.com/peaceiris/actions-hugo/issues/652
- `hugo-version: latest` still resolves through Homebrew; this change
does not fall back to an older Hugo version when the resolved release
has no compatible asset.
- Review note: `lib/index.js` is generated by `npm run build` and
contains bundled dependency code.

## Test plan
- [x] `RUNNER_TEMP=/tmp npm run all`
- [x] `npm run build`


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Broadened test coverage for asset URL generation, download retry
behavior, and extraction across OSes and architectures.

* **Bug Fixes**
* More resilient installer with multiple candidate download URLs and
retry handling for transient failures.
* Improved extraction logic to correctly handle platform- and
format-specific archives.

[![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/687)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Codex <noreply@openai.com>
2026-05-10 22:40:55 +09:00

101 lines
4.4 KiB
TypeScript

import getURL from '../src/get-url';
describe('getURL()', () => {
test('get URLs to Linux assets', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
expect(getURL('Linux', '64bit', 'false', '0.58.2')).toEqual([
`${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`,
`${baseURL}/hugo_0.58.2_Linux_64bit.tar.gz`,
`${baseURL}/hugo_0.58.2_linux-amd64.tar.gz`,
`${baseURL}/hugo_v0.58.2_Linux-64bit.tar.gz`,
`${baseURL}/hugo_v0.58.2_Linux_64bit.tar.gz`,
`${baseURL}/hugo_v0.58.2_linux-amd64.tar.gz`
]);
expect(getURL('Linux', 'ARM64', 'true', '0.58.2')).toEqual([
`${baseURL}/hugo_extended_0.58.2_Linux-ARM64.tar.gz`,
`${baseURL}/hugo_extended_0.58.2_Linux_ARM64.tar.gz`,
`${baseURL}/hugo_extended_0.58.2_linux-arm64.tar.gz`,
`${baseURL}/hugo_extended_v0.58.2_Linux-ARM64.tar.gz`,
`${baseURL}/hugo_extended_v0.58.2_Linux_ARM64.tar.gz`,
`${baseURL}/hugo_extended_v0.58.2_linux-arm64.tar.gz`
]);
});
test('get URLs to legacy Linux assets', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.20.3';
expect(getURL('Linux', '64bit', 'false', '0.20.3')).toEqual([
`${baseURL}/hugo_0.20.3_Linux-64bit.tar.gz`,
`${baseURL}/hugo_0.20.3_Linux_64bit.tar.gz`,
`${baseURL}/hugo_0.20.3_linux-amd64.tar.gz`,
`${baseURL}/hugo_v0.20.3_Linux-64bit.tar.gz`,
`${baseURL}/hugo_v0.20.3_Linux_64bit.tar.gz`,
`${baseURL}/hugo_v0.20.3_linux-amd64.tar.gz`
]);
});
test('get URLs to macOS assets', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.161.1';
expect(getURL('macOS', '64bit', 'true', '0.161.1')).toEqual([
`${baseURL}/hugo_extended_0.161.1_macOS-64bit.tar.gz`,
`${baseURL}/hugo_extended_0.161.1_macOS-64bit.zip`,
`${baseURL}/hugo_extended_0.161.1_macOS-all.tar.gz`,
`${baseURL}/hugo_extended_0.161.1_darwin-universal.tar.gz`,
`${baseURL}/hugo_extended_0.161.1_darwin-universal.pkg`,
`${baseURL}/hugo_extended_v0.161.1_macOS-64bit.tar.gz`,
`${baseURL}/hugo_extended_v0.161.1_macOS-64bit.zip`,
`${baseURL}/hugo_extended_v0.161.1_macOS-all.tar.gz`,
`${baseURL}/hugo_extended_v0.161.1_darwin-universal.tar.gz`,
`${baseURL}/hugo_extended_v0.161.1_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([
`${baseURL}/hugo_0.20.2_macOS-64bit.tar.gz`,
`${baseURL}/hugo_0.20.2_macOS-64bit.zip`,
`${baseURL}/hugo_0.20.2_macOS-all.tar.gz`,
`${baseURL}/hugo_0.20.2_darwin-universal.tar.gz`,
`${baseURL}/hugo_0.20.2_darwin-universal.pkg`,
`${baseURL}/hugo_v0.20.2_macOS-64bit.tar.gz`,
`${baseURL}/hugo_v0.20.2_macOS-64bit.zip`,
`${baseURL}/hugo_v0.20.2_macOS-all.tar.gz`,
`${baseURL}/hugo_v0.20.2_darwin-universal.tar.gz`,
`${baseURL}/hugo_v0.20.2_darwin-universal.pkg`
]);
});
test('get URLs to Windows assets', () => {
const baseURL = 'https://github.com/gohugoio/hugo/releases/download/v0.58.2';
expect(getURL('Windows', '64bit', 'false', '0.58.2')).toEqual([
`${baseURL}/hugo_0.58.2_Windows-64bit.zip`,
`${baseURL}/hugo_0.58.2_windows-amd64.zip`,
`${baseURL}/hugo_v0.58.2_Windows-64bit.zip`,
`${baseURL}/hugo_v0.58.2_windows-amd64.zip`
]);
expect(getURL('Windows', 'ARM64', 'true', '0.58.2')).toEqual([
`${baseURL}/hugo_extended_0.58.2_Windows-ARM64.zip`,
`${baseURL}/hugo_extended_0.58.2_windows-arm64.zip`,
`${baseURL}/hugo_extended_v0.58.2_Windows-ARM64.zip`,
`${baseURL}/hugo_extended_v0.58.2_windows-arm64.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([
`${baseURL}/hugo_0.20.3_Windows-64bit.zip`,
`${baseURL}/hugo_0.20.3_windows-amd64.zip`,
`${baseURL}/hugo_v0.20.3_Windows-64bit.zip`,
`${baseURL}/hugo_v0.20.3_windows-amd64.zip`
]);
});
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([
`${baseURL}/hugo_0.58.2_MyOS-64bit.tar.gz`
]);
});
});