Skip to content

Commit

Permalink
fix(setup-asdf): improve asdf install logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Jun 14, 2024
1 parent 6a4c9e2 commit 3594548
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 45 deletions.
111 changes: 66 additions & 45 deletions actions/setup-asdf/src/runners/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,62 +28,83 @@ const runner: AppRunner<typeof app> = async (data, context) => {
}

const asdfSetup: AppRunner<typeof app> = 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<typeof app> = 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<typeof app> = 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<typeof app> = (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<typeof app> = async (data, context) => {
await asdfToolInstall(context, data.input.workDir)
const asdfInstallTools: AppRunner<typeof app> = (data, context) => {
return group("Install asdf tools", () => {
return asdfToolInstall(context, data.input.workDir)
})
}

export default runner
3 changes: 3 additions & 0 deletions actions/setup-asdf/src/runners/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import app from "../app"

const runner: AppRunner<typeof app> = (data, context) => {
if (data.input.cache.enabled) {
context.use("log").info("Uploading cache at {0}", data.input.asdfDir)
context.use("cache").save(
{
system: true,
custom: [data.input.cache.key],
},
data.input.asdfDir
)
} else {
context.use("log").info("Disabled caching via user config")
}
}

Expand Down
3 changes: 3 additions & 0 deletions actions/setup-asdf/src/runners/pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import app from "../app"

const runner: AppRunner<typeof app> = (data, context) => {
if (data.input.cache.enabled) {
context.use("log").info("Downloading cache at {0}", data.input.asdfDir)
context.use("cache").restore(
{
system: true,
custom: [data.input.cache.key],
},
data.input.asdfDir
)
} else {
context.use("log").info("Disabled caching via user config")
}
}

Expand Down

0 comments on commit 3594548

Please sign in to comment.