feat: initial commit

This commit is contained in:
Ryan Cao
2023-07-18 22:17:42 +08:00
commit ac59a1f6d5
14 changed files with 509 additions and 0 deletions

10
src/index.ts Normal file
View File

@@ -0,0 +1,10 @@
import { install } from "./stages/install";
import { configure } from "./stages/configure";
(async () => {
await install();
await configure();
})().catch((e) => {
console.error(e);
process.exit(1);
});

8
src/post.ts Normal file
View File

@@ -0,0 +1,8 @@
import { push } from "./stages/push";
(async () => {
await push();
})().catch((e) => {
console.error(e);
process.exit(1);
});

11
src/stages/configure.ts Normal file
View File

@@ -0,0 +1,11 @@
import { getInput, startGroup, endGroup } from "@actions/core";
import { exec } from "@actions/exec";
export const configure = async () => {
startGroup("Configure attic");
const endpoint = getInput("endpoint");
const token = getInput("token");
await exec("attic", ["login", "--set-default", "ci", endpoint, token]);
endGroup();
};

29
src/stages/install.ts Normal file
View File

@@ -0,0 +1,29 @@
import { startGroup, endGroup } from "@actions/core";
import { exec } from "@actions/exec";
import { fetch } from "ofetch";
import { writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
export const install = async () => {
startGroup("Install attic");
const installScript = await fetch(
"https://raw.githubusercontent.com/zhaofengli/attic/main/.github/install-attic-ci.sh"
).then((r) => {
if (!r.ok)
throw new Error(
`Failed to fetch install script: ${r.status} ${r.statusText}`
);
return r.text();
});
const installScriptPath = join(tmpdir(), "install-attic-ci.sh");
await writeFile(installScriptPath, installScript);
await exec("bash", [installScriptPath]);
endGroup();
};

9
src/stages/push.ts Normal file
View File

@@ -0,0 +1,9 @@
import { getInput, getMultilineInput } from "@actions/core";
import { exec } from "@actions/exec";
export const push = async () => {
const cache = getInput("cache");
const paths = getMultilineInput("token");
await exec("attic", ["push", cache, ...paths]);
};