-
Notifications
You must be signed in to change notification settings - Fork 296
feat: implement imports feature for workflow dependencies #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ab67eca
d614751
8ebde00
d7fee2c
f2dfd81
21a9f06
d924b1b
1e10040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| --- | ||
| title: Imports | ||
| description: Import workflow components from external GitHub repositories | ||
| --- | ||
|
|
||
| The `imports` field allows agentic workflows to import content from external GitHub repositories, enabling code reuse and modular workflow design. | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| Import components from external repositories by specifying the repository, version, and file path in the frontmatter: | ||
|
|
||
| ```aw | ||
| --- | ||
| on: workflow_dispatch | ||
| permissions: | ||
| contents: read | ||
| engine: claude | ||
| imports: | ||
| - microsoft/genaiscript v1.5.0 agentics/engine.md | ||
| - githubnext/gh-aw main .github/workflows/agentics/shared/tool-refused.md | ||
| --- | ||
|
|
||
| # My Workflow | ||
|
|
||
| This workflow imports shared components from external repositories. | ||
| ``` | ||
|
|
||
| ## Import Format | ||
|
|
||
| Each import follows the format: `org/repo version path` | ||
|
|
||
| - **org/repo**: GitHub repository in `owner/repository` format | ||
| - **version**: Git reference (branch name, tag, or commit SHA) | ||
| - **path**: Relative path to the file within the repository | ||
|
|
||
| Examples: | ||
| - `microsoft/genaiscript v1.5.0 agentics/engine.md` - Import from a specific version tag | ||
| - `githubnext/gh-aw main .github/workflows/shared/config.md` - Import from main branch | ||
| - `example/repo abc123def path/to/file.md` - Import from specific commit | ||
|
|
||
| ## Installation | ||
|
|
||
| Before compiling workflows with imports, install the dependencies: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a step before compiling feels wrong. We're already 1-step when we need to be 0-step. We don't want to be 2-step Why isn't this part of compiling?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes should be merged |
||
|
|
||
| ```bash | ||
| # Install imports for all workflows | ||
| gh aw install | ||
|
|
||
| # Install imports for a specific workflow | ||
| gh aw install my-workflow | ||
| ``` | ||
|
|
||
| The install command: | ||
| 1. Parses import specifications from workflow files | ||
| 2. Resolves versions to commit SHAs using git ls-remote | ||
| 3. Clones repositories at the specified versions | ||
| 4. Stores imported files in `.aw/imports/` | ||
| 5. Creates/updates `.aw/imports.lock` with resolved SHAs | ||
| 6. Creates `.aw/.gitignore` to automatically ignore the `imports/` folder | ||
|
|
||
| ## Lock File | ||
|
|
||
| The install command generates `.aw/imports.lock` which records: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another lock is too complex isn't it? Lock on lock...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup can be merged in the generated lock.yml file |
||
| - Resolved commit SHAs for each import | ||
| - Timestamp when imports were resolved | ||
| - List of transitive files (from @include directives) | ||
|
|
||
| Example lock file: | ||
| ``` | ||
| # Import lock file generated by gh-aw | ||
| # This file records resolved versions and commit SHAs for imports | ||
| # Do not edit manually | ||
|
|
||
| version: 1 | ||
|
|
||
| microsoft/genaiscript v1.5.0 agentics/engine.md abc123def456... 2025-01-15T10:30:00Z | ||
|
|
||
| githubnext/gh-aw main .github/workflows/agentics/shared/tool-refused.md ce06aa00a9ce... 2025-01-15T10:30:01Z | ||
| ``` | ||
|
|
||
| ## Compilation | ||
|
|
||
| During compilation, imported files are processed: | ||
| 1. Frontmatter from imports is merged (tools, engine config, etc.) | ||
| 2. Markdown content is prepended to the workflow | ||
| 3. The workflow is compiled as if the content was local | ||
|
|
||
| ```bash | ||
| # Compile after installing imports | ||
| gh aw compile my-workflow | ||
| ``` | ||
|
|
||
| If imports are not installed, compilation fails with: | ||
| ``` | ||
| error: import org/repo version path not found in lock file (run 'gh aw install') | ||
| ``` | ||
|
|
||
| ## Import Resolution | ||
|
|
||
| Imports are resolved before @include directives during compilation: | ||
| 1. Parse imports from frontmatter | ||
| 2. Read lock file and verify imports exist | ||
| 3. Load imported files from `.aw/imports/` | ||
| 4. Merge frontmatter and markdown content | ||
| 5. Process @include directives | ||
| 6. Compile final workflow | ||
|
|
||
| ## Frontmatter Merging | ||
|
|
||
| When importing files with frontmatter, configurations are merged: | ||
|
|
||
| **Tools**: Tool configurations are combined. If the same tool exists in both files, the imported configuration is used. | ||
|
|
||
| ```aw | ||
| # Imported file | ||
| --- | ||
| tools: | ||
| github: | ||
| allowed: [get_issue, list_issues] | ||
| --- | ||
| ``` | ||
|
|
||
| ```aw | ||
| # Main workflow | ||
| --- | ||
| imports: | ||
| - org/repo v1.0 tools-config.md | ||
| tools: | ||
| github: | ||
| allowed: [get_pull_request] | ||
| --- | ||
| ``` | ||
|
|
||
| Result: GitHub tools will have both sets of allowed functions. | ||
|
|
||
| **Other fields**: Imported values take precedence for non-tools fields. | ||
|
|
||
| ## Version Control | ||
|
|
||
| The `gh aw install` command automatically creates a `.aw/.gitignore` file that ignores the `imports/` folder. This ensures the cached imported files are not committed while the lock file remains trackable. | ||
|
|
||
| You can also add `.aw/imports/` to your project's root `.gitignore` for additional protection: | ||
|
|
||
| ```gitignore | ||
| # Workflow imports (cached files only, not the lock file) | ||
| .aw/imports/ | ||
| ``` | ||
|
|
||
| The lock file (`.aw/imports.lock`) should be committed to version control to ensure reproducible builds by pinning exact commit SHAs, similar to `go.sum` or `package-lock.json`. | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Use version tags**: Prefer semantic version tags (v1.0.0) over branch names for stability | ||
| 2. **Install before compile**: Always run `gh aw install` after adding or updating imports | ||
| 3. **Commit lock file**: Include `.aw/imports.lock` in version control for reproducibility | ||
| 4. **Test imports**: Verify imported content compiles successfully | ||
| 5. **Document dependencies**: Document why each import is needed | ||
|
|
||
| ## Transitive Dependencies | ||
|
|
||
| Imported files can contain @include directives. The install command automatically: | ||
| - Discovers transitive @include references | ||
| - Validates all referenced files exist | ||
| - Records them in the lock file | ||
|
|
||
| ## Comparison with @include | ||
|
|
||
| | Feature | @include | imports | | ||
| |---------|----------|---------| | ||
| | Source | Local repository | External repositories | | ||
| | Resolution | Compile time | Install time | | ||
| | Caching | None (always read) | Cached in .aw/imports/ | | ||
| | Version control | Implicit (via git) | Explicit (via lock file) | | ||
| | Use case | Project-local reuse | Cross-repo sharing | | ||
|
|
||
| Use @include for local files, imports for external dependencies. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **Import not found during compile**: | ||
| ``` | ||
| error: import org/repo version path not found in lock file | ||
| ``` | ||
| Solution: Run `gh aw install` to install imports. | ||
|
|
||
| **Version resolution failed**: | ||
| ``` | ||
| error: failed to resolve version v1.0.0 to commit SHA | ||
| ``` | ||
| Solution: Verify the version/tag/branch exists in the repository. | ||
|
|
||
| **File not found in imported repository**: | ||
| ``` | ||
| error: imported file not found: path/to/file.md | ||
| ``` | ||
| Solution: Check the file path exists in the repository at the specified version. | ||
|
|
||
| ## Example: Importing Security Notices | ||
|
|
||
| ```aw | ||
| --- | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| permissions: | ||
| contents: read | ||
| issues: write | ||
| engine: claude | ||
| imports: | ||
| - githubnext/gh-aw main .github/workflows/agentics/shared/tool-refused.md | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In GitHub Actions
e.g. We should align with this I think |
||
| - githubnext/gh-aw main .github/workflows/agentics/shared/xpia.md | ||
| tools: | ||
| github: | ||
| allowed: [get_issue, add_issue_comment] | ||
| --- | ||
|
|
||
| # Issue Triage Bot | ||
|
|
||
| This workflow imports security notices and tool usage guidelines. | ||
|
|
||
| Analyze issue #${{ github.event.issue.number }} and provide triage recommendations. | ||
| ``` | ||
|
|
||
| ```bash | ||
| # Install and compile | ||
| gh aw install | ||
| gh aw compile issue-triage | ||
| ``` | ||
|
|
||
| The compiled workflow will include the imported security notices and XPIA protection guidelines. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment below, let's use
microsoft/genaiscript/agentics/engine.md@v1.5.0- Import from a specific version tag