From 35945488a90c80ce448bd71058f9ca0bd71e6008 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong <14089557+kamontat@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:20:09 +0700 Subject: [PATCH] fix(setup-asdf): improve asdf install logs --- actions/setup-asdf/src/runners/main.ts | 111 +++++++++++++++---------- actions/setup-asdf/src/runners/post.ts | 3 + actions/setup-asdf/src/runners/pre.ts | 3 + 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/actions/setup-asdf/src/runners/main.ts b/actions/setup-asdf/src/runners/main.ts index 765b93f..a84d685 100644 --- a/actions/setup-asdf/src/runners/main.ts +++ b/actions/setup-asdf/src/runners/main.ts @@ -4,7 +4,7 @@ import type app from "../app" import { join } from "node:path" import { existsSync } from "node:fs" import { which } from "@actions/io" -import { addPath, exportVariable } from "@actions/core" +import { addPath, exportVariable, group } from "@actions/core" import { asdfPluginAdd, @@ -28,62 +28,83 @@ const runner: AppRunner = async (data, context) => { } const asdfSetup: AppRunner = async (data, context) => { - context.use("log").debug("Setting up system for asdf") + return group("Set up asdf", async () => { + context.use("log").debug("Setting up system for asdf") - exportVariable("ASDF_DIR", data.input.asdfDir) - addPath(join(data.input.asdfDir, "bin")) - addPath(join(data.input.asdfDir, "shims")) + exportVariable("ASDF_DIR", data.input.asdfDir) + addPath(join(data.input.asdfDir, "bin")) + addPath(join(data.input.asdfDir, "shims")) + }) } const asdfInstall: AppRunner = async (data, context) => { const executor = context.use("exec") const logger = context.use("log") - if (existsSync(data.input.asdfDir)) { - logger.info( - "Updating asdf to version '{0}' on (ASDF_DIR={1})", - data.input.ref, - data.input.asdfDir - ) + return group("Install asdf", async () => { + if (existsSync(data.input.asdfDir)) { + logger.info( + "Updating asdf to version '{0}' on (ASDF_DIR={1})", + data.input.ref, + data.input.asdfDir + ) - executor.withOptions({ cwd: data.input.asdfDir }) - executor.rerun("git", "remote", "set-branches", "origin", data.input.ref) - executor.rerun("git", "fetch", "--depth", "1", "origin", data.input.ref) - executor.rerun("git", "checkout", "-B", data.input.ref, "origin") - } else { - logger.info( - "Installing asdf version '{0}' on (ASDF_DIR={1})", - data.input.ref, - data.input.asdfDir - ) + executor.withOptions({ cwd: data.input.asdfDir }) + await executor.rerun( + "git", + "remote", + "set-branches", + "origin", + data.input.ref + ) + await executor.rerun( + "git", + "fetch", + "--depth", + "1", + "origin", + data.input.ref + ) + await executor.rerun("git", "checkout", "-B", data.input.ref, "origin") + } else { + logger.info( + "Installing asdf version '{0}' on (ASDF_DIR={1})", + data.input.ref, + data.input.asdfDir + ) - executor.rerun( - "git", - "clone", - "--depth", - "1", - "--branch", - data.input.ref, - "--single-branch", - "https://github.com/asdf-vm/asdf.git", - data.input.asdfDir - ) - } + await executor.rerun( + "git", + "clone", + "--depth", + "1", + "--branch", + data.input.ref, + "--single-branch", + "https://github.com/asdf-vm/asdf.git", + data.input.asdfDir + ) + } + }) } -const asdfInstallPlugins: AppRunner = async (data, context) => { - const installed = await asdfPluginList(context) - const toolVersion = await asdfToolList(context, data.input.workDir) - await Promise.all( - toolVersion.map(async ({ name }) => { - if (!installed.includes(name)) { - await asdfPluginAdd(context, name) - } - }) - ) +const asdfInstallPlugins: AppRunner = (data, context) => { + return group("Install asdf plugins", async () => { + const installed = await asdfPluginList(context) + const toolVersion = await asdfToolList(context, data.input.workDir) + await Promise.all( + toolVersion.map(async ({ name }) => { + if (!installed.includes(name)) { + await asdfPluginAdd(context, name) + } + }) + ) + }) } -const asdfInstallTools: AppRunner = async (data, context) => { - await asdfToolInstall(context, data.input.workDir) +const asdfInstallTools: AppRunner = (data, context) => { + return group("Install asdf tools", () => { + return asdfToolInstall(context, data.input.workDir) + }) } export default runner diff --git a/actions/setup-asdf/src/runners/post.ts b/actions/setup-asdf/src/runners/post.ts index 56d47b2..0dda404 100644 --- a/actions/setup-asdf/src/runners/post.ts +++ b/actions/setup-asdf/src/runners/post.ts @@ -4,6 +4,7 @@ import app from "../app" const runner: AppRunner = (data, context) => { if (data.input.cache.enabled) { + context.use("log").info("Uploading cache at {0}", data.input.asdfDir) context.use("cache").save( { system: true, @@ -11,6 +12,8 @@ const runner: AppRunner = (data, context) => { }, data.input.asdfDir ) + } else { + context.use("log").info("Disabled caching via user config") } } diff --git a/actions/setup-asdf/src/runners/pre.ts b/actions/setup-asdf/src/runners/pre.ts index b736a2c..ce7a715 100644 --- a/actions/setup-asdf/src/runners/pre.ts +++ b/actions/setup-asdf/src/runners/pre.ts @@ -4,6 +4,7 @@ import app from "../app" const runner: AppRunner = (data, context) => { if (data.input.cache.enabled) { + context.use("log").info("Downloading cache at {0}", data.input.asdfDir) context.use("cache").restore( { system: true, @@ -11,6 +12,8 @@ const runner: AppRunner = (data, context) => { }, data.input.asdfDir ) + } else { + context.use("log").info("Disabled caching via user config") } }