Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JLarky/gha-ts

 
 

Repository files navigation

GitHub Release GitHub License

gha-ts gha-ts

A TypeScript library for writing GitHub Actions workflows and rendering them to YAML.

  • Designed closely with stefma/pkl-gha semantics (but we don't do camel-case -> kebab-case conversions for actions)
  • Stable YAML rendering (Bun’s Bun.YAML or npm yaml)

What?

Author GitHub Actions workflows in TypeScript with strong typing and helpful validation, then render to YAML for .github/workflows/.

  • Strong typing: Catch errors at build-time instead of in CI.
  • Deterministic YAML: Stable key ordering and converters.

Install

If using Bun:

bunx jsr add -D @jlarky/gha-ts # or bun add -D @jlarky/gha-ts

If using Node.js:

npx nypm add -D @jlarky/gha-ts yaml # or npx jsr add -D @jlarky/gha-ts

Notes:

  • Bun users will import YAML from bun and node users will use yaml from npm.
  • This example is using Bun, but you can find other examples in the examples directory.

Quickstart

Create a workflow module at .github/workflows/example-bun.main.ts (when using Bun):

#!/usr/bin/env bun
import { YAML } from "bun";
import { workflow } from "@jlarky/gha-ts/workflow-types";
import { checkout } from "@jlarky/gha-ts/actions";
import { generateWorkflow } from "@jlarky/gha-ts/cli";

const wf = workflow({
  name: "Example workflow",
  on: {
    push: { branches: ["main"] },
    pull_request: {},
  },
  jobs: {
    exampleJob: {
      "runs-on": "ubuntu-latest",
      steps: [
        checkout({ "fetch-depth": 0 }),
        { name: "Test", run: "echo 'Hello, world!'" },
      ],
    },
  },
});

await generateWorkflow(wf, YAML.stringify, import.meta.url);

Examples

License

MIT

Alternatives

Non JavaScript/TypeScript:

About

Type-safe GitHub Action workflows

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Pkl 50.4%
  • TypeScript 49.4%
  • Shell 0.2%