Compare commits

...

10 Commits

Author SHA1 Message Date
Mikey Lombardi (He/Him)
5ae47fdd5c
Merge b7e8a5bdba into 00e5abe1c8 2024-04-09 10:12:04 -05:00
Linda_pp
00e5abe1c8
fix(doc): Update @v2 to @v3 in README.md (#649) 2024-04-07 03:09:58 +09:00
peaceiris
1b06a03d21
chore(release): Remove build assets [skip ci] 2024-04-02 12:17:51 +09:00
peaceiris
75d2e84710
chore(release): 3.0.0 2024-04-02 12:17:50 +09:00
peaceiris
e482f7ce0f
chore(release): Add build assets 2024-04-02 12:17:49 +09:00
peaceiris
d85452eadf
chore: revert version 2024-04-02 12:16:58 +09:00
peaceiris
01bd2b16cc
build: node 20.11.1 2024-04-02 09:33:47 +09:00
Michael T Lombardi
b7e8a5bdba
(GH-608) Add getConventions and refactor
This commit introduces the getConventions function, which does a one-time calculation
for the changes in packaging conventions to propagate to the getArch and getOS
functions.

It updates those functions and the installer code to leverage the conventions.

Finally, it updates the test arrangement for getArch and getOS to use test cases
instead of repeating the same test over and over and adds unit tests for the new
getConventions function.
2022-10-13 23:13:33 -05:00
codefactor-io
c7d0025d39
[CodeFactor] Apply fixes to commit e70fd02 2022-10-06 13:13:28 +00:00
Michael T Lombardi
e70fd029fa
(GH-608) Fix package url for v0.102.0 & v0.103.0
Prior to this change, the URL building for versions of hugo was
deterministic as the URLs for the packages were set to a
project-specific standard. That URL creation began to fail for macOS in
[0.102.0] and for Windows in [0.103.0]. It does not fail for Linux
because the hugo releases for Linux continue to include the old package
naming as an alias.

This change:

- Updates the `get-os` function to take the hugo version as additional
  input, altering the return value based on the version.
- Updates the `get-arch` function to take the operating system name and
  hugo version as additional input, altering the return value based on
  both. Including the OS name is required for handling macOS.
- Fixes #608
- Fixes #605

[0.102.0]: https://github.com/gohugoio/hugo/releases/tag/v0.102.0
[0.103.0]: https://github.com/gohugoio/hugo/releases/tag/v0.103.0
2022-10-06 08:09:56 -05:00
11 changed files with 355 additions and 33 deletions

2
.nvmrc
View File

@ -1 +1 @@
20.10.0 20.11.1

View File

@ -2,6 +2,39 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
# [3.0.0](https://github.com/peaceiris/actions-hugo/compare/v2.6.0...v3.0.0) (2024-04-02)
### build
* node 20.11.1 ([01bd2b1](https://github.com/peaceiris/actions-hugo/commit/01bd2b16cc6cadbc63cba9bddb36c689f462c2db))
### chore
* npm audit fix ([966dfad](https://github.com/peaceiris/actions-hugo/commit/966dfad3859a5cfc80b6e36761b0b4c7b3dd5e0c))
* revert version ([d85452e](https://github.com/peaceiris/actions-hugo/commit/d85452eadfba7065bf8c0601c8c22e427982d108))
### ci
* bump actions/dependency-review-action from 2 to 3 (#622) ([844f873](https://github.com/peaceiris/actions-hugo/commit/844f8735f61722d43677c23cbeae4283af7b554a)), closes [#622](https://github.com/peaceiris/actions-hugo/issues/622)
* bump actions/setup-node from 3.5.1 to 3.6.0 (#625) ([3fa8fd6](https://github.com/peaceiris/actions-hugo/commit/3fa8fd6cee4e03774c4e900dca8b766d1cdcae93)), closes [#625](https://github.com/peaceiris/actions-hugo/issues/625)
* bump checkout to v4 (#639) ([aadc3a9](https://github.com/peaceiris/actions-hugo/commit/aadc3a98dfd3437f8f97d436ea91b82a73dc85dd)), closes [#639](https://github.com/peaceiris/actions-hugo/issues/639)
* bump peaceiris/actions-hugo from 2.5.0 to 2.6.0 (#621) ([b1822b6](https://github.com/peaceiris/actions-hugo/commit/b1822b6abe1a489f9ba7b9b664d916aeafd3e592)), closes [#621](https://github.com/peaceiris/actions-hugo/issues/621)
### docs
* bump ruby version to 3.2 (#629) ([7c4b9f1](https://github.com/peaceiris/actions-hugo/commit/7c4b9f1f99c72728600c292c1f0e7138cc3a8865)), closes [#629](https://github.com/peaceiris/actions-hugo/issues/629)
* bump versions (#628) ([7652d53](https://github.com/peaceiris/actions-hugo/commit/7652d5336914f4ecd975baff70cd3c4b5070678b)), closes [#628](https://github.com/peaceiris/actions-hugo/issues/628)
* remove braces (#634) ([31c4654](https://github.com/peaceiris/actions-hugo/commit/31c46541ceabb0656cd9e943914ab1701da3e788)), closes [#634](https://github.com/peaceiris/actions-hugo/issues/634)
* replace set-output with GITHUB_OUTPUT ([3d92e2f](https://github.com/peaceiris/actions-hugo/commit/3d92e2fd556bef7470d7e2a6aea63141183c20a6))
* update cache usage (#636) ([c0084b0](https://github.com/peaceiris/actions-hugo/commit/c0084b0763db3a37f864755d9174f2a6f3e0c1c5)), closes [#636](https://github.com/peaceiris/actions-hugo/issues/636)
### feat
* bump to use node20 runtime (#641) ([c57490a](https://github.com/peaceiris/actions-hugo/commit/c57490a8b04136ae58ab5866a93d3db2f0fa0945)), closes [#641](https://github.com/peaceiris/actions-hugo/issues/641)
# [2.6.0](https://github.com/peaceiris/actions-hugo/compare/v2.5.0...v2.6.0) (2022-10-23) # [2.6.0](https://github.com/peaceiris/actions-hugo/compare/v2.5.0...v2.6.0) (2022-10-23)

View File

@ -91,7 +91,7 @@ jobs:
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '0.119.0' hugo-version: '0.119.0'
# extended: true # extended: true
@ -121,7 +121,7 @@ Set `extended: true` to use a Hugo extended version.
```yaml ```yaml
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '0.119.0' hugo-version: '0.119.0'
extended: true extended: true
@ -133,7 +133,7 @@ Set `hugo-version: 'latest'` to use the latest version of Hugo.
```yaml ```yaml
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: 'latest' hugo-version: 'latest'
``` ```
@ -190,7 +190,7 @@ Next, add a step to read a Hugo version from the `.env` file.
echo "HUGO_VERSION=${HUGO_VERSION}" >> "${GITHUB_OUTPUT}" echo "HUGO_VERSION=${HUGO_VERSION}" >> "${GITHUB_OUTPUT}"
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '${{ steps.hugo-version.outputs.HUGO_VERSION }}' hugo-version: '${{ steps.hugo-version.outputs.HUGO_VERSION }}'
extended: true extended: true
@ -256,7 +256,7 @@ jobs:
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '0.119.0' hugo-version: '0.119.0'
extended: true extended: true
@ -310,7 +310,7 @@ jobs:
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '0.119.0' hugo-version: '0.119.0'
extended: true extended: true
@ -364,7 +364,7 @@ jobs:
run: git config core.quotePath false run: git config core.quotePath false
- name: Setup Hugo - name: Setup Hugo
uses: peaceiris/actions-hugo@v2 uses: peaceiris/actions-hugo@v3
with: with:
hugo-version: '0.119.0' hugo-version: '0.119.0'
``` ```

View File

@ -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 }) => {
expect(() => { test.each(tests)('%s', ({ arch, os, throws, expected }) => {
getArch('mips'); if (throws) {
}).toThrowError('mips is not supported'); expect(() => {
}); getArch(arch, os, conventions)
}).toThrow(`${arch} is not supported`);
} else {
expect(getArch(arch, os, conventions)).toBe(expected);
}
})
})
}); });

View 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);
});
});

View File

@ -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');
}); });
}); });

2
package-lock.json generated
View File

@ -6,7 +6,7 @@
"packages": { "packages": {
"": { "": {
"name": "actions-hugo", "name": "actions-hugo",
"version": "3.0.0", "version": "2.6.0",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

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 (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
View 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
}
}
}

View File

@ -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`);
} }

View File

@ -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);