ghaction

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 6 Imported by: 0

README

ghaction

Generic GitHub Action and Workflow YAML generation — single source of truth for tinywasm composite actions and workflows.

No domain knowledge of gorelease, goflare or other consumers. Provides typed Go structs Action/Workflow + deterministic Render() + Sync() and optimal Node 24 presets.

Installation

go get github.com/tinywasm/ghaction@latest

Usage

Action (composite)
import "github.com/tinywasm/ghaction"

func GoreleaseAction() ghaction.Action {
  return ghaction.Action{
    Name: "Create GitHub Release",
    Steps: []ghaction.Step{
      {Name: "Setup Go", Uses: ghaction.DefaultSetupGo, With: []ghaction.KeyValue{{Key: "go-version-file", Value: "go.mod"}}},
      {Name: "Build", Shell: "bash", Run: buildScript},
    },
  }
}

// in tests/action_sync_test.go
func TestActionYmlIsInSync(t *testing.T) {
  a := GoreleaseAction()
  changed, _ := ghaction.Sync("../action.yml", a)
  if changed { t.Fatal("action.yml out of sync") }
}
Workflow (typed)
func ReleaseWorkflow() ghaction.Workflow {
  return ghaction.Workflow{
    Name: "Release",
    On: ghaction.On{Push: &ghaction.Push{Tags: []string{"v*"}}},
    Permissions: map[string]string{"contents": "write"},
    Jobs: map[string]ghaction.Job{
      "release": {
        RunsOn: ghaction.DefaultRunsOn,
        Steps: []ghaction.WorkflowStep{
          ghaction.CheckoutWithTags(),
          ghaction.SetupGoStep(),
          {Name: "Build", Shell: "bash", Run: buildScript},
        },
      },
    },
  }
}

// in tests/generation_test.go
func TestWorkflowsAreInSync(t *testing.T) {
  ghaction.SyncWorkflow("../.github/workflows/release.yml", ReleaseWorkflow())
}

Presets (optimal defaults, Node 24)

  • DefaultCheckout = "actions/checkout@v5" (Node 24)
  • DefaultSetupGo = "actions/setup-go@v6" (Node 24)
  • CheckoutStep(), CheckoutWithTags(), SetupGoStep(), GoVetStep(), GoTestStep(), PresetTestWorkflow()

Bumping Node versions happens once in presets.go; consumers get it via go get -u + gotest regen.

Why generic?

gorelease owns DefaultTargets, goflare owns TinyGoVersionghaction never hardcodes domain strings. Consumers generate bash from their own constants and pass Uses: ghaction.DefaultSetupGo to avoid hardcoding actions/setup-go@v6.

See action.go, workflow.go, presets.go for API.

Documentation

Index

Constants

View Source
const (
	DefaultCheckout      = "actions/checkout@v5"
	DefaultSetupGo       = "actions/setup-go@v6"
	DefaultRunsOn        = "ubuntu-latest"
	DefaultGoVersionFile = "go.mod"
)

Optimal defaults - single place to bump Node24 actions.

View Source
const HeaderGeneratedAction = `` /* 151-byte string literal not displayed */
View Source
const HeaderGeneratedWorkflow = `` /* 160-byte string literal not displayed */

Variables

This section is empty.

Functions

func Sync added in v0.1.0

func Sync(path string, a Action) (changed bool, err error)

Sync writes a's YAML to path when it differs from what is already there.

func SyncWorkflow added in v0.1.0

func SyncWorkflow(path string, w Workflow) (changed bool, err error)

SyncWorkflow writes w's YAML to path when it differs.

func WithCheckoutFetchDepth added in v0.1.0

func WithCheckoutFetchDepth(depth string) func(*WorkflowStep)

WithCheckoutFetchDepth overrides fetch-depth.

func WithCheckoutFetchTags added in v0.1.0

func WithCheckoutFetchTags(v string) func(*WorkflowStep)

WithCheckoutFetchTags overrides fetch-tags.

Types

type Action added in v0.1.0

type Action struct {
	Name        string
	Description string
	Author      string
	Branding    Branding
	Header      string
	Inputs      []Input
	Outputs     []Output
	Steps       []Step
}

func (Action) Render added in v0.1.0

func (a Action) Render() []byte

Render produces the action YAML. It is deterministic.

type Branding added in v0.1.0

type Branding struct {
	Icon  string
	Color string
}

type Input added in v0.1.0

type Input struct {
	Name        string
	Description string
	Default     string
	Required    bool
}

type Job added in v0.1.0

type Job struct {
	RunsOn      string
	If          string
	Permissions map[string]string
	Env         []KeyValue
	Steps       []WorkflowStep
}

Job is a single workflow job.

type KeyValue added in v0.1.0

type KeyValue struct {
	Key   string
	Value string
}

KeyValue is an ordered key-value pair.

type On added in v0.1.0

type On struct {
	Push             *Push
	PullRequest      *PullRequest
	Schedule         []Schedule
	WorkflowDispatch *WorkflowDispatch
}

On defines trigger events.

type Output added in v0.1.0

type Output struct {
	Name        string
	Description string
	Value       string
}

type PullRequest added in v0.1.0

type PullRequest struct {
	Branches []string
	Paths    []string
}

type Push added in v0.1.0

type Push struct {
	Branches []string
	Tags     []string
	Paths    []string
}

type Schedule added in v0.1.0

type Schedule struct {
	Cron string
}

type Step added in v0.1.0

type Step struct {
	Name    string
	ID      string
	If      string
	Uses    string
	With    []KeyValue
	Shell   string
	Run     string
	Env     []KeyValue
	Comment string
}

type Workflow added in v0.1.0

type Workflow struct {
	Name        string
	On          On
	Permissions map[string]string
	Jobs        map[string]Job
	Header      string
}

Workflow is a typed representation of a GitHub Actions workflow. It is generic and has no consumer domain knowledge.

func PresetTestWorkflow added in v0.1.0

func PresetTestWorkflow() Workflow

PresetTestWorkflow returns an optimal test workflow preset. Consumers can sync it in a test to avoid hardcoding test.yml.

func (Workflow) Render added in v0.1.0

func (w Workflow) Render() []byte

Render produces deterministic workflow YAML.

type WorkflowDispatch added in v0.1.0

type WorkflowDispatch struct{}

type WorkflowStep added in v0.1.0

type WorkflowStep struct {
	Name  string
	ID    string
	If    string
	Uses  string
	With  []KeyValue
	Run   string
	Shell string
	Env   []KeyValue
}

WorkflowStep is a step inside a job.

func CheckoutStep added in v0.1.0

func CheckoutStep(opts ...func(*WorkflowStep)) WorkflowStep

CheckoutStep returns a checkout step with optimal defaults. Use WithCheckoutFetchDepth / WithCheckoutFetchTags to override.

func CheckoutWithTags added in v0.1.0

func CheckoutWithTags() WorkflowStep

CheckoutWithTags returns checkout with fetch-depth 0 and fetch-tags true, optimal for release workflows.

func GoTestStep added in v0.1.0

func GoTestStep() WorkflowStep

GoTestStep returns a go test step.

func GoVetStep added in v0.1.0

func GoVetStep() WorkflowStep

GoVetStep returns a go vet step.

func SetupGoStep added in v0.1.0

func SetupGoStep(opts ...func(*WorkflowStep)) WorkflowStep

SetupGoStep returns setup-go with optimal defaults (Node24, go-version-file).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL