Skip to content

Bug: gh aw add installs relative imports outside .github/workflows/ at the wrong destination #77151

Done

Description

@tbrandenburg

Description

When installing a remote workflow using gh aw add, relative imports pointing to files outside .github/workflows/ appear to be downloaded to an incorrect destination.

As a result, the workflow is installed, but compilation fails with import file not found.

Minimal Reproduction

Source repository structure:

.github/
├── prompts/
│   └── review.md
└── workflows/
    └── review.md

The workflow .github/workflows/review.md contains:

---
imports:
  - ../prompts/review.md
inlined-imports: true
---

In a separate consuming repository, install the remote workflow:

gh aw add example-org/workflow-library/.github/workflows/review.md@main

Replace example-org/workflow-library with an accessible synthetic test repository.

Then compile:

gh aw compile review --strict --approve

Expected Behavior

gh aw add should install the workflow and its referenced dependencies while preserving the relative import structure.

The consuming repository should contain:

.github/
├── prompts/
│   └── review.md
└── workflows/
    └── review.md

Compilation should succeed.

Actual Behavior

The installed workflow fails compilation:

error: import file not found
  - ../prompts/review.md

Source inspection suggests that the import may instead be installed at:

.github/workflows/.github/prompts/review.md

This destination is inferred from the implementation and has not yet been independently verified through a minimal end-to-end reproduction.

Root Cause Analysis

The likely issue is in [pkg/cli/includes.go](https://github.com/github/gh-aw/blob/main/pkg/cli/includes.go), specifically fetchFrontmatterImportsRecursive.

The function correctly resolves the remote import path:

.github/workflows/../prompts/review.md
→ .github/prompts/review.md

However, when the resolved path does not start with the original workflow directory, the implementation appears to retain the full repository-relative path and append it to the local .github/workflows/ destination.

This potentially produces:

.github/workflows/.github/prompts/review.md

instead of:

.github/prompts/review.md

The relevant behavior was observed during source inspection of v1.0.1, v1.2.2, and main.

Proposed Implementation Plan

  1. Update import destination resolution in pkg/cli/includes.go so that imports outside the original workflow directory preserve their repository-relative location in the consuming repository.
  2. Ensure all resolved destinations remain within the destination repository, rejecting unsafe path traversal.
  3. Add regression tests covering:
    • Imports within .github/workflows/shared/.
    • Relative imports into .github/prompts/.
    • Nested and transitive imports.
    • Invalid imports attempting to escape the repository.
  4. Verify that gh aw add followed by strict compilation succeeds in a clean consuming repository.

Acceptance Criteria

  • Relative imports outside .github/workflows/ are installed at paths compatible with compiler resolution.
  • Existing imports within .github/workflows/ continue working.
  • Transitive dependency fetching continues working.
  • Path traversal outside the destination repository is prevented.
  • Automated regression tests cover the affected layouts.

Environment

  • Reported failure: gh-aw v1.0.1
  • Source inspected: v1.0.1, v1.2.2, and main
  • Platform: GitHub CLI extension (gh aw add)
  • Scenario: Remote workflow installation with relative frontmatter imports

Related Issues

These related issues are closed, but the installation destination problem described here appears to remain unresolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions