From 16bd754a82ee143df12a0ed04b5c7ca90a287d52 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:43:43 +0800 Subject: [PATCH] add prettier config --- .prettierrc | 4 ++++ src/index.ts | 4 ++-- src/post.ts | 2 +- src/stages/configure.ts | 28 ++++++++++++------------- src/stages/install.ts | 42 ++++++++++++++++++------------------- src/stages/push.ts | 46 +++++++++++++++++++---------------------- src/utils.ts | 28 +++++++++++-------------- 7 files changed, 75 insertions(+), 79 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..bffbe16 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "useTabs": true, + "printWidth": 120 +} diff --git a/src/index.ts b/src/index.ts index a51ef2e..2eecccd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(); diff --git a/src/post.ts b/src/post.ts index 76193d5..67eecb3 100644 --- a/src/post.ts +++ b/src/post.ts @@ -1,7 +1,7 @@ import { push } from "./stages/push"; const main = async () => { - await push(); + await push(); }; main(); diff --git a/src/stages/configure.ts b/src/stages/configure.ts index d14bd5d..4929748 100644 --- a/src/stages/configure.ts +++ b/src/stages/configure.ts @@ -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(); }; diff --git a/src/stages/install.ts b/src/stages/install.ts index 4ba66eb..6968a92 100644 --- a/src/stages/install.ts +++ b/src/stages/install.ts @@ -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(); }; diff --git a/src/stages/push.ts b/src/stages/push.ts index 07584a8..41e940c 100644 --- a/src/stages/push.ts +++ b/src/stages/push.ts @@ -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(); }; diff --git a/src/utils.ts b/src/utils.ts index 20f3862..a38183a 100644 --- a/src/utils.ts +++ b/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, - _enc: unknown, - next: () => unknown - ) { - this.chunks.push(Buffer.from(chunk)); - next(); - } + _write(chunk: WithImplicitCoercion, _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; };