Documentation
¶
Overview ¶
Package codegen provides schema fetching and code generation for GitHub Actions.
Index ¶
- Variables
- func ActionURL(owner, repo string) string
- func GetGoFieldName(name string) string
- func GetGoTypeName(name string) string
- type ActionBranding
- type ActionInput
- type ActionOutput
- type ActionRuns
- type ActionSpec
- type ActionWrapperConfig
- type Fetcher
- func (f *Fetcher) Fetch(url string) ([]byte, error)
- func (f *Fetcher) FetchAction(name string) ([]byte, error)
- func (f *Fetcher) FetchActionByOwnerRepo(owner, repo string) ([]byte, error)
- func (f *Fetcher) FetchAll(outputDir string) (*Manifest, error)
- func (f *Fetcher) FetchSchema(schemaType SchemaType) ([]byte, error)
- type Field
- type GeneratedCode
- type Generator
- type Manifest
- type ManifestAction
- type ManifestSchema
- type SchemaDefinition
- type SchemaProperty
- type SchemaType
- type WorkflowSchema
Constants ¶
This section is empty.
Variables ¶
var PopularActions = map[string]struct{ Owner, Repo string }{
"checkout": {"actions", "checkout"},
"setup-go": {"actions", "setup-go"},
"setup-node": {"actions", "setup-node"},
"setup-python": {"actions", "setup-python"},
"cache": {"actions", "cache"},
"upload-artifact": {"actions", "upload-artifact"},
"download-artifact": {"actions", "download-artifact"},
}
PopularActions contains commonly used GitHub Actions.
var SchemaURLs = map[SchemaType]string{ SchemaWorkflow: "https://json.schemastore.org/github-workflow.json", SchemaDependabot: "https://json.schemastore.org/dependabot-2.0.json", SchemaIssueForms: "https://json.schemastore.org/github-issue-forms.json", }
SchemaURLs contains the URLs for various JSON schemas.
Functions ¶
func ActionURL ¶
ActionURL returns the URL for an action's action.yml file. Pattern: https://raw.githubusercontent.com/{owner}/{repo}/main/action.yml
func GetGoFieldName ¶
GetGoFieldName converts a kebab-case or snake_case input name to Go field name.
func GetGoTypeName ¶
GetGoTypeName converts an action name to a Go type name.
Types ¶
type ActionBranding ¶
type ActionBranding struct {
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
Color string `yaml:"color,omitempty" json:"color,omitempty"`
}
ActionBranding defines the branding for the action in GitHub marketplace.
type ActionInput ¶
type ActionInput struct {
Description string `yaml:"description" json:"description"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Default string `yaml:"default,omitempty" json:"default,omitempty"`
DeprecationMessage string `yaml:"deprecationMessage,omitempty" json:"deprecation_message,omitempty"`
}
ActionInput represents an input parameter for an action.
type ActionOutput ¶
type ActionOutput struct {
Description string `yaml:"description" json:"description"`
Value string `yaml:"value,omitempty" json:"value,omitempty"`
}
ActionOutput represents an output from an action.
type ActionRuns ¶
type ActionRuns struct {
Using string `yaml:"using" json:"using"`
Main string `yaml:"main,omitempty" json:"main,omitempty"`
Pre string `yaml:"pre,omitempty" json:"pre,omitempty"`
PreIf string `yaml:"pre-if,omitempty" json:"pre_if,omitempty"`
Post string `yaml:"post,omitempty" json:"post,omitempty"`
PostIf string `yaml:"post-if,omitempty" json:"post_if,omitempty"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Steps []any `yaml:"steps,omitempty" json:"steps,omitempty"` // For composite actions
}
ActionRuns defines how the action runs.
type ActionSpec ¶
type ActionSpec struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
Author string `yaml:"author,omitempty" json:"author,omitempty"`
Inputs map[string]ActionInput `yaml:"inputs,omitempty" json:"inputs,omitempty"`
Outputs map[string]ActionOutput `yaml:"outputs,omitempty" json:"outputs,omitempty"`
Runs ActionRuns `yaml:"runs" json:"runs"`
Branding *ActionBranding `yaml:"branding,omitempty" json:"branding,omitempty"`
}
ActionSpec represents a parsed action.yml file.
func ParseActionYAML ¶
func ParseActionYAML(data []byte) (*ActionSpec, error)
ParseActionYAML parses an action.yml file content into an ActionSpec.
func (*ActionSpec) GetInputNames ¶
func (a *ActionSpec) GetInputNames() []string
GetInputNames returns a sorted list of input names from an action spec.
func (*ActionSpec) GetOutputNames ¶
func (a *ActionSpec) GetOutputNames() []string
GetOutputNames returns a list of output names from an action spec.
func (*ActionSpec) GetRequiredInputs ¶
func (a *ActionSpec) GetRequiredInputs() []string
GetRequiredInputs returns a list of required input names.
func (*ActionSpec) IsCompositeAction ¶
func (a *ActionSpec) IsCompositeAction() bool
IsCompositeAction returns true if this is a composite action.
func (*ActionSpec) IsDockerAction ¶
func (a *ActionSpec) IsDockerAction() bool
IsDockerAction returns true if this is a Docker action.
func (*ActionSpec) IsJavaScriptAction ¶
func (a *ActionSpec) IsJavaScriptAction() bool
IsJavaScriptAction returns true if this is a JavaScript/Node action.
type ActionWrapperConfig ¶
type ActionWrapperConfig struct {
// ActionRef is the full action reference (e.g., "actions/checkout@v4")
ActionRef string
// PackageName is the Go package name (e.g., "checkout")
PackageName string
// TypeName is the Go struct name (e.g., "Checkout")
TypeName string
// Spec is the parsed action.yml
Spec *ActionSpec
}
ActionWrapperConfig configures how an action wrapper is generated.
type Fetcher ¶
Fetcher handles HTTP requests for schemas with retry logic.
func NewFetcher ¶
func NewFetcher() *Fetcher
NewFetcher creates a new Fetcher with default settings.
func (*Fetcher) FetchAction ¶
FetchAction fetches an action.yml file for the given action.
func (*Fetcher) FetchActionByOwnerRepo ¶
FetchActionByOwnerRepo fetches an action.yml file for the given owner/repo.
func (*Fetcher) FetchAll ¶
FetchAll fetches all schemas and actions to the specified output directory. Returns the manifest of fetched files.
func (*Fetcher) FetchSchema ¶
func (f *Fetcher) FetchSchema(schemaType SchemaType) ([]byte, error)
FetchSchema fetches a JSON schema by type.
type GeneratedCode ¶
GeneratedCode contains the result of code generation.
type Generator ¶
type Generator struct{}
Generator generates Go code from action specs.
func (*Generator) GenerateActionWrapper ¶
func (g *Generator) GenerateActionWrapper(config ActionWrapperConfig) (*GeneratedCode, error)
GenerateActionWrapper generates a Go wrapper for an action.
func (*Generator) GenerateActionWrapperFromYAML ¶
func (g *Generator) GenerateActionWrapperFromYAML(yaml []byte, actionRef string) (*GeneratedCode, error)
GenerateActionWrapperFromYAML generates a wrapper from raw action.yml content.
type Manifest ¶
type Manifest struct {
Version string `json:"version"`
Schemas []ManifestSchema `json:"schemas"`
Actions []ManifestAction `json:"actions"`
FetchedAt string `json:"fetched_at"`
}
Manifest represents the specs/manifest.json file.
type ManifestAction ¶
type ManifestAction struct {
Name string `json:"name"`
Owner string `json:"owner"`
Repo string `json:"repo"`
URL string `json:"url"`
File string `json:"file"`
}
ManifestAction represents an action entry in the manifest.
type ManifestSchema ¶
type ManifestSchema struct {
Type SchemaType `json:"type"`
URL string `json:"url"`
File string `json:"file"`
}
ManifestSchema represents a schema entry in the manifest.
type SchemaDefinition ¶
type SchemaDefinition struct {
SchemaProperty
Title string `json:"title,omitempty"`
}
SchemaDefinition represents a definition in a JSON schema.
type SchemaProperty ¶
type SchemaProperty struct {
Type any `json:"type,omitempty"` // string or []string
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
Ref string `json:"$ref,omitempty"`
Items *SchemaProperty `json:"items,omitempty"`
Properties map[string]SchemaProperty `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
OneOf []SchemaProperty `json:"oneOf,omitempty"`
AnyOf []SchemaProperty `json:"anyOf,omitempty"`
AllOf []SchemaProperty `json:"allOf,omitempty"`
Pattern string `json:"pattern,omitempty"`
MinItems *int `json:"minItems,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
}
SchemaProperty represents a property in a JSON schema.
func (*SchemaProperty) GetPropertyType ¶
func (p *SchemaProperty) GetPropertyType() string
GetPropertyType returns a string representation of the property type.
type SchemaType ¶
type SchemaType string
SchemaType represents a type of schema that can be fetched.
const ( SchemaWorkflow SchemaType = "workflow" SchemaDependabot SchemaType = "dependabot" SchemaIssueForms SchemaType = "issue-forms" SchemaAction SchemaType = "action" )
type WorkflowSchema ¶
type WorkflowSchema struct {
Schema string `json:"$schema,omitempty"`
ID string `json:"$id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Properties map[string]SchemaProperty `json:"properties,omitempty"`
Definitions map[string]SchemaDefinition `json:"definitions,omitempty"`
Required []string `json:"required,omitempty"`
}
WorkflowSchema represents a parsed JSON schema for workflows.
func ParseWorkflowSchema ¶
func ParseWorkflowSchema(data []byte) (*WorkflowSchema, error)
ParseWorkflowSchema parses a JSON schema for workflows.
func (*WorkflowSchema) ResolveRef ¶
func (s *WorkflowSchema) ResolveRef(ref string) (*SchemaDefinition, error)
ResolveRef resolves a $ref in a JSON schema.