Skip to content

fix: honor GH_AW_WORKFLOWS_DIR in GetWorkflowDir() and eliminate 27 hardcoded literals#32100

Merged
pelikhan merged 7 commits into
mainfrom
copilot/fix-getworkflowdir-env-var-drift
May 14, 2026
Merged

fix: honor GH_AW_WORKFLOWS_DIR in GetWorkflowDir() and eliminate 27 hardcoded literals#32100
pelikhan merged 7 commits into
mainfrom
copilot/fix-getworkflowdir-env-var-drift

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

Bug Fix

What was the bug?

GetWorkflowDir() was documented to read GH_AW_WORKFLOWS_DIR at call time but always returned the hardcoded string. Additionally, 27 production sites bypassed the helper entirely by inlining ".github/workflows", making the env-var override non-functional throughout the codebase.

How did you fix it?

pkg/constants/constants.go — implement the documented contract:

func GetWorkflowDir() string {
    if dir := os.Getenv("GH_AW_WORKFLOWS_DIR"); dir != "" {
        return dir
    }
    return filepath.Join(".github", "workflows")
}

Call-site consolidation — replaced all 27 hardcoded ".github/workflows" literals with constants.GetWorkflowDir() across 20 files:

  • pkg/cli/: workflows.go (shim), enable.go, logs_utils.go, compile_orchestrator.go, compile_validation.go, mcp_safe_update_cache.go, upgrade_command.go, list_workflows_command.go, lint_command.go, mcp_list.go, trial_helpers.go, fix_command.go, remove_command.go (×3), resolver.go, add_command.go, compile_watch.go, run_workflow_execution.go, update_container_pins.go
  • pkg/parser/import_bfs.go
  • Added constants import to 7 files that lacked it

Flag defaults in lint_command.go and list_workflows_command.go now call constants.GetWorkflowDir() at command-construction time so they also respect the env var.

Testing

Added TestGetWorkflowDirEnvOverride and TestGetWorkflowDirEnvEmpty to pkg/constants/constants_test.go to pin the env-var override behaviour as a regression guard.

Copilot AI and others added 2 commits May 14, 2026 11:42
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…e 27 hardcoded literals

- Add os.Getenv("GH_AW_WORKFLOWS_DIR") override to constants.GetWorkflowDir()
- Add regression tests for env-var override and empty-env fallback
- Replace getWorkflowsDir() shim in pkg/cli/workflows.go with constants.GetWorkflowDir()
- Replace all 27 hardcoded ".github/workflows" literals across pkg/cli/ and pkg/parser/
  with constants.GetWorkflowDir() calls
- Add constants import to files that lacked it (compile_orchestrator, compile_validation,
  mcp_safe_update_cache, mcp_list, compile_watch, update_container_pins, import_bfs)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GetWorkflowDir() env-var contract drift and consolidate hardcoded literals fix: honor GH_AW_WORKFLOWS_DIR in GetWorkflowDir() and eliminate 27 hardcoded literals May 14, 2026
Copilot AI requested a review from pelikhan May 14, 2026 11:50
@pelikhan pelikhan marked this pull request as ready for review May 14, 2026 11:51
Copilot AI review requested due to automatic review settings May 14, 2026 11:51
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main and recompile

Copilot AI and others added 2 commits May 14, 2026 11:57
…owdir-env-var-drift

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot merge main and recompile

Done — merged main and ran make recompile. The only artifact was an updated .github/workflows/architecture-guardian.lock.yml, committed in chore: merge main and recompile workflows.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes constants.GetWorkflowDir() to honor GH_AW_WORKFLOWS_DIR at runtime and propagates the helper across the CLI/parser so the workflow directory override works consistently (instead of being bypassed by hardcoded ".github/workflows" literals). Adds regression tests for the env-var override behavior, and includes regenerated workflow lockfiles.

Changes:

  • Implement env-var override in pkg/constants.GetWorkflowDir() and add unit tests covering override + empty behavior.
  • Replace hardcoded ".github/workflows" usage across CLI/parser call sites with constants.GetWorkflowDir().
  • Regenerate multiple .github/workflows/*.lock.yml files (notably updating the claude_harness invocation argument ordering/placement).
Show a summary per file
File Description
pkg/constants/constants.go Implement runtime GH_AW_WORKFLOWS_DIR override in GetWorkflowDir().
pkg/constants/constants_test.go Add regression tests for env override + empty env behavior.
pkg/parser/import_bfs.go Use constants.GetWorkflowDir() as default base path for remote nested imports.
pkg/cli/workflows.go Route workflow-dir resolution through constants.GetWorkflowDir().
pkg/cli/upgrade_command.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/update_container_pins.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/trial_helpers.go Use constants.GetWorkflowDir() when building workflow description path.
pkg/cli/run_workflow_execution.go Use constants.GetWorkflowDir() for lock-file path resolution.
pkg/cli/resolver.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/remove_command.go Default workflows directory now uses constants.GetWorkflowDir().
pkg/cli/mcp_safe_update_cache.go Default workflows directory now uses constants.GetWorkflowDir().
pkg/cli/mcp_list.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/logs_utils.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/list_workflows_command.go Default --path now uses constants.GetWorkflowDir().
pkg/cli/lint_command.go Default --dir now uses constants.GetWorkflowDir().
pkg/cli/fix_command.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/enable.go Default workflows directory now uses constants.GetWorkflowDir().
pkg/cli/compile_watch.go Watch mode now targets constants.GetWorkflowDir() under git root.
pkg/cli/compile_validation.go Dependabot validation compares against constants.GetWorkflowDir().
pkg/cli/compile_orchestrator.go Default workflow directory now uses constants.GetWorkflowDir().
pkg/cli/add_command.go Default workflows directory now uses constants.GetWorkflowDir() under git root.
.github/workflows/test-create-pr-error-handling.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/static-analysis-report.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/smoke-agent-scoped-approved.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/smoke-agent-public-none.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/smoke-agent-public-approved.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/smoke-agent-all-none.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/smoke-agent-all-merged.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/sergo.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/schema-consistency-checker.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/safe-output-health.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/prompt-clustering-analysis.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/lockfile-stats.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/hourly-ci-cleaner.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/go-pattern-detector.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/github-mcp-tools-report.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/github-mcp-structural-analysis.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/example-workflow-analyzer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/design-decision-gate.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/deep-report.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-token-consumption-report.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-team-evolution-insights.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-subagent-optimizer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-security-red-team.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-safe-outputs-conformance.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-safe-output-optimizer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-otel-instrumentation-advisor.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-grafana-otel-instrumentation-advisor.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-function-namer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-code-metrics.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-choice-test.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-caveman-optimizer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-aw-cross-repo-compile-check.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-astrostylelite-markdown-spellcheck.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/daily-agentrx-trace-optimizer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/copilot-session-insights.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/copilot-agent-analysis.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/commit-changes-analyzer.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/cloclo.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/cli-version-checker.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/claude-code-user-docs-review.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/ci-doctor.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/aw-failure-investigator.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/audit-workflows.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/approach-validator.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).
.github/workflows/api-consumption-report.lock.yml Regenerated lockfile (updates claude_harness invocation arg ordering/placement).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

pkg/cli/logs_utils.go:38

  • The verbose warning message is hardcoded to "No .github/workflows directory found" even though workflowsDir is now dynamic via constants.GetWorkflowDir(). Update the message (and ideally the preceding comment) to reference the actual workflowsDir so GH_AW_WORKFLOWS_DIR users get accurate output.
    pkg/cli/enable.go:287
  • When GH_AW_WORKFLOWS_DIR is set, this verbose message still says "No .github/workflows directory found" even though workflowsDir is now derived from constants.GetWorkflowDir(). Consider including the actual workflowsDir in the message to avoid confusing output under overrides.
  • Files reviewed: 22/22 changed files
  • Comments generated: 7

Comment on lines 335 to 340
func GetWorkflowDir() string {
if dir := os.Getenv("GH_AW_WORKFLOWS_DIR"); dir != "" {
return dir
}
return filepath.Join(".github", "workflows")
}
Comment thread pkg/cli/compile_watch.go
Comment on lines +33 to 36
workflowsDir := filepath.Join(gitRoot, constants.GetWorkflowDir())
if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
return fmt.Errorf("the .github/workflows directory does not exist in git root (%s)", gitRoot)
}
Comment on lines 195 to 200
workflowsDir := getWorkflowsDir()

_, _, err := readWorkflowFile(normalizedID+".md", workflowsDir)
if err != nil {
return fmt.Errorf("failed to find workflow in local .github/workflows: %w", err)
}
Comment thread pkg/cli/remove_command.go Outdated
Comment on lines 212 to 216
// Find all include files in .github/workflows
// Only consider files in subdirectories (like shared/) as potential include files
// Root-level .md files are workflow files, not include files
workflowsDir := ".github/workflows"
workflowsDir := constants.GetWorkflowDir()
var allIncludes []string
Comment on lines +74 to 76
cmd.Flags().String("path", constants.GetWorkflowDir(), "Path to workflows directory in the remote repository (used with --repo)")
cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows; ignored when --repo is set)")

Comment thread pkg/cli/run_workflow_execution.go Outdated
Comment on lines 202 to 205
// Check if the lock file exists in .github/workflows
lockFilePath = filepath.Join(".github/workflows", lockFileName)
lockFilePath = filepath.Join(constants.GetWorkflowDir(), lockFileName)
if _, err := os.Stat(lockFilePath); os.IsNotExist(err) {
executionLog.Printf("Lock file not found: %s (workflow must be compiled first)", lockFilePath)
Comment on lines 860 to 862
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review all comments

Copilot AI and others added 2 commits May 14, 2026 13:42
…ators

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot review all comments

All review comments addressed in the latest commits:

  • constants.go: GetWorkflowDir() now uses filepath.ToSlash on the env-var override (normalizes Windows paths) and returns a hardcoded ".github/workflows" literal as the default — with a doc comment explaining that forward slashes are always required for git/GitHub paths.
  • compile_watch.go: missing-directory error now references constants.GetWorkflowDir() instead of the hardcoded string.
  • run_workflow_execution.go: both the readWorkflowFile error and the lock-file-not-found message now reference the computed directory; stale .github/workflows comment updated.
  • remove_command.go: comment updated to remove the hardcoded directory name.
  • list_workflows_command.go: --dir help text now reads "default: $GH_AW_WORKFLOWS_DIR or .github/workflows".

The lockfile changes in test-create-pr-error-handling.lock.yml are a natural byproduct of running make recompile after merging main.

@pelikhan pelikhan merged commit 4076b10 into main May 14, 2026
24 of 26 checks passed
@pelikhan pelikhan deleted the copilot/fix-getworkflowdir-env-var-drift branch May 14, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix GetWorkflowDir() env-var contract drift + consolidate 27 hardcoded ".github/workflows" literals

3 participants