Go API
This document describes how to use jactionlint as Go library.
jactionlint can be used from Go programs by importing the module.
import "github.com/jdx/jactionlint/v2"See the documentation to know the list of all APIs. It contains a workflow file parser built on top of yaml/go-yaml library, expression ${{ }} lexer/parser/checker, etc.
Followings are unexhaustive list of interesting APIs.
Commandstruct represents entirejactionlintcommand.Command.Maintakes command line arguments and runs command until the end and returns exit status. Its signature is the same in v2. Only the parsing changed: the arguments are POSIX/GNU options (--format,-f), and a single-dash long option of v1 is an error that names the replacement. See the migration table.LinterOptionsis unchanged.Lintermanages linter lifecycle and applies checks to given files. If you want to run jactionlint checks in your program, please use this struct.ProjectandProjectsdetect a project (Git repository) in a given directory path and find configuration in it.Configrepresents structure ofjactionlint.yamlconfig file.ReadConfigFile()reads a file and resolves itsextends, andParseConfig()parses bytes.Config.RuleLevel()tells at whichSeveritya rule runs. Unknown keys are errors.Erroris a finding. It has the stable rule ID (ID), theSeverity, the region (Line,Column,EndLineandEndColumn), the documentation URL (DocURL) and an optional automaticFix, which is a list of byte-rangeTextEdits.Rules()returns theRuleInfoof every rule (ID, group, summary, default level, profile and options).LookupRule()finds one by its ID. The IDs are stable.RuleDocURL()returns the URL of the documentation of a rule.Severityis the level of a finding:SeverityInfo,SeverityWarningorSeverityError.SeverityOffdisables a rule.Profileis the set of rules enabled by the configuration:ProfileCorrectness,ProfileDefaultorProfilePedantic, each including the one before it.LinterOptions.Profileoverrides the profile of the configuration, like--profile.Linter.FixFiles()andLinter.FixRepository()apply the fixes of the errors (FixModeSafeorFixModeUnsafe; the...WithOptionsvariants takeFixOptions, for example to restrict the rules).MigrateConfig()andMigrateConfigFile()rewrite the deprecated keys of a config into therulesmapping,Linter.MigrateIgnores()andMigrateZizmorIgnores()rewrite# zizmor: ignore[...]comments, andLinter.WriteBaseline()writes a baseline. AConfigthat sets no profile meansProfileDefault.Rules()also tells which rules are online or fixable;RenamedRules()lists the retired rule IDs that ignores still accept.Workflow,Job,Step, ... are nodes of workflow syntax tree.Workflowis a root node.Parse()parses given contents into a workflow syntax tree. It tries to find syntax errors as much as possible and returns found errors as slice.ParseUses()parses the value of auses:key, for steps and for reusable workflow calls, into aUsesRef: itsKind(UsesAction,UsesReusableWorkflow,UsesDocker,UsesLocal,UsesInvalid), owner, repo, subpath, ref andRefKind(RefFullSHA,RefShortSHA,RefSemverTag,RefOther,RefDigest,RefNone), and Docker image, tag and digest.UsesRef.IsPinned(),SameRepo()andCanonicalName()help rules that compare references.Workflow.Commentsis theCommentIndexof the YAML comments of the file. A rule looks a node up by the line of itsPos:Inline()is the trailing comment,Before()andAfter()are the comment blocks directly above and below (a blank line ends a block), andDocumented()tells whether a line has either.NewCommentIndex()builds an index from any YAML source.LinterOptions.Onlineturns on the online checks (impostor-commit,known-vulnerable-actions, and so on). They talk to GitHub through theGitHubClientinterface; the built-in client sends REST requests with a token from the environment and caches the answers. SetLinterOptions.GitHubClientto serve your own, for exampleNewFixtureGitHubClient()with answers recorded byNewRecordingGitHubClient(), so that tests need no network. WithoutOnlineno client is ever called, and the WebAssembly build has no built-in client.LinterOptions.OnlineOptionssets the mode (OnlineModeCacheanswers from the cache only,OnlineModeStrictmakesLinter.OnlineFailed()true when a lookup was skipped), the API URL, the token source, the allow and deny lists and the retry behavior;Linter.OnlineSkipped()is the number of lookups that failed and were skipped. A failed lookup never makes aLintcall fail.Passis a visitor to traverse a workflow syntax tree. Multiple passes can be applied at single pass usingVisitor.Ruleis an interface for rule checkers andRuleBaseis a base struct to implement a rule checker.RuleBase.ReportID()reports an error with the stable ID of the diagnostic.RuleBase.Error()reports it with the name of the rule as the ID.RuleExpressionis a rule checker to check expression syntax in${{ }}.RuleShellcheckis a rule checker to applyshellcheckcommand torun:sections and collect errors from it.RuleJobNeedsis a rule checker to check dependencies inneeds:section. It can detect cyclic dependencies.- ...
ExprLexerlexes expression syntax in${{ }}and returns slice ofToken.ExprParserparses given slice ofTokenand returns syntax tree for expression in${{ }}.ExprNodeis an interface for nodes in the expression syntax tree.ExprTypeis an interface of types in expression syntax${{ }}.ObjectType,ArrayType,StringType,NumberType, ... are structs to represent actual types of expression.ExprSemanticsCheckerchecks semantics of expression syntax${{ }}. It traverses given expression syntax tree and deduces its type, checking types and resolving variables (contexts).ValidateRefGlob()andValidatePathGlob()validate glob filter pattern and returns all errors found by the validator.ActionMetadatais a struct for action metadata file (action.yml). It is used to check inputs specified atwith:and typingsteps.{id}.outputsobject strictly.PopularActionsglobal variable is the data set of popular actions' metadata collected by the script.AllWebhookTypesglobal variable is the mapping from all webhook names to their types collected by the script.WorkflowKeyAvailability()returns available context names and special function names for the given workflow key likejobs.<job_id>.outputs.<output_id>. This function uses the data collected by the script.
Library versioning
The version of this repository is for command line tool jactionlint. So it does not represent the version of the library. It means that the library does not follow semantic versioning and any patch version bump may introduce some breaking changes.
Since jactionlint v2 the Go module is github.com/jdx/jactionlint/v2. The package name is still jactionlint.
Go version compatibility
Following the Go's official policy, last two major Go versions are supported. For example, when the latest Go version is v1.22, v1.21 and v1.22 are supported. Minimum supported Go version is written in the go.mod file in this repository.
Checks | Rules | Installation | Usage | Configuration | References