Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying custom Scarb.lock path #27

Merged
merged 12 commits into from
Oct 10, 2024
Next Next commit
Support scarb-lock argument
Use custom Scarb.lock path if provided
DelevoXDG committed Oct 9, 2024
commit d64ee3e1aa3041360893993fd4fe830e2fcfc41e
4 changes: 2 additions & 2 deletions lib/cache-restore.js
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@ import fs from "fs/promises";

import { getCacheDirectory, getCacheKey, State } from "./cache-utils";

export async function restoreCache() {
export async function restoreCache(scarbLockPath) {
const cacheDir = await getCacheDirectory();
await fs.mkdir(cacheDir, { recursive: true });

core.info(`Restoring Scarb cache into ${cacheDir}`);

const primaryKey = await getCacheKey();
const primaryKey = await getCacheKey(scarbLockPath);
core.info(`Cache primary key is ${primaryKey}`);
core.saveState(State.CachePrimaryKey, primaryKey);

8 changes: 4 additions & 4 deletions lib/cache-utils.js
Original file line number Diff line number Diff line change
@@ -54,9 +54,9 @@ function wellKnownCachePath() {
}
}

export async function getCacheKey() {
export async function getCacheKey(scarbLockfilePath) {
const platform = process.env.RUNNER_OS;
const fileHash = await glob.hashFiles(await getScarbLockfilePath());
const fileHash = await glob.hashFiles(await getScarbLockfilePath(scarbLockfilePath));

if (!fileHash) {
throw new Error(
@@ -67,8 +67,8 @@ export async function getCacheKey() {
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
}

async function getScarbLockfilePath() {
const lockfilePath = path.join(process.env.GITHUB_WORKSPACE, "Scarb.lock");
async function getScarbLockfilePath(scarbLockfilePath) {
const lockfilePath = path.join(process.env.GITHUB_WORKSPACE, scarbLockfilePath || "Scarb.lock");

await fs.access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
3 changes: 2 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ export default async function main() {
try {
const scarbVersionInput = core.getInput("scarb-version");
const toolVersionsPathInput = core.getInput("tool-versions");
const scarbLockPathInput = core.getInput("scarb-lock");

const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
scarbVersionInput,
@@ -47,7 +48,7 @@ export default async function main() {

core.setOutput("scarb-version", await getFullVersionFromScarb());

await restoreCache().catch((e) => {
await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e