workflowfile

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package workflowfile owns the parsed workflow YAML representation: loading, extraction of action refs, local composite discovery, and comment-preserving rewriting. It intentionally has no dependency on the lockfile or resolver packages.

Index

Constants

View Source
const SentinelComment = "# This workflow is managed by gh actions-lock."

SentinelComment is prepended to workflow files managed by gh actions-lock so users can tell at a glance that the file's action refs are locked.

Variables

This section is empty.

Functions

func DiscoverWorkflows

func DiscoverWorkflows() ([]string, error)

DiscoverWorkflows finds all workflow files in .github/workflows/ relative to the current directory. Returns nil if the directory doesn't exist.

func DiscoverWorkflowsIn

func DiscoverWorkflowsIn(dir string) ([]string, error)

DiscoverWorkflowsIn finds all workflow files (*.yml, *.yaml) in dir. Returns nil if the directory doesn't exist.

func EnsureSentinel added in v0.1.0

func EnsureSentinel(content []byte) []byte

EnsureSentinel prepends the sentinel comment to the workflow content if it is not already present at the top of the file. The comment is placed before any existing content with a blank line separating it from the YAML body.

func ExtractLocalCompositeRefs

func ExtractLocalCompositeRefs(workflowPath string, localPaths []string) ([]parserlock.ActionRef, []string)

ExtractLocalCompositeRefs reads action.yml files from local paths relative to the workflow file's directory and returns any repository action refs found in their steps.

func IsHostedRunnerLabel added in v0.0.15

func IsHostedRunnerLabel(label string) bool

IsHostedRunnerLabel reports whether label is a known GitHub-hosted runner.

func KeyFromPath

func KeyFromPath(workflowPath string) string

KeyFromPath converts a workflow path discovered on disk (relative to the repo root or cwd) into the repo-relative key used inside the lockfile.

func RegisterOrgHostedLabels added in v0.0.16

func RegisterOrgHostedLabels(labels []string)

RegisterOrgHostedLabels adds labels to the hosted runner allowlist. Call before ParseAll; safe to call multiple times. The special value "*" marks all labels as hosted.

Types

type File

type File struct {
	Path    string
	Content []byte
	// contains filtered or unexported fields
}

File is the parsed workflow YAML the CLI rewrites in-place. It carries the original byte content alongside the parsed node tree so RewriteActionRefs can do anchored, comment-preserving substitution.

func Load

func Load(path string) (*File, error)

Load reads and parses a workflow file.

func Parse

func Parse(path string, content []byte) (*File, error)

Parse builds a File from already-loaded workflow content.

func (*File) ExtractActionRefs

func (f *File) ExtractActionRefs() ([]parserlock.ActionRef, []string, []string)

ExtractActionRefs finds all uses: references to repository actions in the workflow.

func (*File) ExtractRunsOnLabels added in v0.0.15

func (f *File) ExtractRunsOnLabels() []string

ExtractRunsOnLabels returns the deduplicated runs-on labels across all jobs.

func (*File) HasNonHostedRunnerLabels added in v0.0.15

func (f *File) HasNonHostedRunnerLabels() bool

HasNonHostedRunnerLabels reports whether any job uses a non-hosted runner label.

func (*File) NonHostedRunnerLabels added in v0.0.16

func (f *File) NonHostedRunnerLabels() []string

NonHostedRunnerLabels returns distinct non-hosted labels across all jobs.

func (*File) RewriteActionRefs

func (f *File) RewriteActionRefs(replacements map[string]string) ([]byte, int, error)

RewriteActionRefs rewrites targeted uses: refs in the original workflow content while preserving the surrounding formatting and comments.

Jump to

Keyboard shortcuts

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