From b2fd603d9e26312cc396bad62b69f9f82fd4d3b0 Mon Sep 17 00:00:00 2001 From: yusancky Date: Mon, 5 Feb 2024 21:57:21 +0800 Subject: [PATCH] Fix for core.getState --- src/main.ts | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main.ts b/src/main.ts index 315c06a..b008695 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,7 +28,7 @@ if (version === "latest") { } else { const releases = await octokit.paginate( octokit.rest.repos.listReleases, - repoSet, + repoSet ); const versions = releases.map((release) => release.tag_name.slice(1)); version = semver.maxSatisfying(versions, version)!; @@ -36,7 +36,7 @@ if (version === "latest") { core.debug(`Resolved version: v${version}`); if (!version) throw new DOMException( - `${core.getInput("typst-version")} resolved to ${version}`, + `${core.getInput("typst-version")} resolved to ${version}` ); let found = tc.find("typst", version); @@ -58,7 +58,7 @@ if (!found) { const folder = `typst-${target}`; const file = `${folder}${archiveExt}`; found = await tc.downloadTool( - `https://github.com/typst/typst/releases/download/v${version}/${file}`, + `https://github.com/typst/typst/releases/download/v${version}/${file}` ); if (file.endsWith(".zip")) { found = await tc.extractZip(found); @@ -76,40 +76,35 @@ core.info(`✅ Typst v${version} installed!`); const cachePackage = core.getInput("cache-dependency-path"); if (cachePackage) { if (fs.existsSync(cachePackage)) { - const cachePath = { + const cacheDir = { linux: join(process.env.XDG_CACHE_HOME!, "typst/packages"), darwin: join(process.env.HOME!, "/Library/Caches/typst/packages"), win32: join(process.env.LOCALAPPDATA!, "typst/packages"), }[process.platform.toString()]!; const hash = await glob.hashFiles(cachePackage); const cacheKey = await cache.restoreCache( - [cachePath], + [cacheDir], `typst-packages-${hash}`, - ["typst-packages-", "typst-"], + ["typst-packages-", "typst-"] ); if (cacheKey != undefined) { core.info(`✅ Packages downloaded from cache!`); } else { - const cachePathState = core.getState(cachePath); await exec.exec(`typst compile ${cachePackage}`); - if (!cachePathState) { - core.warning("Cache path is empty. Please check the previous logs."); - } else { - let cacheId = 0; - try { - cacheId = await cache.saveCache([cachePath], `typst-package-${hash}`); - } catch (err) { - const message = (err as Error).message; - core.warning(message); - } - if (cacheId != -1) { - core.info(`Cache saved with the key: typst-package-${hash}`); - } + let cacheId = 0; + try { + cacheId = await cache.saveCache([cacheDir], `typst-package-${hash}`); + } catch (err) { + const message = (err as Error).message; + core.warning(message); + } + if (cacheId != -1) { + core.info(`Cache saved with the key: typst-package-${hash}`); } } } else { core.warning( - "The file with the name as same as the `cache` input was not found. Packages will not be cached.", + "The file with the name as same as the `cache` input was not found. Packages will not be cached." ); } }