Skip to content

API Reference

The GitHub Action Parser library provides a comprehensive set of types and functions for parsing, validating, and processing GitHub Action and Workflow YAML files.

Package Overview

go
import "github.com/scagogogo/github-action-parser/pkg/parser"

The parser package contains all the functionality needed to work with GitHub Actions and Workflows:

  • Core Types: Data structures representing GitHub Action and Workflow components
  • Parser Functions: Functions to parse YAML files and directories
  • Validation: Tools to validate parsed files according to GitHub specifications
  • Utilities: Helper functions for type conversion and data processing

Quick Reference

Main Functions

FunctionDescription
ParseFile(path string)Parse a single YAML file
Parse(r io.Reader)Parse from an io.Reader
ParseDir(dir string)Parse all YAML files in a directory
NewValidator()Create a new validator instance

Core Types

TypeDescription
ActionFileMain structure representing an action or workflow
InputInput parameter definition
OutputOutput parameter definition
JobWorkflow job definition
StepIndividual step in a job
RunsConfigAction execution configuration

Validation Types

TypeDescription
ValidatorValidator for GitHub Action specifications
ValidationErrorValidation error information

Utility Types

TypeDescription
StringOrStringSliceFlexible string/array type for YAML

Error Handling

All parsing functions return errors that provide detailed information about parsing failures:

go
action, err := parser.ParseFile("action.yml")
if err != nil {
    // Handle parsing error
    fmt.Printf("Failed to parse: %v\n", err)
    return
}

Validation errors are returned as a slice of ValidationError structs:

go
validator := parser.NewValidator()
errors := validator.Validate(action)
for _, err := range errors {
    fmt.Printf("Field %s: %s\n", err.Field, err.Message)
}

Type Safety

The library provides full type safety for all GitHub Action and Workflow structures. All fields are properly typed according to the GitHub Actions specification, with appropriate use of pointers for optional fields and interfaces for flexible data types.

Performance

The parser is optimized for performance and can efficiently handle:

  • Large action and workflow files
  • Batch processing of multiple files
  • Recursive directory parsing
  • Memory-efficient processing of large repositories

Next Steps

Released under the MIT License.