feat: initial commit
This commit is contained in:
10
src/index.ts
Normal file
10
src/index.ts
Normal 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
8
src/post.ts
Normal 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
11
src/stages/configure.ts
Normal 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
29
src/stages/install.ts
Normal 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
9
src/stages/push.ts
Normal 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]);
|
||||
};
|
||||
Reference in New Issue
Block a user