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
27 changes: 24 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: "Create bare bones Scarb.toml for cache testing"
- name: "Create bare bones Scarb.lock for cache testing"
shell: bash
run: |
cat <<EOF > Scarb.toml
[package]
cat <<EOF > Scarb.lock
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "example_package"
version = "1.0.0"
EOF

- name: "Create Scarb.lock in subfolder for cache testing"
shell: bash
run: |
mkdir ./subdir
cat <<EOF > ./subdir/Scarb.lock
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "example_package"
version = "1.1.0"
EOF

- name: "Fetch latest Scarb version from GitHub releases"
id: version
shell: pwsh
Expand Down Expand Up @@ -73,6 +89,11 @@ jobs:
scarb-version: nightly
- run: scarb --version | grep "${{ steps.version.outputs.LATEST_NIGHTLY_VERSION }}"

- name: "Setup Scarb with `scarb-lock` file in subfolder"
uses: ./
with:
scarb-lock: ./subdir/Scarb.lock

- name: "Create .tool-versions file"
run: echo "scarb 0.7.0" >> .tool-versions
- name: "Setup Scarb using `.tool-versions` file"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- `tool-versions` - **Optional**. String.
- Stating a relative or absolute path to the `.tool-versions` file.
- Should be used only if `scarb-version` is not specified.
- `scarb-lock` - **Optional**. String.
- Stating a relative or absolute path to the `Scarb.lock` file used for caching dependencies.
- Empty/not specified: `Scarb.lock` in the working directory will be used.

## Outputs

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
tool-versions:
description: Path to .tool-versions file
required: false
scarb-lock:
description: Path to Scarb.lock file
required: false
outputs:
scarb-prefix:
description: The prefix of the installed Scarb
Expand Down
8 changes: 4 additions & 4 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73693,9 +73693,9 @@ function wellKnownCachePath() {
}
}

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

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

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

await fs.access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
Expand Down
2 changes: 1 addition & 1 deletion dist/cache-save/index.js.map

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74790,9 +74790,9 @@ function wellKnownCachePath() {
}
}

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

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

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

await promises_default().access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
Expand All @@ -74821,13 +74821,13 @@ async function getScarbLockfilePath() {



async function restoreCache() {
async function restoreCache(scarbLockPath) {
const cacheDir = await getCacheDirectory();
await promises_default().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);

Expand All @@ -74853,6 +74853,7 @@ 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,
Expand Down Expand Up @@ -74886,7 +74887,7 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/cache-restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

if (!fileHash) {
throw new Error(
Expand All @@ -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 getScarbLockPath(scarbLockPath) {
const lockfilePath = scarbLockPath || "Scarb.lock";

await fs.access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
Expand Down
3 changes: 2 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading