Move index.js

This commit is contained in:
2024-06-16 21:20:37 -06:00
parent 8e8ff90bd6
commit f3a0d79b76
5 changed files with 0 additions and 0 deletions

31
stages/configure.ts Normal file
View File

@@ -0,0 +1,31 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { saveStorePaths } from "../utils";
export const configure = async () => {
core.startGroup("Configure attic");
try {
const endpoint = core.getInput("endpoint");
const cache = core.getInput("cache");
const token = core.getInput("token");
const skipUse = core.getInput("skip-use");
core.info("Logging in to attic cache");
await exec("/run/current-system/sw/bin/attic", ["login", "--set-default", cache, endpoint, token]);
if (skipUse === "true") {
core.info("Not adding attic cache to substituters as skip-use is set to true");
} else {
core.info("Adding attic cache to substituters");
await exec("/run/current-system/sw/bin/attic", ["use", cache]);
}
core.info("Collecting store paths before build");
await saveStorePaths();
} catch (e) {
core.setFailed(`Action failed with error: ${e}`);
}
core.endGroup();
};

40
stages/install.ts Normal file
View File

@@ -0,0 +1,40 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import { writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
export const install = async () => {
core.startGroup("Install attic");
core.info("Installing attic");
const installScript = await fetch(
"https://raw.githubusercontent.com/zhaofengli/attic/main/.github/install-attic-ci.sh",
).then((r) => {
if (!r.ok) {
core.setFailed(`Action failed with error: ${r.statusText}`);
core.endGroup();
process.exit(1);
}
return r.text();
});
try {
const installScriptPath = join(tmpdir(), "install-attic-ci.sh");
await writeFile(installScriptPath, installScript);
core.info("Running install script");
await exec("bash", [installScriptPath]);
} catch (e) {
core.setFailed(`Action failed with error: ${e}`);
}
core.endGroup();
};
export const isInstalled = async () => {
let return_code = await exec("/run/current-system/sw/bin/attic", ["-V"]);
return return_code === 0;
};

40
stages/push.ts Normal file
View File

@@ -0,0 +1,40 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import splitArray from "just-split";
import { saveStorePaths, getStorePaths } from "../utils";
export const push = async () => {
core.startGroup("Push to Attic");
try {
const skipPush = core.getInput("skip-push");
if (skipPush === "true") {
core.info("Pushing to cache is disabled by skip-push");
} else {
const cache = core.getInput("cache");
core.info("Pushing to cache");
const oldPaths = await getStorePaths();
await saveStorePaths();
const newPaths = await getStorePaths();
const addedPaths = newPaths
.filter((p) => !oldPaths.includes(p))
.filter(
(p) => !p.endsWith(".drv") && !p.endsWith(".drv.chroot") && !p.endsWith(".check") && !p.endsWith(".lock"),
);
const splitAddedPaths = splitArray(addedPaths, 25);
for (const addedPaths of splitAddedPaths) {
await exec("/run/current-system/sw/bin/attic", ["push", cache, ...addedPaths]);
}
}
} catch (e) {
core.warning(`Action encountered error: ${e}`);
core.info("Not considering errors during push a failure.");
}
core.endGroup();
};