mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-06-06 03:28:40 +02:00
b1937e141c
## 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>
88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
import * as main from '../src/main';
|
|
import * as io from '@actions/io';
|
|
import path from 'path';
|
|
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';
|
|
|
|
jest.setTimeout(30000);
|
|
|
|
describe('Integration testing run()', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
const workDir = path.join(`${process.env.HOME}`, Action.WorkDirName);
|
|
await io.rmRF(workDir);
|
|
|
|
delete process.env['INPUT_HUGO-VERSION'];
|
|
delete process.env['INPUT_EXTENDED'];
|
|
clearMockFetchResponses();
|
|
});
|
|
|
|
test('succeed in installing a custom version', async () => {
|
|
const testVersion = Tool.TestVersionSpec;
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${testVersion}`);
|
|
});
|
|
|
|
test('succeed in installing a custom extended version', async () => {
|
|
const testVersion = Tool.TestVersionSpec;
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
const result: main.ActionResult = await main.run();
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(`hugo v${testVersion}`);
|
|
expect(result.output).toMatch(`extended`);
|
|
});
|
|
|
|
test('succeed in installing the latest version', async () => {
|
|
const testVersion = 'latest';
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
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}`);
|
|
});
|
|
|
|
test('succeed in installing the latest extended version', async () => {
|
|
const testVersion = 'latest';
|
|
process.env['INPUT_HUGO-VERSION'] = testVersion;
|
|
process.env['INPUT_EXTENDED'] = 'true';
|
|
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}`);
|
|
expect(result.output).toMatch(`extended`);
|
|
});
|
|
|
|
test('fail to install the latest version due to 404 of brew', async () => {
|
|
process.env['INPUT_HUGO-VERSION'] = 'latest';
|
|
mockFetchResponse(`https://formulae.brew.sh/api/formula/${Tool.Repo}.json`, 404);
|
|
|
|
await expect(main.run()).rejects.toThrow(FetchError);
|
|
});
|
|
});
|
|
|
|
describe('showVersion()', () => {
|
|
let result: main.ActionResult = {
|
|
exitcode: 0,
|
|
output: ''
|
|
};
|
|
|
|
test('return version', async () => {
|
|
result = await main.showVersion('git', ['--version']);
|
|
expect(result.exitcode).toBe(0);
|
|
expect(result.output).toMatch(/git version/);
|
|
});
|
|
|
|
test('return not found', async () => {
|
|
await expect(main.showVersion('gitgit', ['--version'])).rejects.toThrow('spawn gitgit ENOENT');
|
|
});
|
|
});
|