Skip to content

Commit

Permalink
feat: migrate to new github-actions version
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Jun 14, 2024
1 parent 7c18412 commit 6c6ddae
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 29 deletions.
9 changes: 2 additions & 7 deletions actions/setup-asdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@
"clean": "heft clean"
},
"dependencies": {
"@actions/cache": "3.2.4",
"@actions/core": "1.10.1",
"@actions/exec": "1.1.1",
"@actions/github": "6.0.0",
"@actions/http-client": "2.2.1",
"@actions/io": "1.1.3",
"@kcws/github-actions": "0.8.1"
"@kcws/github-actions": "0.9.0"
},
"devDependencies": {
"@kcws/eslint-config": "1.21.1",
"@kcws/heft-node-rig": "0.25.0",
"@kcws/heft-node-rig": "0.26.0",
"@kcws/prettier-config": "0.17.2",
"@rushstack/heft": "0.66.18",
"@types/heft-jest": "1.0.6",
Expand Down
2 changes: 2 additions & 0 deletions actions/setup-asdf/src/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ describe("app.context", () => {
expect(context.use("cache")).not.toBeFalsy()
expect(context.use("log")).not.toBeFalsy()
expect(context.use("exec")).not.toBeFalsy()
expect(context.use("io")).not.toBeFalsy()
expect(context.use("system")).not.toBeFalsy()
})
})
6 changes: 6 additions & 0 deletions actions/setup-asdf/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import {
ExecContextPlugin,
CacheContextPlugin,
toBool,
SystemContextPlugin,
IOContextPlugin,
HelperContextPlugin,
} from "@kcws/github-actions"

export const context = ContextBuilder.fromPackageJson()
.addPlugin(new LogContextPlugin())
.addPlugin(new HelperContextPlugin())
.addPlugin(new CacheContextPlugin())
.addPlugin(new InputContextPlugin())
.addPlugin(new ExecContextPlugin())
.addPlugin(new SystemContextPlugin())
.addPlugin(new IOContextPlugin())
.build()

export default Actions.builder(context, context => {
Expand Down
22 changes: 12 additions & 10 deletions actions/setup-asdf/src/runners/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import type app from "../app"

import { join } from "node:path"
import { existsSync } from "node:fs"
import { which } from "@actions/io"
import { addPath, exportVariable, group } from "@actions/core"

import {
asdfPluginAdd,
Expand All @@ -16,7 +14,7 @@ import {
const runner: AppRunner<typeof app> = async (data, context) => {
await asdfSetup(data, context)

const path = await which("asdf", false)
const path = await context.use("io").which("asdf", false)
if (path === undefined || path === null || path === "") {
await asdfInstall(data, context)
}
Expand All @@ -28,19 +26,23 @@ const runner: AppRunner<typeof app> = async (data, context) => {
}

const asdfSetup: AppRunner<typeof app> = async (data, context) => {
return group("Set up asdf", async () => {
return context.use("helper").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"))
context.use("system").setEnvVar("ASDF_DIR", data.input.asdfDir)
context
.use("system")
.addPaths(
join(data.input.asdfDir, "bin"),
join(data.input.asdfDir, "shims")
)
})
}

const asdfInstall: AppRunner<typeof app> = async (data, context) => {
const executor = context.use("exec")
const logger = context.use("log")
return group("Install asdf", async () => {
return context.use("helper").group("Install asdf", async () => {
if (existsSync(data.input.asdfDir)) {
logger.info(
"Updating asdf to version '{0}' on (ASDF_DIR={1})",
Expand Down Expand Up @@ -88,7 +90,7 @@ const asdfInstall: AppRunner<typeof app> = async (data, context) => {
}

const asdfInstallPlugins: AppRunner<typeof app> = (data, context) => {
return group("Install asdf plugins", async () => {
return context.use("helper").group("Install asdf plugins", async () => {
const installed = await asdfPluginList(context)
const toolVersion = await asdfToolList(context, data.input.workDir)
await Promise.all(
Expand All @@ -102,7 +104,7 @@ const asdfInstallPlugins: AppRunner<typeof app> = (data, context) => {
}

const asdfInstallTools: AppRunner<typeof app> = (data, context) => {
return group("Install asdf tools", () => {
return context.use("helper").group("Install asdf tools", () => {
return asdfToolInstall(context, data.input.workDir)
})
}
Expand Down
1 change: 1 addition & 0 deletions common/resources/.github/tests/setup-asdf/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 20.14.0
16 changes: 11 additions & 5 deletions common/resources/.github/workflows/_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ jobs:
steps:
- name: Set up repository
uses: actions/checkout@v4
- name: example with default name
- name: with default name
uses: kc-workspace/github-actions/example-ts@main
- name: example [with] custom name
- name: '[with] custom name'
uses: kc-workspace/github-actions/example-ts@main
with:
name: custom
- name: example [env] custom name [action specific]
- name: '[env] custom name [action specific]'
uses: kc-workspace/github-actions/example-ts@main
env:
EXAMPLE_TS__NAME: action-specific
- name: example [env] custom name [generic name]
- name: '[env] custom name [generic name]'
uses: kc-workspace/github-actions/example-ts@main
env:
NAME: generic-name
Expand All @@ -28,7 +28,13 @@ jobs:
steps:
- name: Set up repository
uses: actions/checkout@v4
- uses: kc-workspace/github-actions/setup-asdf@main
- name: with default value
uses: kc-workspace/github-actions/setup-asdf@main
- name: with tools enabled
uses: kc-workspace/github-actions/setup-asdf@main
with:
workdir: .github/tests/setup-asdf
install-tools: true
test-create-hosts-dryrun:
runs-on: ubuntu-latest
steps:
Expand Down
42 changes: 35 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6c6ddae

Please sign in to comment.