mirror of
https://github.com/ryanccn/attic-action.git
synced 2024-11-19 22:16:35 +00:00
add prettier config
This commit is contained in:
parent
5f106d5966
commit
16bd754a82
7 changed files with 75 additions and 79 deletions
4
.prettierrc
Normal file
4
.prettierrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"useTabs": true,
|
||||
"printWidth": 120
|
||||
}
|
|
@ -2,8 +2,8 @@ import { install } from "./stages/install";
|
|||
import { configure } from "./stages/configure";
|
||||
|
||||
const main = async () => {
|
||||
await install();
|
||||
await configure();
|
||||
await install();
|
||||
await configure();
|
||||
};
|
||||
|
||||
main();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { push } from "./stages/push";
|
||||
|
||||
const main = async () => {
|
||||
await push();
|
||||
await push();
|
||||
};
|
||||
|
||||
main();
|
||||
|
|
|
@ -3,22 +3,22 @@ import { exec } from "@actions/exec";
|
|||
import { getStorePaths } from "../utils";
|
||||
|
||||
export const configure = async () => {
|
||||
core.startGroup("Configure attic");
|
||||
core.startGroup("Configure attic");
|
||||
|
||||
try {
|
||||
const endpoint = core.getInput("endpoint");
|
||||
const cache = core.getInput("cache");
|
||||
const token = core.getInput("token");
|
||||
try {
|
||||
const endpoint = core.getInput("endpoint");
|
||||
const cache = core.getInput("cache");
|
||||
const token = core.getInput("token");
|
||||
|
||||
core.info("Logging in to attic cache");
|
||||
await exec("attic", ["login", "--set-default", cache, endpoint, token]);
|
||||
core.info("Logging in to attic cache");
|
||||
await exec("attic", ["login", "--set-default", cache, endpoint, token]);
|
||||
|
||||
core.info("Collecting store paths before build");
|
||||
const paths = await getStorePaths();
|
||||
core.saveState("initial-paths", JSON.stringify(paths));
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
}
|
||||
core.info("Collecting store paths before build");
|
||||
const paths = await getStorePaths();
|
||||
core.saveState("initial-paths", JSON.stringify(paths));
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
}
|
||||
|
||||
core.endGroup();
|
||||
core.endGroup();
|
||||
};
|
||||
|
|
|
@ -7,31 +7,31 @@ import { tmpdir } from "node:os";
|
|||
import { join } from "node:path";
|
||||
|
||||
export const install = async () => {
|
||||
core.startGroup("Install attic");
|
||||
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();
|
||||
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);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return r.text();
|
||||
});
|
||||
return r.text();
|
||||
});
|
||||
|
||||
try {
|
||||
const installScriptPath = join(tmpdir(), "install-attic-ci.sh");
|
||||
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}`);
|
||||
}
|
||||
await writeFile(installScriptPath, installScript);
|
||||
core.info("Running install script");
|
||||
await exec("bash", [installScriptPath]);
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
}
|
||||
|
||||
core.endGroup();
|
||||
core.endGroup();
|
||||
};
|
||||
|
|
|
@ -3,33 +3,29 @@ import { exec } from "@actions/exec";
|
|||
import { getStorePaths } from "../utils";
|
||||
|
||||
export const push = async () => {
|
||||
core.startGroup("Push to Attic");
|
||||
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");
|
||||
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 = JSON.parse(core.getState("initial-paths")) as string[];
|
||||
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")
|
||||
);
|
||||
core.info("Pushing to cache");
|
||||
const oldPaths = JSON.parse(core.getState("initial-paths")) as string[];
|
||||
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"),
|
||||
);
|
||||
|
||||
await exec("attic", ["push", cache, ...addedPaths]);
|
||||
}
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
}
|
||||
await exec("attic", ["push", cache, ...addedPaths]);
|
||||
}
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error: ${e}`);
|
||||
}
|
||||
|
||||
core.endGroup();
|
||||
core.endGroup();
|
||||
};
|
||||
|
|
28
src/utils.ts
28
src/utils.ts
|
@ -2,26 +2,22 @@ import { exec } from "@actions/exec";
|
|||
import { Writable } from "node:stream";
|
||||
|
||||
class StringStream extends Writable {
|
||||
chunks: Buffer[] = [];
|
||||
chunks: Buffer[] = [];
|
||||
|
||||
_write(
|
||||
chunk: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
|
||||
_enc: unknown,
|
||||
next: () => unknown
|
||||
) {
|
||||
this.chunks.push(Buffer.from(chunk));
|
||||
next();
|
||||
}
|
||||
_write(chunk: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, _enc: unknown, next: () => unknown) {
|
||||
this.chunks.push(Buffer.from(chunk));
|
||||
next();
|
||||
}
|
||||
|
||||
string() {
|
||||
return Buffer.concat(this.chunks).toString("utf-8");
|
||||
}
|
||||
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);
|
||||
const outStream = new StringStream();
|
||||
await exec("nix", ["path-info", "--all"], { outStream });
|
||||
const paths = outStream.string().split("\n").filter(Boolean);
|
||||
|
||||
return paths;
|
||||
return paths;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue