Compare commits

...

3 commits

Author SHA1 Message Date
d7ba37343c
tests(withdeploy): add tests for withdeploy
Some checks failed
Renovate / renovate (push) Successful in 54s
Check Transpiled JavaScript / Check dist/ (push) Successful in 41s
Continuous Integration / TypeScript Tests (push) Successful in 58s
Continuous Integration / GitHub Actions Test (push) Failing after 6s
2024-11-27 20:47:44 +01:00
35de0fc568
fix: include extended & with deploy in tool version for proper caching
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Successful in 52s
Continuous Integration / TypeScript Tests (push) Successful in 56s
Renovate / renovate (push) Successful in 54s
Continuous Integration / GitHub Actions Test (push) Failing after 6s
2024-11-27 20:29:19 +01:00
10b6b9aa45
feat: support with deploy option
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Failing after 38s
Continuous Integration / GitHub Actions Test (push) Successful in 9s
Continuous Integration / TypeScript Tests (push) Successful in 52s
Renovate / renovate (push) Successful in 56s
2024-11-27 20:14:56 +01:00
7 changed files with 117 additions and 26 deletions

View file

@ -43,6 +43,8 @@ jobs:
- name: Test - name: Test
id: npm-ci-test id: npm-ci-test
run: npm run ci-test run: npm run ci-test
env:
GITHUB_TOKEN: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
test-action: test-action:
name: GitHub Actions Test name: GitHub Actions Test
@ -59,6 +61,8 @@ jobs:
with: with:
extended: true extended: true
dart-sass: true dart-sass: true
with-deploy: true
github-token: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
- name: Test installed tools - name: Test installed tools
id: test-tools id: test-tools

View file

@ -18,7 +18,9 @@ afterEach(() => {
describe('Install Hugo', () => { describe('Install Hugo', () => {
test('Download latest Hugo', async () => { test('Download latest Hugo', async () => {
const releaseLookup = new OctokitReleaseLookup() const releaseLookup = new OctokitReleaseLookup(
process.env.GITHUB_TOKEN || undefined
)
const platformMock = new Platform('linux', undefined, { HOME: tmpDir }) const platformMock = new Platform('linux', undefined, { HOME: tmpDir })
const hugo = new HugoInstaller(releaseLookup, platformMock) const hugo = new HugoInstaller(releaseLookup, platformMock)
@ -29,4 +31,36 @@ describe('Install Hugo', () => {
}) })
).not.toThrow() ).not.toThrow()
}, 30_000) }, 30_000)
test('Download latest Hugo - extended', async () => {
const releaseLookup = new OctokitReleaseLookup(
process.env.GITHUB_TOKEN || undefined
)
const platformMock = new Platform('linux', undefined, { HOME: tmpDir })
const hugo = new HugoInstaller(releaseLookup, platformMock)
expect(
async () =>
await hugo.install({
version: 'latest',
extended: true
})
).not.toThrow()
}, 30_000)
test('Download latest Hugo - with deploy', async () => {
const releaseLookup = new OctokitReleaseLookup(
process.env.GITHUB_TOKEN || undefined
)
const platformMock = new Platform('linux', undefined, { HOME: tmpDir })
const hugo = new HugoInstaller(releaseLookup, platformMock)
expect(
async () =>
await hugo.install({
version: 'latest',
withDeploy: true
})
).not.toThrow()
}, 30_000)
}) })

View file

@ -15,6 +15,12 @@ inputs:
description: 'Download (if necessary) dart-sass' description: 'Download (if necessary) dart-sass'
required: false required: false
default: 'false' default: 'false'
with-deploy:
description:
'Fetch a Hugo build that includes the deploy command - if true, will
override the extended option'
required: false
default: 'false'
dart-sass-version: dart-sass-version:
description: description:
'The dart-sass version to download.ts (if necessary) and use. Example: 'The dart-sass version to download.ts (if necessary) and use. Example:

40
dist/index.js vendored
View file

@ -50809,13 +50809,21 @@ class HugoInstaller {
} }
async install(cmd) { async install(cmd) {
const release = await this.releaseLookup.getRelease(Hugo.Org, Hugo.Repo, cmd.version, HugoReleaseTransformer); const release = await this.releaseLookup.getRelease(Hugo.Org, Hugo.Repo, cmd.version, HugoReleaseTransformer);
core.debug(`Hugo extended: ${cmd.extended}`); core.debug(`Hugo extended: ${cmd.extended ?? false}`);
core.debug(`Hugo with deploy: ${cmd.withDeploy ?? false}`);
core.debug(`Operating System: ${this.platform.os}`); core.debug(`Operating System: ${this.platform.os}`);
core.debug(`Processor Architecture: ${this.platform.arch}`); core.debug(`Processor Architecture: ${this.platform.arch}`);
const hugoBinName = this.platform.binaryName(Hugo.CmdName); const hugoBinName = this.platform.binaryName(Hugo.CmdName);
const tmpDir = external_node_os_namespaceObject.tmpdir(); const tmpDir = external_node_os_namespaceObject.tmpdir();
let versionSpec = release.tag_name;
if (cmd.extended) {
versionSpec = `${release.tag_name}+extended`;
}
else if (cmd.withDeploy) {
versionSpec = `${release.tag_name}+extended+withdeploy`;
}
try { try {
const cachedTool = tool_cache.find(Hugo.Name, release.tag_name, this.platform.arch); const cachedTool = tool_cache.find(Hugo.Name, versionSpec, this.platform.arch);
if (cachedTool) { if (cachedTool) {
core.addPath(cachedTool); core.addPath(cachedTool);
return; return;
@ -50824,7 +50832,7 @@ class HugoInstaller {
catch (e) { catch (e) {
core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`); core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`);
} }
const toolUrl = release.assetUrl(this.platform, cmd.extended); const toolUrl = release.assetUrl(this.platform, cmd.extended, cmd.withDeploy);
if (!toolUrl) { if (!toolUrl) {
throw new Error('No matching URL detected for given platform'); throw new Error('No matching URL detected for given platform');
} }
@ -50839,7 +50847,7 @@ class HugoInstaller {
} }
await (0,io.rmRF)(destPath); await (0,io.rmRF)(destPath);
try { try {
const cachedHugoPath = await tool_cache.cacheFile(external_path_default().join(tmpDir, hugoBinName), hugoBinName, Hugo.Name, release.tag_name, this.platform.arch); const cachedHugoPath = await tool_cache.cacheFile(external_path_default().join(tmpDir, hugoBinName), hugoBinName, Hugo.Name, versionSpec, this.platform.arch);
core.addPath(cachedHugoPath); core.addPath(cachedHugoPath);
} }
catch (e) { catch (e) {
@ -50857,16 +50865,21 @@ const HugoReleaseTransformer = {
} }
}; };
class HugoRelease { class HugoRelease {
static keyReplacementRegex = new RegExp('hugo_(extended_)*(\\d+.\\d+.\\d+)_'); static keyReplacementRegex = new RegExp('hugo_(extended_)*(withdeploy_)*(\\d+.\\d+.\\d+)_');
tag_name; tag_name;
defaultAssets; defaultAssets;
extendedAssets; extendedAssets;
withDeployAssets;
constructor(tag_name, assets) { constructor(tag_name, assets) {
this.tag_name = tag_name; this.tag_name = tag_name;
this.defaultAssets = new Map(); this.defaultAssets = new Map();
this.extendedAssets = new Map(); this.extendedAssets = new Map();
this.withDeployAssets = new Map();
for (const asset of assets) { for (const asset of assets) {
if (asset.name.includes('extended')) { if (asset.name.includes('extended_withdeploy')) {
this.withDeployAssets.set(asset.name.replace(HugoRelease.keyReplacementRegex, ''), asset.browser_download_url);
}
else if (asset.name.includes('extended')) {
this.extendedAssets.set(asset.name.replace(HugoRelease.keyReplacementRegex, ''), asset.browser_download_url); this.extendedAssets.set(asset.name.replace(HugoRelease.keyReplacementRegex, ''), asset.browser_download_url);
} }
else { else {
@ -50874,11 +50887,17 @@ class HugoRelease {
} }
} }
} }
assetUrl(platform, extended) { assetUrl(platform, extended, withDeploy) {
const src = extended ? this.extendedAssets : this.defaultAssets; let assets = this.defaultAssets;
if (extended) {
assets = this.extendedAssets;
}
else if (withDeploy) {
assets = this.withDeployAssets;
}
const arch = platform.os === 'darwin' ? 'universal' : platform.arch; const arch = platform.os === 'darwin' ? 'universal' : platform.arch;
const key = `${platform.os}-${arch}${platform.archiveExtension()}`; const key = `${platform.os}-${arch}${platform.archiveExtension()}`;
return src.get(key); return assets.get(key);
} }
} }
@ -51006,7 +51025,8 @@ async function run() {
const hugoInstaller = new HugoInstaller(releaseLookup); const hugoInstaller = new HugoInstaller(releaseLookup);
await hugoInstaller.install({ await hugoInstaller.install({
version: core.getInput('hugo-version'), version: core.getInput('hugo-version'),
extended: core.getBooleanInput('extended') extended: core.getBooleanInput('extended'),
withDeploy: core.getBooleanInput('with-deploy')
}); });
if (!core.getBooleanInput('dart-sass')) if (!core.getBooleanInput('dart-sass'))
return; return;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -13,6 +13,7 @@ import { errorMsg } from './utils/error'
export interface IHugoInstallCommand { export interface IHugoInstallCommand {
version?: string version?: string
extended?: boolean extended?: boolean
withDeploy?: boolean
} }
export class HugoInstaller { export class HugoInstaller {
@ -32,19 +33,23 @@ export class HugoInstaller {
HugoReleaseTransformer HugoReleaseTransformer
) )
core.debug(`Hugo extended: ${cmd.extended}`) core.debug(`Hugo extended: ${cmd.extended ?? false}`)
core.debug(`Hugo with deploy: ${cmd.withDeploy ?? false}`)
core.debug(`Operating System: ${this.platform.os}`) core.debug(`Operating System: ${this.platform.os}`)
core.debug(`Processor Architecture: ${this.platform.arch}`) core.debug(`Processor Architecture: ${this.platform.arch}`)
const hugoBinName = this.platform.binaryName(Hugo.CmdName) const hugoBinName = this.platform.binaryName(Hugo.CmdName)
const tmpDir = os.tmpdir() const tmpDir = os.tmpdir()
let versionSpec = release.tag_name
if (cmd.extended) {
versionSpec = `${release.tag_name}+extended`
} else if (cmd.withDeploy) {
versionSpec = `${release.tag_name}+extended+withdeploy`
}
try { try {
const cachedTool = tc.find( const cachedTool = tc.find(Hugo.Name, versionSpec, this.platform.arch)
Hugo.Name,
release.tag_name,
this.platform.arch
)
if (cachedTool) { if (cachedTool) {
core.addPath(cachedTool) core.addPath(cachedTool)
return return
@ -53,7 +58,11 @@ export class HugoInstaller {
core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`) core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`)
} }
const toolUrl = release.assetUrl(this.platform, cmd.extended) const toolUrl = release.assetUrl(
this.platform,
cmd.extended,
cmd.withDeploy
)
if (!toolUrl) { if (!toolUrl) {
throw new Error('No matching URL detected for given platform') throw new Error('No matching URL detected for given platform')
@ -79,7 +88,7 @@ export class HugoInstaller {
path.join(tmpDir, hugoBinName), path.join(tmpDir, hugoBinName),
hugoBinName, hugoBinName,
Hugo.Name, Hugo.Name,
release.tag_name, versionSpec,
this.platform.arch this.platform.arch
) )
@ -103,13 +112,14 @@ export const HugoReleaseTransformer = {
export class HugoRelease implements IGithubRelease { export class HugoRelease implements IGithubRelease {
private static readonly keyReplacementRegex = new RegExp( private static readonly keyReplacementRegex = new RegExp(
'hugo_(extended_)*(\\d+.\\d+.\\d+)_' 'hugo_(extended_)*(withdeploy_)*(\\d+.\\d+.\\d+)_'
) )
readonly tag_name: string readonly tag_name: string
private readonly defaultAssets: Map<string, string> private readonly defaultAssets: Map<string, string>
private readonly extendedAssets: Map<string, string> private readonly extendedAssets: Map<string, string>
private readonly withDeployAssets: Map<string, string>
constructor( constructor(
tag_name: string, tag_name: string,
@ -118,9 +128,15 @@ export class HugoRelease implements IGithubRelease {
this.tag_name = tag_name this.tag_name = tag_name
this.defaultAssets = new Map<string, string>() this.defaultAssets = new Map<string, string>()
this.extendedAssets = new Map<string, string>() this.extendedAssets = new Map<string, string>()
this.withDeployAssets = new Map<string, string>()
for (const asset of assets) { for (const asset of assets) {
if (asset.name.includes('extended')) { if (asset.name.includes('extended_withdeploy')) {
this.withDeployAssets.set(
asset.name.replace(HugoRelease.keyReplacementRegex, ''),
asset.browser_download_url
)
} else if (asset.name.includes('extended')) {
this.extendedAssets.set( this.extendedAssets.set(
asset.name.replace(HugoRelease.keyReplacementRegex, ''), asset.name.replace(HugoRelease.keyReplacementRegex, ''),
asset.browser_download_url asset.browser_download_url
@ -134,11 +150,21 @@ export class HugoRelease implements IGithubRelease {
} }
} }
assetUrl(platform: Platform, extended?: boolean): string | undefined { assetUrl(
const src = extended ? this.extendedAssets : this.defaultAssets platform: Platform,
extended?: boolean,
withDeploy?: boolean
): string | undefined {
let assets = this.defaultAssets
if (extended) {
assets = this.extendedAssets
} else if (withDeploy) {
assets = this.withDeployAssets
}
const arch = platform.os === 'darwin' ? 'universal' : platform.arch const arch = platform.os === 'darwin' ? 'universal' : platform.arch
const key = `${platform.os}-${arch}${platform.archiveExtension()}` const key = `${platform.os}-${arch}${platform.archiveExtension()}`
return src.get(key) return assets.get(key)
} }
} }

View file

@ -11,7 +11,8 @@ export async function run(): Promise<void> {
await hugoInstaller.install({ await hugoInstaller.install({
version: core.getInput('hugo-version'), version: core.getInput('hugo-version'),
extended: core.getBooleanInput('extended') extended: core.getBooleanInput('extended'),
withDeploy: core.getBooleanInput('with-deploy')
}) })
if (!core.getBooleanInput('dart-sass')) return if (!core.getBooleanInput('dart-sass')) return