Compare commits
3 commits
renovate/n
...
main
Author | SHA1 | Date | |
---|---|---|---|
d7ba37343c | |||
35de0fc568 | |||
10b6b9aa45 |
7 changed files with 117 additions and 26 deletions
|
@ -43,6 +43,8 @@ jobs:
|
|||
- name: Test
|
||||
id: npm-ci-test
|
||||
run: npm run ci-test
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
|
||||
|
||||
test-action:
|
||||
name: GitHub Actions Test
|
||||
|
@ -59,6 +61,8 @@ jobs:
|
|||
with:
|
||||
extended: true
|
||||
dart-sass: true
|
||||
with-deploy: true
|
||||
github-token: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
|
||||
|
||||
- name: Test installed tools
|
||||
id: test-tools
|
||||
|
|
|
@ -18,7 +18,9 @@ afterEach(() => {
|
|||
|
||||
describe('Install Hugo', () => {
|
||||
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 hugo = new HugoInstaller(releaseLookup, platformMock)
|
||||
|
||||
|
@ -29,4 +31,36 @@ describe('Install Hugo', () => {
|
|||
})
|
||||
).not.toThrow()
|
||||
}, 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)
|
||||
})
|
||||
|
|
|
@ -15,6 +15,12 @@ inputs:
|
|||
description: 'Download (if necessary) dart-sass'
|
||||
required: 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:
|
||||
description:
|
||||
'The dart-sass version to download.ts (if necessary) and use. Example:
|
||||
|
|
40
dist/index.js
vendored
40
dist/index.js
vendored
|
@ -50809,13 +50809,21 @@ class HugoInstaller {
|
|||
}
|
||||
async install(cmd) {
|
||||
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(`Processor Architecture: ${this.platform.arch}`);
|
||||
const hugoBinName = this.platform.binaryName(Hugo.CmdName);
|
||||
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 {
|
||||
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) {
|
||||
core.addPath(cachedTool);
|
||||
return;
|
||||
|
@ -50824,7 +50832,7 @@ class HugoInstaller {
|
|||
catch (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) {
|
||||
throw new Error('No matching URL detected for given platform');
|
||||
}
|
||||
|
@ -50839,7 +50847,7 @@ class HugoInstaller {
|
|||
}
|
||||
await (0,io.rmRF)(destPath);
|
||||
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);
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -50857,16 +50865,21 @@ const HugoReleaseTransformer = {
|
|||
}
|
||||
};
|
||||
class HugoRelease {
|
||||
static keyReplacementRegex = new RegExp('hugo_(extended_)*(\\d+.\\d+.\\d+)_');
|
||||
static keyReplacementRegex = new RegExp('hugo_(extended_)*(withdeploy_)*(\\d+.\\d+.\\d+)_');
|
||||
tag_name;
|
||||
defaultAssets;
|
||||
extendedAssets;
|
||||
withDeployAssets;
|
||||
constructor(tag_name, assets) {
|
||||
this.tag_name = tag_name;
|
||||
this.defaultAssets = new Map();
|
||||
this.extendedAssets = new Map();
|
||||
this.withDeployAssets = new Map();
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
@ -50874,11 +50887,17 @@ class HugoRelease {
|
|||
}
|
||||
}
|
||||
}
|
||||
assetUrl(platform, extended) {
|
||||
const src = extended ? this.extendedAssets : this.defaultAssets;
|
||||
assetUrl(platform, extended, withDeploy) {
|
||||
let assets = this.defaultAssets;
|
||||
if (extended) {
|
||||
assets = this.extendedAssets;
|
||||
}
|
||||
else if (withDeploy) {
|
||||
assets = this.withDeployAssets;
|
||||
}
|
||||
const arch = platform.os === 'darwin' ? 'universal' : platform.arch;
|
||||
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);
|
||||
await hugoInstaller.install({
|
||||
version: core.getInput('hugo-version'),
|
||||
extended: core.getBooleanInput('extended')
|
||||
extended: core.getBooleanInput('extended'),
|
||||
withDeploy: core.getBooleanInput('with-deploy')
|
||||
});
|
||||
if (!core.getBooleanInput('dart-sass'))
|
||||
return;
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
52
src/hugo.ts
52
src/hugo.ts
|
@ -13,6 +13,7 @@ import { errorMsg } from './utils/error'
|
|||
export interface IHugoInstallCommand {
|
||||
version?: string
|
||||
extended?: boolean
|
||||
withDeploy?: boolean
|
||||
}
|
||||
|
||||
export class HugoInstaller {
|
||||
|
@ -32,19 +33,23 @@ export class HugoInstaller {
|
|||
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(`Processor Architecture: ${this.platform.arch}`)
|
||||
|
||||
const hugoBinName = this.platform.binaryName(Hugo.CmdName)
|
||||
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 {
|
||||
const cachedTool = tc.find(
|
||||
Hugo.Name,
|
||||
release.tag_name,
|
||||
this.platform.arch
|
||||
)
|
||||
const cachedTool = tc.find(Hugo.Name, versionSpec, this.platform.arch)
|
||||
if (cachedTool) {
|
||||
core.addPath(cachedTool)
|
||||
return
|
||||
|
@ -53,7 +58,11 @@ export class HugoInstaller {
|
|||
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) {
|
||||
throw new Error('No matching URL detected for given platform')
|
||||
|
@ -79,7 +88,7 @@ export class HugoInstaller {
|
|||
path.join(tmpDir, hugoBinName),
|
||||
hugoBinName,
|
||||
Hugo.Name,
|
||||
release.tag_name,
|
||||
versionSpec,
|
||||
this.platform.arch
|
||||
)
|
||||
|
||||
|
@ -103,13 +112,14 @@ export const HugoReleaseTransformer = {
|
|||
|
||||
export class HugoRelease implements IGithubRelease {
|
||||
private static readonly keyReplacementRegex = new RegExp(
|
||||
'hugo_(extended_)*(\\d+.\\d+.\\d+)_'
|
||||
'hugo_(extended_)*(withdeploy_)*(\\d+.\\d+.\\d+)_'
|
||||
)
|
||||
|
||||
readonly tag_name: string
|
||||
|
||||
private readonly defaultAssets: Map<string, string>
|
||||
private readonly extendedAssets: Map<string, string>
|
||||
private readonly withDeployAssets: Map<string, string>
|
||||
|
||||
constructor(
|
||||
tag_name: string,
|
||||
|
@ -118,9 +128,15 @@ export class HugoRelease implements IGithubRelease {
|
|||
this.tag_name = tag_name
|
||||
this.defaultAssets = new Map<string, string>()
|
||||
this.extendedAssets = new Map<string, string>()
|
||||
this.withDeployAssets = new Map<string, string>()
|
||||
|
||||
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
|
||||
|
@ -134,11 +150,21 @@ export class HugoRelease implements IGithubRelease {
|
|||
}
|
||||
}
|
||||
|
||||
assetUrl(platform: Platform, extended?: boolean): string | undefined {
|
||||
const src = extended ? this.extendedAssets : this.defaultAssets
|
||||
assetUrl(
|
||||
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 key = `${platform.os}-${arch}${platform.archiveExtension()}`
|
||||
|
||||
return src.get(key)
|
||||
return assets.get(key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ export async function run(): Promise<void> {
|
|||
|
||||
await hugoInstaller.install({
|
||||
version: core.getInput('hugo-version'),
|
||||
extended: core.getBooleanInput('extended')
|
||||
extended: core.getBooleanInput('extended'),
|
||||
withDeploy: core.getBooleanInput('with-deploy')
|
||||
})
|
||||
|
||||
if (!core.getBooleanInput('dart-sass')) return
|
||||
|
|
Loading…
Reference in a new issue