-
Notifications
You must be signed in to change notification settings - Fork 344
feat: add upload-artifact safe output type for run-scoped GitHub Actions artifact uploads #25002
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
465b20e
ff14be6
60b0376
1d4b6ad
a9e8f8f
ae61a26
f962e66
bedab80
fdeeba3
4efbf5b
d577e59
1684416
f0d8940
666601f
6b2777f
e9e9c61
36c1694
221a3fa
e1b9b28
b07adc9
568e236
39c1548
5314cc7
b7c0b49
44a92dd
cf2d96f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| safe-outputs: | ||
| upload-artifact: | ||
| max-uploads: 3 | ||
| default-retention-days: 7 | ||
| max-retention-days: 30 | ||
| allow: | ||
| skip-archive: true | ||
| --- | ||
|
|
||
| <!-- | ||
| # Shared Upload Artifact Safe Output Configuration | ||
|
|
||
| This shared workflow enables the `upload_artifact` safe output tool, which lets AI agents | ||
| upload files as run-scoped GitHub Actions artifacts. | ||
|
|
||
| ## How it works | ||
|
|
||
| The agent stages files to `$RUNNER_TEMP/gh-aw/safeoutputs/upload-artifacts/` and calls the | ||
| `upload_artifact` tool. The `safe_outputs` job picks up the staged files and uploads them | ||
| directly via the `@actions/artifact` REST API (no `actions: write` permission needed — | ||
| authentication uses `ACTIONS_RUNTIME_TOKEN` which is always available to the runner). | ||
|
|
||
| The tool returns a temporary opaque artifact ID (`tmp_artifact_*`) that can be resolved to | ||
| a download URL by an authorised downstream step. | ||
|
|
||
| ## Usage | ||
|
|
||
| Import this shared workflow to enable `upload_artifact` in any workflow: | ||
|
|
||
| ```yaml | ||
| imports: | ||
| - shared/safe-output-upload-artifact.md | ||
| ``` | ||
|
|
||
| The agent must stage files before calling the tool: | ||
|
|
||
| ```bash | ||
| # Stage files to the upload-artifacts directory | ||
| cp dist/report.json $RUNNER_TEMP/gh-aw/safeoutputs/upload-artifacts/report.json | ||
| ``` | ||
|
|
||
| Then call the tool: | ||
|
|
||
| ```json | ||
| { "type": "upload_artifact", "path": "report.json", "retention_days": 7 } | ||
| ``` | ||
|
|
||
| ## Configuration defaults | ||
|
|
||
| - `max-uploads`: 3 uploads per run | ||
| - `default-retention-days`: 7 days | ||
| - `max-retention-days`: 30 days | ||
| - `allow.skip-archive`: true (single-file uploads can skip zip archiving) | ||
|
|
||
| Override any of these by defining `upload-artifact` directly in your workflow's | ||
| `safe-outputs` section (the top-level definition takes precedence over the import). | ||
| --> | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,12 @@ runtimes: | |
| version: "1.25" | ||
|
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. The |
||
| safe-outputs: | ||
| allowed-domains: [default-safe-outputs] | ||
| upload-artifact: | ||
|
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. Good defaults:
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. The |
||
| max-uploads: 1 | ||
| default-retention-days: 1 | ||
| max-retention-days: 1 | ||
| allow: | ||
| skip-archive: true | ||
| add-comment: | ||
| allowed-repos: ["github/gh-aw"] | ||
| hide-older-comments: true | ||
|
|
@@ -140,9 +146,10 @@ strict: false | |
| - Extract the discussion number from the result (e.g., if the result is `{"number": 123, "title": "...", ...}`, extract 123) | ||
| - Use the `add_comment` tool with `discussion_number: <extracted_number>` to add a fun, playful comment stating that the smoke test agent was here | ||
| 9. **Build gh-aw**: Run `GOCACHE=/tmp/go-cache GOMODCACHE=/tmp/go-mod make build` to verify the agent can successfully build the gh-aw project (both caches must be set to /tmp because the default cache locations are not writable). If the command fails, mark this test as ❌ and report the failure. | ||
| 10. **Discussion Creation Testing**: Use the `create_discussion` safe-output tool to create a discussion in the announcements category titled "copilot was here" with the label "ai-generated" | ||
| 11. **Workflow Dispatch Testing**: Use the `dispatch_workflow` safe output tool to trigger the `haiku-printer` workflow with a haiku as the message input. Create an original, creative haiku about software testing or automation. | ||
| 12. **PR Review Testing**: Review the diff of the current pull request. Leave 1-2 inline `create_pull_request_review_comment` comments on specific lines, then call `submit_pull_request_review` with a brief body summarizing your review and event `COMMENT`. To test `reply_to_pull_request_review_comment`: use the `pull_request_read` tool (with `method: "get_review_comments"` and `pullNumber: ${{ github.event.pull_request.number }}`) to fetch the PR's existing review comments, then reply to the most recent one using `reply_to_pull_request_review_comment` with its actual numeric `id` as the `comment_id`. Note: `create_pull_request_review_comment` does not return a `comment_id` — you must fetch existing comment IDs from the GitHub API. If the PR has no existing review comments, skip the reply sub-test. | ||
| 10. **Upload gh-aw binary as artifact**: After a successful build, use bash to copy the `./gh-aw` binary into the staging directory (`mkdir -p $RUNNER_TEMP/gh-aw/safeoutputs/upload-artifacts && cp ./gh-aw $RUNNER_TEMP/gh-aw/safeoutputs/upload-artifacts/gh-aw`), then call the `upload_artifact` safe-output tool with `path: "gh-aw"`, `retention_days: 1`, and `skip_archive: true`. The `upload_artifact` tool is available and configured in this workflow run — use it directly, do NOT use `missing_tool` for it. Mark this test as ❌ if the build in step 9 failed. | ||
| 11. **Discussion Creation Testing**: Use the `create_discussion` safe-output tool to create a discussion in the announcements category titled "copilot was here" with the label "ai-generated" | ||
| 12. **Workflow Dispatch Testing**: Use the `dispatch_workflow` safe output tool to trigger the `haiku-printer` workflow with a haiku as the message input. Create an original, creative haiku about software testing or automation. | ||
| 13. **PR Review Testing**: Review the diff of the current pull request. Leave 1-2 inline `create_pull_request_review_comment` comments on specific lines, then call `submit_pull_request_review` with a brief body summarizing your review and event `COMMENT`. To test `reply_to_pull_request_review_comment`: use the `pull_request_read` tool (with `method: "get_review_comments"` and `pullNumber: ${{ github.event.pull_request.number }}`) to fetch the PR's existing review comments, then reply to the most recent one using `reply_to_pull_request_review_comment` with its actual numeric `id` as the `comment_id`. Note: `create_pull_request_review_comment` does not return a `comment_id` — you must fetch existing comment IDs from the GitHub API. If the PR has no existing review comments, skip the reply sub-test. | ||
|
|
||
| ## Output | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,10 @@ inputs: | |
| description: 'Install @actions/github for handlers that use a per-handler github-token (creates Octokit via getOctokit)' | ||
|
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. The new
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. 🤖 Smoke test run §24109101982 confirms this is still a clean, minimal addition. The Note 🔒 Integrity filter blocked 2 itemsThe following items were blocked because they don't meet the GitHub integrity level.
To allow these resources, lower tools:
github:
min-integrity: approved # merged | approved | unapproved | none
|
||
| required: false | ||
| default: 'false' | ||
| safe-output-artifact-client: | ||
|
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. Good addition —
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. 🤖 Smoke test agent dropping in! The
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. New
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. 🤖 Smoke test agent here! The
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. 🤖 Smoke test run §24109101982 confirms the
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. The new
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. 🤖 Smoke test agent 24110635667 agrees — the
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. Good addition of the |
||
| description: 'Install @actions/artifact so upload_artifact.cjs can upload GitHub Actions artifacts via REST API directly' | ||
| required: false | ||
| default: 'false' | ||
| job-name: | ||
| description: 'Name of the job being set up. When OTEL_EXPORTER_OTLP_ENDPOINT is configured, a gh-aw.<job-name>.setup span is pushed to the OTLP endpoint.' | ||
| required: false | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
The shared workflow config with
max-uploads: 3,default-retention-days: 7, andmax-retention-days: 30provides reasonable defaults. The documentation comment clearly explains the upload flow viaACTIONS_RUNTIME_TOKENwithout requiringactions: writepermission — a great security design.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.
🤖 Smoke test run §24110244763 confirms: sensible defaults for the shared workflow! The no-
actions: writedesign is a great security win.