fix: add dart-sass to PATH
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Failing after 35s
Continuous Integration / GitHub Actions Test (push) Failing after 8s
Continuous Integration / TypeScript Tests (push) Successful in 48s

This commit is contained in:
Peter 2024-05-03 16:34:46 +02:00
parent 07d6db952e
commit 47b2964798
Signed by: prskr
GPG key ID: F56BED6903BC5E37
5 changed files with 56 additions and 17 deletions

View file

@ -0,0 +1,32 @@
import fs from 'node:fs'
import path from 'path'
import os from 'node:os'
import { OctokitReleaseLookup } from '../src/asset-lookup'
import { Platform } from '../src/os'
import { DartSassInstaller } from '../src/dart-sass'
let tmpDir = ''
beforeEach(() => {
jest.resetModules()
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-hugo-'))
})
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true })
})
describe('Install dart-sass', () => {
test('Download latest dart-sass', async () => {
const releaseLookup = new OctokitReleaseLookup()
const platformMock = new Platform('linux', undefined, { HOME: tmpDir })
const dartSassInstaller = new DartSassInstaller(releaseLookup, platformMock)
expect(
async () =>
await dartSassInstaller.install({
version: 'latest'
})
).not.toThrow()
})
})

15
dist/index.js vendored
View file

@ -49450,12 +49450,9 @@ class HugoInstaller {
try {
const cachedTool = tool_cache.find(Hugo.Name, release.tag_name, this.platform.arch);
if (cachedTool) {
await (0,io.cp)(cachedTool, external_path_default().join(binDir, hugoBinName));
core.addPath(cachedTool);
return;
}
else {
core.info('Tool not present in cache - downloading it...');
}
}
catch (e) {
core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`);
@ -49555,8 +49552,8 @@ class OctokitReleaseLookup {
class DartSassInstaller {
releaseLookup;
platform;
constructor(releaseLookup) {
this.platform = new Platform();
constructor(releaseLookup, platform) {
this.platform = platform ?? new Platform();
this.releaseLookup = releaseLookup;
}
async install(cmd) {
@ -49567,9 +49564,12 @@ class DartSassInstaller {
const binDir = await this.platform.ensureBinDir(workDir);
const tmpDir = external_node_os_namespaceObject.tmpdir();
try {
core.addPath(tool_cache.find(DartSass.Name, release.tag_name, this.platform.arch));
const cachedDartSass = tool_cache.find(DartSass.Name, release.tag_name, this.platform.arch);
if (cachedDartSass) {
core.addPath(cachedDartSass);
return;
}
}
catch (e) {
core.warning(`Failed to lookup cached version: ${errorMsg(e)}`);
}
@ -49595,6 +49595,7 @@ class DartSassInstaller {
}
catch (e) {
core.warning(`Failed to cache dart-sass directory: ${errorMsg(e)}`);
core.addPath(external_path_default().join(binDir, 'dart-sass'));
}
}
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -18,8 +18,8 @@ export class DartSassInstaller {
private readonly releaseLookup: IReleaseLookup
private readonly platform: Platform
constructor(releaseLookup: IReleaseLookup) {
this.platform = new Platform()
constructor(releaseLookup: IReleaseLookup, platform?: Platform) {
this.platform = platform ?? new Platform()
this.releaseLookup = releaseLookup
}
@ -39,8 +39,15 @@ export class DartSassInstaller {
const tmpDir = os.tmpdir()
try {
core.addPath(tc.find(DartSass.Name, release.tag_name, this.platform.arch))
const cachedDartSass = tc.find(
DartSass.Name,
release.tag_name,
this.platform.arch
)
if (cachedDartSass) {
core.addPath(cachedDartSass)
return
}
} catch (e) {
core.warning(`Failed to lookup cached version: ${errorMsg(e)}`)
}
@ -82,6 +89,7 @@ export class DartSassInstaller {
)
} catch (e) {
core.warning(`Failed to cache dart-sass directory: ${errorMsg(e)}`)
core.addPath(path.join(binDir, 'dart-sass'))
}
}
}

View file

@ -6,7 +6,7 @@ import { components } from '@octokit/openapi-types'
import * as tc from '@actions/tool-cache'
import path from 'path'
import * as os from 'node:os'
import { mv, rmRF, cp } from '@actions/io'
import { mv, rmRF } from '@actions/io'
import { randomUUID } from 'crypto'
import { errorMsg } from './utils/error'
@ -48,10 +48,8 @@ export class HugoInstaller {
this.platform.arch
)
if (cachedTool) {
await cp(cachedTool, path.join(binDir, hugoBinName))
core.addPath(cachedTool)
return
} else {
core.info('Tool not present in cache - downloading it...')
}
} catch (e) {
core.warning(`Failed to lookup tool in cache: ${errorMsg(e)}`)