Skip to content

Commit

Permalink
feat: update example with latest package
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Jun 13, 2024
1 parent 0c5bf2e commit 36b30c1
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 85 deletions.
5 changes: 2 additions & 3 deletions actions/example-ts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const createConfig = require("@kcws/eslint-config")
const createConfig = require("@kcws/eslint-config");
module.exports = createConfig({
cwd: __dirname,
profile: "node",
typescript: true,
jest: true,
prettier: true,
ecma: "latest",
})
});
4 changes: 2 additions & 2 deletions actions/example-ts/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const createConfig = require("@kcws/prettier-config")
module.exports = createConfig({})
const createConfig = require("@kcws/prettier-config");
module.exports = createConfig({});
14 changes: 12 additions & 2 deletions actions/example-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
"name": "@kcactions/example-ts",
"version": "0.1.0",
"main": "lib/index.js",
"homepage": "https://github.com/kc-workspace/github-actions-src/tree/main/actions/example-ts",
"repository": {
"type": "git",
"url": "https://github.com/kc-workspace/github-actions-src.git",
"directory": "actions/example-ts"
},
"author": {
"name": "Kamontat Chantrachirathumrong",
"email": "[email protected]",
"url": "https://github.com/kamontat"
},
"scripts": {
Expand All @@ -18,14 +25,17 @@
"@actions/github": "6.0.0",
"@actions/http-client": "2.2.1",
"@actions/io": "1.1.3",
"@kcws/github-actions": "0.5.0"
"@kcws/github-actions": "0.6.0"
},
"devDependencies": {
"@kcws/eslint-config": "1.21.1",
"@kcws/heft-node-rig": "0.19.0",
"@kcws/heft-node-rig": "0.22.0",
"@kcws/prettier-config": "0.17.2",
"@rushstack/heft": "0.66.18",
"@types/heft-jest": "1.0.6",
"@types/node": "20.14.2"
},
"engines": {
"node": ">=20"
}
}
15 changes: 11 additions & 4 deletions actions/example-ts/src/app/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import actions, { context } from "."
import { ContextBuilder } from "@kcws/github-actions"

import app, { context } from "."

describe("app", () => {
it("should executes runner", async () => {
const runner = jest.fn()
await actions.exec(runner)
await app.exec(runner)
expect(runner).toHaveBeenCalledTimes(1)
})
})

describe("app.context", () => {
it("should contains metadata", () => {
expect(context.name).not.toBe("")
expect(context.version).not.toBe("")
// By default package.json should not found on source code
// because package.json is NOT on the same directory as source code
expect(context.name).toBe("")
expect(context.version).toBe("")

ContextBuilder.fromContext(context)
})

it("should contains plugins", () => {
expect(context.use("input")).not.toBeFalsy()
expect(context.use("log")).not.toBeFalsy()
expect(context.use("exec")).not.toBeFalsy()
})
})
14 changes: 0 additions & 14 deletions actions/example-ts/src/index.test.ts

This file was deleted.

18 changes: 3 additions & 15 deletions actions/example-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import { AppRunner } from "@kcws/github-actions"
import app from "./app"
import runner from "./runners/main"

import actions from "./app"

const runner: AppRunner<typeof actions> = (data, context) => {
const logger = context.use("log")

logger.info(process.cwd())
logger.info(__dirname)
logger.info("Use {0}: {1}", context.name, context.version)
logger.info("hello {name}", data.input)
}

actions.exec(runner)

export default runner
app.exec(runner)
13 changes: 3 additions & 10 deletions actions/example-ts/src/post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { AppRunner } from "@kcws/github-actions"
import app from "./app"
import runner from "./runners/post"

import actions from "./app"

const runner: AppRunner<typeof actions> = (data, context) => {
context.use("log").info("hello post {name}", data.input)
}

actions.exec(runner)

export default runner
app.exec(runner)
13 changes: 3 additions & 10 deletions actions/example-ts/src/pre.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { AppRunner } from "@kcws/github-actions"
import app from "./app"
import runner from "./runners/pre"

import actions from "./app"

const runner: AppRunner<typeof actions> = (data, context) => {
context.use("log").info("hello pre {name}", data.input)
}

actions.exec(runner)

export default runner
app.exec(runner)
22 changes: 22 additions & 0 deletions actions/example-ts/src/runners/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
jest.mock("@actions/core")

import { info } from "@actions/core"

import app from "../app"
import runner from "./main"

describe("application runner", () => {
test("should print info logs with default value", async () => {
await app.exec(runner)

expect(info).toHaveBeenCalled()
expect(info).toHaveBeenLastCalledWith("hello world")
})

test("should print info logs with custom value", async () => {
await app.exec(runner, { name: "name" })

expect(info).toHaveBeenCalled()
expect(info).toHaveBeenLastCalledWith("hello name")
})
})
12 changes: 12 additions & 0 deletions actions/example-ts/src/runners/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AppRunner } from "@kcws/github-actions"

import app from "../app"

const runner: AppRunner<typeof app> = (data, context) => {
const logger = context.use("log")

logger.info("Use {0}: {1}", context.name, context.version)
logger.info("hello {name}", data.input)
}

export default runner
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ jest.mock("@actions/core")

import { info } from "@actions/core"

import { context } from "./app"
import app from "../app"
import runner from "./post"

describe("[post-hook] application runner", () => {
test("should print info logs", async () => {
await runner({ input: { name: "name" } }, context)
app.exec(runner)
expect(info).toHaveBeenCalledTimes(1)
expect(info).toHaveBeenCalledWith("hello post name")
expect(info).toHaveBeenCalledWith("hello post world")
})
})
9 changes: 9 additions & 0 deletions actions/example-ts/src/runners/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AppRunner } from "@kcws/github-actions"

import app from "../app"

const runner: AppRunner<typeof app> = (data, context) => {
context.use("log").info("hello post {name}", data.input)
}

export default runner
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ jest.mock("@actions/core")

import { info } from "@actions/core"

import { context } from "./app"
import app from "../app"
import runner from "./pre"

describe("[pre-hook] application runner", () => {
test("should print info logs", async () => {
await runner({ input: { name: "name" } }, context)
app.exec(runner)
expect(info).toHaveBeenCalledTimes(1)
expect(info).toHaveBeenCalledWith("hello pre name")
expect(info).toHaveBeenCalledWith("hello pre world")
})
})
9 changes: 9 additions & 0 deletions actions/example-ts/src/runners/pre.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AppRunner } from "@kcws/github-actions"

import app from "../app"

const runner: AppRunner<typeof app> = (data, context) => {
context.use("log").info("hello pre {name}", data.input)
}

export default runner
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

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

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
packages:
- "actions/*"
- "utils/*"

0 comments on commit 36b30c1

Please sign in to comment.