Skip to content

Commit

Permalink
Fix for core.getState
Browse files Browse the repository at this point in the history
  • Loading branch information
yusancky authored Feb 5, 2024
1 parent 9d92508 commit b2fd603
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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)!;
}
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);
Expand All @@ -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);
Expand All @@ -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."
);
}
}

0 comments on commit b2fd603

Please sign in to comment.