Skip to content

Commit c55fcab

Browse files
authored
docs: add concrete steps/mcp-servers/jobs import examples to imports reference (#23835)
1 parent 296d87a commit c55fcab

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

docs/src/content/docs/reference/imports.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,181 @@ Example — `tools.bash.allowed` merging:
271271
# result: [read, list, write]
272272
```
273273

274+
### Importing Steps
275+
276+
Share reusable pre-execution steps — such as token rotation, environment setup, or gate checks — across multiple workflows by defining them in a shared file:
277+
278+
```aw title="shared/rotate-token.md" wrap
279+
---
280+
description: Shared token rotation setup
281+
steps:
282+
- name: Rotate GitHub App token
283+
id: get-token
284+
uses: actions/create-github-app-token@v1
285+
with:
286+
app-id: ${{ vars.APP_ID }}
287+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
288+
---
289+
```
290+
291+
Any workflow that imports this file gets the rotation step prepended before its own steps:
292+
293+
```aw title="my-workflow.md" wrap
294+
---
295+
on: issues
296+
engine: copilot
297+
imports:
298+
- shared/rotate-token.md
299+
permissions:
300+
contents: read
301+
issues: write
302+
steps:
303+
- name: Prepare context
304+
run: echo "context ready"
305+
---
306+
307+
# My Workflow
308+
309+
Process the issue using the rotated token from the imported step.
310+
```
311+
312+
Steps from imports run **before** steps defined in the main workflow, in import declaration order.
313+
314+
### Importing MCP Servers
315+
316+
Define an MCP server configuration once and import it wherever needed:
317+
318+
```aw title="shared/mcp/tavily.md" wrap
319+
---
320+
description: Tavily web search MCP server
321+
mcp-servers:
322+
tavily:
323+
url: "https://mcp.tavily.com/mcp/?tavilyApiKey=${{ secrets.TAVILY_API_KEY }}"
324+
allowed: ["*"]
325+
network:
326+
allowed:
327+
- mcp.tavily.com
328+
---
329+
```
330+
331+
Import it into any workflow that needs web search:
332+
333+
```aw title="research.md" wrap
334+
---
335+
on: issues
336+
engine: copilot
337+
imports:
338+
- shared/mcp/tavily.md
339+
permissions:
340+
contents: read
341+
issues: write
342+
---
343+
344+
# Research Workflow
345+
346+
Search the web for relevant information and summarize findings in the issue.
347+
```
348+
349+
### Importing Top-level `jobs:`
350+
351+
Top-level `jobs:` defined in a shared workflow are merged into the importing workflow's compiled lock file. The job execution order is determined by `needs` entries — a shared job can run before or after other jobs in the final workflow:
352+
353+
```aw title="shared/build.md" wrap
354+
---
355+
description: Shared build job that compiles artifacts for the agent to inspect
356+
357+
jobs:
358+
build:
359+
runs-on: ubuntu-latest
360+
needs: [activation]
361+
outputs:
362+
artifact_name: ${{ steps.build.outputs.artifact_name }}
363+
steps:
364+
- uses: actions/checkout@v6
365+
- name: Build
366+
id: build
367+
run: |
368+
npm ci && npm run build
369+
echo "artifact_name=build-output" >> "$GITHUB_OUTPUT"
370+
- uses: actions/upload-artifact@v4
371+
with:
372+
name: build-output
373+
path: dist/
374+
375+
steps:
376+
- uses: actions/download-artifact@v4
377+
with:
378+
name: ${{ needs.build.outputs.artifact_name }}
379+
path: /tmp/build-output
380+
---
381+
```
382+
383+
Import it so the `build` job runs before the agent and its artifacts are available as pre-steps:
384+
385+
```aw title="my-workflow.md" wrap
386+
---
387+
on: pull_request
388+
engine: copilot
389+
imports:
390+
- shared/build.md
391+
permissions:
392+
contents: read
393+
pull-requests: write
394+
---
395+
396+
# Code Review Workflow
397+
398+
Review the build output in /tmp/build-output and suggest improvements.
399+
```
400+
401+
In the compiled lock file the `build` job appears alongside `activation` and `agent` jobs, ordered according to each job's `needs` declarations.
402+
403+
### Importing Jobs via `safe-outputs.jobs`
404+
405+
Jobs defined under `safe-outputs:` can be shared across workflows. These jobs become callable MCP tools that the AI agent can invoke during execution:
406+
407+
```aw title="shared/notify.md" wrap
408+
---
409+
description: Shared notification job
410+
safe-outputs:
411+
notify-slack:
412+
description: "Post a message to Slack"
413+
runs-on: ubuntu-latest
414+
output: "Notification sent"
415+
inputs:
416+
message:
417+
description: "Message to post"
418+
required: true
419+
type: string
420+
steps:
421+
- name: Post to Slack
422+
env:
423+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
424+
run: |
425+
curl -s -X POST "$SLACK_WEBHOOK" \
426+
-H "Content-Type: application/json" \
427+
-d "{\"text\":\"${{ inputs.message }}\"}"
428+
---
429+
```
430+
431+
Import and use it in multiple workflows:
432+
433+
```aw title="my-workflow.md" wrap
434+
---
435+
on: issues
436+
engine: copilot
437+
imports:
438+
- shared/notify.md
439+
permissions:
440+
contents: read
441+
issues: write
442+
---
443+
444+
# My Workflow
445+
446+
Process the issue. When done, use notify-slack to send a summary notification.
447+
```
448+
274449
### Error Handling
275450

276451
- **Circular imports**: Detected at compile time.

0 commit comments

Comments
 (0)