Support GH_ACTIONS_PIN_WORKFLOWS_DIR for non-standard workflow locations - #39
Merged
nodeselector merged 1 commit intoJun 12, 2026
Conversation
Undocumented env var for lab/non-standard environments where workflows live outside .github/workflows/. When set, workflow discovery and lockfile I/O (both read and write) use the override directory. Implementation: - workflowfile: extract DiscoverWorkflowsIn(dir) from DiscoverWorkflows - lockfile: replace State.repoRoot with State.lockPath; add LoadStateAt for explicit lockfile paths - root: read env var in newRun, route to DiscoverWorkflowsIn and LoadStateAt when set
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for overriding the GitHub Actions workflows directory (and corresponding actions.lock location) via the GH_ACTIONS_PIN_WORKFLOWS_DIR environment variable, while preserving default behavior when unset.
Changes:
- Extracted
workflowfile.DiscoverWorkflowsIn(dir)for workflow discovery in non-standard directories. - Added
lockfile.LoadStateAt(path, meta)and refactored state to store an explicit lockfile path. - Updated CLI run wiring to route workflow discovery + lockfile I/O through the override directory when provided.
Show a summary per file
| File | Description |
|---|---|
| internal/workflowfile/workflowfile.go | Adds DiscoverWorkflowsIn(dir) and keeps DiscoverWorkflows() as a wrapper for the default directory. |
| internal/workflowfile/workflowfile_test.go | Adds focused unit tests for DiscoverWorkflowsIn (happy path + missing dir). |
| internal/lockfile/state.go | Refactors state to store lockPath and introduces LoadStateAt to load/save lockfiles at explicit paths. |
| cmd/gh-actions-pin/root.go | Reads GH_ACTIONS_PIN_WORKFLOWS_DIR and uses it to drive workflow discovery and lockfile location. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
internal/workflowfile/workflowfile.go:102
- The workflow-file filtering logic here (ReadDir + ext check + sort) is effectively duplicated elsewhere (e.g., directory expansion of user-provided paths). To reduce drift risk, consider extracting a small shared helper for listing workflow files in a directory and reusing it across call sites.
// DiscoverWorkflowsIn finds all workflow files (*.yml, *.yaml) in dir.
// Returns nil if the directory doesn't exist.
func DiscoverWorkflowsIn(dir string) ([]string, error) {
entries, err := os.ReadDir(dir)
if os.IsNotExist(err) {
return nil, nil
}
- Files reviewed: 4/4 changed files
- Comments generated: 2
| type State struct { | ||
| mu sync.Mutex | ||
| repoRoot string | ||
| lockPath string // full path to actions.lock on disk |
Comment on lines
+162
to
+171
| if workflowsDir != "" { | ||
| paths, err := workflowfile.DiscoverWorkflowsIn(workflowsDir) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(paths) == 0 { | ||
| return nil, fmt.Errorf("no workflow files found in %s", workflowsDir) | ||
| } | ||
| return paths, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CLI hardcodes
.github/workflows/as the scan root for workflow discovery and lockfile placement. In lab and non-standard environments, workflows may live at a different path.This adds an undocumented
GH_ACTIONS_PIN_WORKFLOWS_DIRenv var that overrides where the CLI looks for workflow files and theactions.locklockfile. When unset, behavior is unchanged.Approach
Three packages touched, all surgical:
workflowfile: extractedDiscoverWorkflowsIn(dir)fromDiscoverWorkflows()-- the original becomes a thin wrapper passing.github/workflowslockfile: replacedState.repoRootwithState.lockPath(the field was only used for lockfile path computation). AddedLoadStateAt(path, meta)constructor for explicit lockfile paths;LoadStatewraps itroot.go:newRunreads the env var and routes discovery + lockfile I/O through the override dir when setTesting
DiscoverWorkflowsIn(happy path + missing dir)