mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2025-06-18 10:05:28 +08:00
Compare commits
6 Commits
d7ca6e16c2
...
43d5a36d37
Author | SHA1 | Date | |
---|---|---|---|
![]() |
43d5a36d37 | ||
![]() |
966dfad385 | ||
![]() |
c57490a8b0 | ||
![]() |
b7e8a5bdba | ||
![]() |
c7d0025d39 | ||
![]() |
e70fd029fa |
1
.github/workflows/test-action.yml
vendored
1
.github/workflows/test-action.yml
vendored
@ -11,7 +11,6 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- 'ubuntu-22.04'
|
|
||||||
- 'ubuntu-20.04'
|
- 'ubuntu-20.04'
|
||||||
- 'ubuntu-latest'
|
- 'ubuntu-latest'
|
||||||
- 'macos-latest'
|
- 'macos-latest'
|
||||||
|
11
.github/workflows/test.yml
vendored
11
.github/workflows/test.yml
vendored
@ -14,6 +14,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
- 'ubuntu-22.04'
|
- 'ubuntu-22.04'
|
||||||
@ -24,14 +25,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Read .nvmrc
|
- uses: actions/setup-node@v4
|
||||||
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
|
|
||||||
id: nvm
|
|
||||||
|
|
||||||
- name: Setup Node
|
|
||||||
uses: actions/setup-node@v3.6.0
|
|
||||||
with:
|
with:
|
||||||
node-version: '${{ steps.nvm.outputs.NVMRC }}'
|
node-version-file: '.nvmrc'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
|
||||||
|
@ -261,10 +261,9 @@ jobs:
|
|||||||
hugo-version: '0.119.0'
|
hugo-version: '0.119.0'
|
||||||
extended: true
|
extended: true
|
||||||
|
|
||||||
- name: Setup Node
|
- uses: actions/setup-node@v4
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: '18'
|
node-version: '20'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
# The action defaults to search for the dependency file (package-lock.json,
|
# The action defaults to search for the dependency file (package-lock.json,
|
||||||
# npm-shrinkwrap.json or yarn.lock) in the repository root, and uses its
|
# npm-shrinkwrap.json or yarn.lock) in the repository root, and uses its
|
||||||
|
@ -1,15 +1,121 @@
|
|||||||
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,
|
||||||
|
dropped32BitSupport: false,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tests: [
|
||||||
|
{ arch: 'x64', os: 'linux', expected: '64bit' },
|
||||||
|
{ arch: 'x64', os: 'macOS', expected: '64bit' },
|
||||||
|
{ arch: 'x64', os: 'windows', expected: '64bit' },
|
||||||
|
{ arch: 'arm', os: 'linux', expected: 'ARM' },
|
||||||
|
{ arch: 'arm', os: 'macOS', expected: 'ARM' },
|
||||||
|
{ arch: 'arm', os: 'windows', expected: 'ARM' },
|
||||||
|
{ arch: 'arm64', os: 'linux', 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,
|
||||||
|
dropped32BitSupport: true,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: true,
|
||||||
|
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', throws: true },
|
||||||
|
{ 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,
|
||||||
|
dropped32BitSupport: 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', throws: true },
|
||||||
|
{ 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,
|
||||||
|
dropped32BitSupport: false,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tests: [
|
||||||
|
{ arch: 'mips', os: 'linux', throws: true}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
].map(function (group) {
|
||||||
|
group.tests = group.tests.map(function (example) {
|
||||||
|
return Object.assign(example, {
|
||||||
|
toString: function () {
|
||||||
|
let name = `${example.os} on ${example.arch} `
|
||||||
|
name += example?.throws ? 'throws as not supported' : `returns ${example.expected}`
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
return Object.assign(group, { toString: function () { return group.condition } });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('exception', () => {
|
describe.each(groups)('%s', ({ conventions, tests }) => {
|
||||||
|
test.each(tests)('%s', ({ arch, os, throws, expected }) => {
|
||||||
|
if (throws) {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getArch('mips');
|
getArch(arch, os, conventions)
|
||||||
}).toThrowError('mips is not supported');
|
}).toThrow(`${arch} is not supported`);
|
||||||
});
|
} else {
|
||||||
|
expect(getArch(arch, os, conventions)).toBe(expected);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
57
__tests__/get-conventions.test.ts
Normal file
57
__tests__/get-conventions.test.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
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,
|
||||||
|
dropped32BitSupport: false,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version === 0.102.z',
|
||||||
|
version: '0.102.0',
|
||||||
|
expected: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
dropped32BitSupport: true,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: true,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version >= 0.103.0',
|
||||||
|
version: '0.103.0',
|
||||||
|
expected: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
dropped32BitSupport: 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,15 +1,96 @@
|
|||||||
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,
|
||||||
|
dropped32BitSupport: 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,
|
||||||
|
dropped32BitSupport: true,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: true,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tests: [
|
||||||
|
{ os: 'linux', expected: 'Linux' },
|
||||||
|
{ os: 'darwin', expected: 'darwin' },
|
||||||
|
{ os: 'win32', expected: 'Windows' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
condition: 'when hugo version >= 0.103.0',
|
||||||
|
conventions: {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: true,
|
||||||
|
dropped32BitSupport: 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,
|
||||||
|
dropped32BitSupport: false,
|
||||||
|
standardizedNaming: false,
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: false,
|
||||||
|
downcasedAll: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getOS('centos');
|
getOS('centos', conventions);
|
||||||
}).toThrowError('centos is not supported');
|
}).toThrow('centos is not supported');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'lib/index.js'
|
main: 'lib/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'package'
|
icon: 'package'
|
||||||
|
2023
package-lock.json
generated
2023
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-hugo",
|
"name": "actions-hugo",
|
||||||
"version": "2.6.0",
|
"version": "3.0.0",
|
||||||
"description": "GitHub Actions for Hugo",
|
"description": "GitHub Actions for Hugo",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.18.0",
|
"node": ">=20.10.0",
|
||||||
"npm": ">=8.19.0"
|
"npm": ">=10.2.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"all": "npm run format:check && npm run lint && npm test",
|
"all": "npm run format:check && npm run lint && npm test",
|
||||||
@ -55,11 +55,11 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.20",
|
"@types/jest": "^26.0.20",
|
||||||
"@types/node": "~12",
|
"@types/node": "~20",
|
||||||
"@types/node-fetch": "^2.5.8",
|
"@types/node-fetch": "^2.5.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
"@typescript-eslint/eslint-plugin": "^4.16.1",
|
||||||
"@typescript-eslint/parser": "^4.16.1",
|
"@typescript-eslint/parser": "^4.16.1",
|
||||||
"@vercel/ncc": "^0.27.0",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"eslint": "^7.21.0",
|
"eslint": "^7.21.0",
|
||||||
"eslint-plugin-jest": "^24.1.5",
|
"eslint-plugin-jest": "^24.1.5",
|
||||||
"husky": "^5.1.3",
|
"husky": "^5.1.3",
|
||||||
|
@ -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 (os == 'darwin' || os == 'macOS' && conventions.arch.darwinUniversal) {
|
||||||
|
return 'universal'
|
||||||
|
}
|
||||||
|
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
return '64bit';
|
return conventions.arch.standardizedNaming ? 'amd64': '64bit' ;
|
||||||
case 'arm':
|
case 'arm':
|
||||||
|
if (conventions.arch.dropped32BitSupport) {
|
||||||
|
throw new Error(`${arch} is not supported`);
|
||||||
|
}
|
||||||
|
|
||||||
return 'ARM';
|
return '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`);
|
||||||
}
|
}
|
||||||
|
29
src/get-conventions.ts
Normal file
29
src/get-conventions.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
export interface conventions {
|
||||||
|
arch: {
|
||||||
|
darwinUniversal: boolean,
|
||||||
|
dropped32BitSupport: boolean,
|
||||||
|
standardizedNaming: boolean
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: boolean,
|
||||||
|
downcasedAll: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default 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,
|
||||||
|
dropped32BitSupport: newerThan102,
|
||||||
|
standardizedNaming: newerThan103
|
||||||
|
},
|
||||||
|
os: {
|
||||||
|
renamedMacOS: newerThan102,
|
||||||
|
downcasedAll: newerThan103
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,14 @@
|
|||||||
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`);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as core from '@actions/core';
|
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 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';
|
||||||
@ -47,10 +48,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 toolURL: string = getURL(osName, archName, extended, version);
|
const toolURL: string = getURL(osName, archName, extended, version);
|
||||||
|
Loading…
Reference in New Issue
Block a user