fix: save store paths to file (#5)

closes #4
This commit is contained in:
gallexme 2023-08-06 04:32:52 +02:00 committed by GitHub
parent e78c87fc0e
commit 56ba67dfc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 25 deletions

View file

@ -1,6 +1,6 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import { exec } from "@actions/exec"; import { exec } from "@actions/exec";
import { getStorePaths } from "../utils"; import { saveStorePaths } from "../utils";
export const configure = async () => { export const configure = async () => {
core.startGroup("Configure attic"); core.startGroup("Configure attic");
@ -14,8 +14,7 @@ export const configure = async () => {
await exec("attic", ["login", "--set-default", cache, endpoint, token]); await exec("attic", ["login", "--set-default", cache, endpoint, token]);
core.info("Collecting store paths before build"); core.info("Collecting store paths before build");
const paths = await getStorePaths(); await saveStorePaths();
core.saveState("initial-paths", JSON.stringify(paths));
} catch (e) { } catch (e) {
core.setFailed(`Action failed with error: ${e}`); core.setFailed(`Action failed with error: ${e}`);
} }

View file

@ -2,8 +2,7 @@ import * as core from "@actions/core";
import { exec } from "@actions/exec"; import { exec } from "@actions/exec";
import splitArray from "just-split"; import splitArray from "just-split";
import { getStorePaths } from "../utils"; import { saveStorePaths, getStorePaths } from "../utils";
export const push = async () => { export const push = async () => {
core.startGroup("Push to Attic"); core.startGroup("Push to Attic");
@ -15,7 +14,8 @@ export const push = async () => {
const cache = core.getInput("cache"); const cache = core.getInput("cache");
core.info("Pushing to cache"); core.info("Pushing to cache");
const oldPaths = JSON.parse(core.getState("initial-paths")) as string[]; const oldPaths = await getStorePaths();
await saveStorePaths();
const newPaths = await getStorePaths(); const newPaths = await getStorePaths();
const addedPaths = newPaths const addedPaths = newPaths
.filter((p) => !oldPaths.includes(p)) .filter((p) => !oldPaths.includes(p))

View file

@ -1,23 +1,10 @@
import { exec } from "@actions/exec"; import { exec } from "@actions/exec";
import { Writable } from "node:stream";
class StringStream extends Writable { import { readFile } from "node:fs/promises";
chunks: Buffer[] = [];
_write(chunk: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, _enc: unknown, next: () => unknown) { export const saveStorePaths = async () => {
this.chunks.push(Buffer.from(chunk)); await exec("sh", ["-c", "nix path-info --all --json > /tmp/store-paths"]);
next(); };
} export const getStorePaths = async () => {
return JSON.parse(await readFile("/tmp/store-paths", "utf8")).map((path) => path.path);
string() {
return Buffer.concat(this.chunks).toString("utf-8");
}
}
export const getStorePaths = async () => {
const outStream = new StringStream();
await exec("nix", ["path-info", "--all"], { outStream });
const paths = outStream.string().split("\n").filter(Boolean);
return paths;
}; };