mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-11-18 12:41:09 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5812cd756 | ||
|
|
47bf91ccca | ||
|
|
87ff2368a1 | ||
|
|
469588f42e |
@@ -11,12 +11,46 @@ on:
|
||||
types: [submitted]
|
||||
|
||||
jobs:
|
||||
claude:
|
||||
# In this repository Claude doesn't run on fork PRs, whatever triggers it. The event for a comment
|
||||
# on a PR's conversation doesn't say where the PR's branch is, so this job asks GitHub. If it can't
|
||||
# tell, Claude doesn't run.
|
||||
fork-check:
|
||||
if: |
|
||||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
|
||||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read
|
||||
outputs:
|
||||
run-claude: ${{ steps.check.outputs.run-claude }}
|
||||
steps:
|
||||
- name: Check that a pull request is not from a fork
|
||||
id: check
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
# Empty on an issue
|
||||
PR_NUMBER: ${{ github.event.pull_request.number || (github.event.issue.pull_request && github.event.issue.number) }}
|
||||
run: |
|
||||
same_repo=true
|
||||
if [ -n "$PR_NUMBER" ]; then
|
||||
for attempt in 1 2 3; do
|
||||
same_repo=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" --jq '.head.repo.id == .base.repo.id') && break
|
||||
[ "$attempt" -lt 3 ] || exit 1
|
||||
sleep 5
|
||||
done
|
||||
fi
|
||||
if [ "$same_repo" = true ]; then
|
||||
echo "run-claude=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "::notice::Claude does not run on pull requests from forks in this repository."
|
||||
fi
|
||||
|
||||
claude:
|
||||
needs: fork-check
|
||||
if: needs.fork-check.outputs.run-claude == 'true'
|
||||
# This job calls Claude, so it runs on GitHub's egress-firewall runner, which
|
||||
# filters the job's outbound network traffic (allow list: .github/egress-firewall.yaml).
|
||||
runs-on: ubuntu-24.04-firewall
|
||||
|
||||
+3
-2
@@ -79,7 +79,7 @@ Thank you for your interest in contributing to Claude Code Action! This document
|
||||
git push origin feature/your-feature-name
|
||||
```
|
||||
|
||||
5. Ensure all CI checks pass. On a pull request from a fork, checks usually start only after a maintainer approves them, and jobs that call Claude are skipped because forks don't get the credentials they need.
|
||||
5. Ensure all CI checks pass. On a pull request from a fork, checks usually start only after a maintainer approves them, and jobs that call Claude are skipped.
|
||||
|
||||
6. Request review from maintainers
|
||||
|
||||
@@ -96,7 +96,8 @@ These steps are for pull requests from forks whose author does not have write ac
|
||||
1. Review the changes, including any to workflow files and test scripts.
|
||||
2. Select **Approve and run**, which starts every waiting workflow. `ci.yml` runs the tests, type check and format check. GitHub gives these runs a read-only token and no secrets. New commits can need a new approval.
|
||||
3. Check the result. Jobs that call Claude, such as `claude-review.yml` and the ones in `test-*.yml`, show as skipped, which doesn't mean they passed. The `test-*.yml` jobs run on `main` after the merge.
|
||||
4. If you want help, mention `@claude` in a comment on the conversation, not in a review. Claude can see whether `ci.yml` passed, but commands such as `bun` are denied. See [Running code from pull requests](./docs/security.md#running-code-from-pull-requests).
|
||||
|
||||
Mentioning `@claude` on a pull request from a fork does nothing in this repository: `claude.yml` skips its Claude job. Don't work around that by pushing the fork's commits to a branch here, because Claude then trusts them as yours. See [Running code from pull requests](./docs/security.md#running-code-from-pull-requests).
|
||||
|
||||
## Action Development
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ inputs:
|
||||
only use for workflows with very limited permissions and validate all outputs.
|
||||
required: false
|
||||
default: ""
|
||||
allow_fork_prs:
|
||||
description: "Whether to run on pull requests from forks, and on workflow_run events for a fork's run. With any value other than 'true', the action skips them, whoever opened them, before it checks anything out. See docs/security.md."
|
||||
required: false
|
||||
default: "true"
|
||||
restrict_untrusted_prs:
|
||||
description: "On pull requests whose author does not have write access, deny commands that commonly run code from the checkout (package managers, test runners, interpreters, shells), even if claude_args allows them. Set to 'false' to turn this off. See docs/security.md."
|
||||
required: false
|
||||
@@ -312,6 +316,7 @@ runs:
|
||||
OVERRIDE_GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
ALLOWED_BOTS: ${{ inputs.allowed_bots }}
|
||||
ALLOWED_NON_WRITE_USERS: ${{ inputs.allowed_non_write_users }}
|
||||
ALLOW_FORK_PRS: ${{ inputs.allow_fork_prs }}
|
||||
RESTRICT_UNTRUSTED_PRS: ${{ inputs.restrict_untrusted_prs }}
|
||||
CLAUDE_CODE_SUBPROCESS_ENV_SCRUB: ${{ env.CLAUDE_CODE_SUBPROCESS_ENV_SCRUB || (inputs.allowed_non_write_users != '' && '1') || '' }}
|
||||
CLAUDE_CODE_SCRIPT_CAPS: ${{ env.CLAUDE_CODE_SCRIPT_CAPS || '' }}
|
||||
|
||||
@@ -147,7 +147,7 @@ runs:
|
||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||
run: |
|
||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||
CLAUDE_CODE_VERSION="2.1.326"
|
||||
CLAUDE_CODE_VERSION="2.1.327"
|
||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||
for attempt in 1 2 3; do
|
||||
echo "Installation attempt $attempt..."
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@
|
||||
"name": "@anthropic-ai/claude-code-base-action",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.326",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"shell-quote": "^1.8.4",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27,23 +27,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]6", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.326", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.326" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-BUTSky/4YWfL/MxC+4kV0NDbJFjbJPoQMFEk/s9G6hV9LUfYPMbsWz94bFQ7ZIo2ubj2xwJ2c2NVxkNlQhVw+Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]7", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.327" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-zS5RIrYphnhftgafFUpNCGwNUwR6UzLUv3cEy6iD1+LDxmVKnwJAaYTgzgsdijqwuGvcpeiWmbkVrEk0Jc4M5A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-D3ZbowCMdKNet0YPZlsJxdJUW1t1Q8KLy1BwNd+5eilf18TlCRtWZlm8DrewFLmu/gxBK7gcsq6uysrIVbPyQg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]6", "", { "os": "darwin", "cpu": "x64" }, "sha512-m8K3Im2S8STdAVBrriuDZyJcnjsu/Vc3476wIOqTAefnCCdtdZ4AHcOcWxt+4KIHE5Vx1qT2qacTRrQBaVVweA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "x64" }, "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-nYVN8jCcH490DCXIvby7rllzQFxLzKeKClfo2u/yv7mx3ipZQv344caULL/amwZ8w8GUzYyZ8hnS6pI9goSq+A=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-baSsuP2/wuWujRpHjKT4WkJB5lhttqKq9jcTfY2KRtQpylbk8E5PWcct/pmwJfNCKIUoE8CD+JpmoWzsdd5Ajw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-WMhDY07gk2O0E8FXTbrVYmPjSLFaYPDCPwsNueVxm6vZ7ek+lPaKuOMAxTb1K07TzSmTOexoWeX2Y9VrbVDMpw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-kK9VO3uFqNd4wgeU0Cefluam5AdPu6mvF1nn6aboGy8TA5NoxlWTmA4/AwMhK39zK1S9Q2OjeX0JtAahYlIchw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "win32", "cpu": "arm64" }, "sha512-S+Ai+HhGRVFfTDmYWRfTrdWF3b4KMsfLSThZCqRJ0WCOKOXrRShMKV1hqqHBljx/wkMDPCpY0V/9S/e6w57eGQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "arm64" }, "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]6", "", { "os": "win32", "cpu": "x64" }, "sha512-Yn1gZXYFuHmjHz7SpHx4TqDcRDsC8TfwWcntJdYjFzMWm+caPAp6QRqr/aTvirjqVA1D+D8Rd29xhuytpE3xTQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "x64" }, "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.326",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"shell-quote": "^1.8.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.326",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
@@ -37,23 +37,23 @@
|
||||
|
||||
"@actions/io": ["@actions/[email protected]", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]6", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.326", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.326", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.326", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.326" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-BUTSky/4YWfL/MxC+4kV0NDbJFjbJPoQMFEk/s9G6hV9LUfYPMbsWz94bFQ7ZIo2ubj2xwJ2c2NVxkNlQhVw+Q=="],
|
||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/[email protected]7", "", { "optionalDependencies": { "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.327", "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.327", "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.327" }, "peerDependencies": { "@anthropic-ai/sdk": ">=0.93.0", "@modelcontextprotocol/sdk": "^1.29.0", "zod": "^4.0.0" } }, "sha512-zS5RIrYphnhftgafFUpNCGwNUwR6UzLUv3cEy6iD1+LDxmVKnwJAaYTgzgsdijqwuGvcpeiWmbkVrEk0Jc4M5A=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "darwin", "cpu": "arm64" }, "sha512-D3ZbowCMdKNet0YPZlsJxdJUW1t1Q8KLy1BwNd+5eilf18TlCRtWZlm8DrewFLmu/gxBK7gcsq6uysrIVbPyQg=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]6", "", { "os": "darwin", "cpu": "x64" }, "sha512-m8K3Im2S8STdAVBrriuDZyJcnjsu/Vc3476wIOqTAefnCCdtdZ4AHcOcWxt+4KIHE5Vx1qT2qacTRrQBaVVweA=="],
|
||||
"@anthropic-ai/claude-agent-sdk-darwin-x64": ["@anthropic-ai/[email protected]7", "", { "os": "darwin", "cpu": "x64" }, "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-nYVN8jCcH490DCXIvby7rllzQFxLzKeKClfo2u/yv7mx3ipZQv344caULL/amwZ8w8GUzYyZ8hnS6pI9goSq+A=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-baSsuP2/wuWujRpHjKT4WkJB5lhttqKq9jcTfY2KRtQpylbk8E5PWcct/pmwJfNCKIUoE8CD+JpmoWzsdd5Ajw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-WMhDY07gk2O0E8FXTbrVYmPjSLFaYPDCPwsNueVxm6vZ7ek+lPaKuOMAxTb1K07TzSmTOexoWeX2Y9VrbVDMpw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]6", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-kK9VO3uFqNd4wgeU0Cefluam5AdPu6mvF1nn6aboGy8TA5NoxlWTmA4/AwMhK39zK1S9Q2OjeX0JtAahYlIchw=="],
|
||||
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": ["@anthropic-ai/[email protected]7", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]6", "", { "os": "win32", "cpu": "arm64" }, "sha512-S+Ai+HhGRVFfTDmYWRfTrdWF3b4KMsfLSThZCqRJ0WCOKOXrRShMKV1hqqHBljx/wkMDPCpY0V/9S/e6w57eGQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-arm64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "arm64" }, "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw=="],
|
||||
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]6", "", { "os": "win32", "cpu": "x64" }, "sha512-Yn1gZXYFuHmjHz7SpHx4TqDcRDsC8TfwWcntJdYjFzMWm+caPAp6QRqr/aTvirjqVA1D+D8Rd29xhuytpE3xTQ=="],
|
||||
"@anthropic-ai/claude-agent-sdk-win32-x64": ["@anthropic-ai/[email protected]7", "", { "os": "win32", "cpu": "x64" }, "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/[email protected]", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-q9vaSZQVFx6B/gPxetGYfLXSJD5v0sOmh0OpZDq7yCrTSA+Rscvrtyol7JJTW40wEpQB4U1B4JXzxQitbQ3CAA=="],
|
||||
|
||||
|
||||
+26
-2
@@ -69,6 +69,28 @@ This doesn't cover other package managers, the `.env` files and `tsconfig.json`
|
||||
|
||||
Note that the runtime executing the tool also reads project config. `bunx <tool>` runs the tool's script under `node` when `node` is on `PATH` (as it is on GitHub-hosted runners); when only Bun is available, Bun executes the script itself and reads `bunfig.toml` from the checkout — including `preload` entries — which comes from the PR head. On such runners, make sure `node` is on `PATH` for the hook, and treat `bunfig.toml` and `.npmrc` in the checkout as PR-controlled runtime config on pull requests from authors with write access.
|
||||
|
||||
### Refusing pull requests from forks
|
||||
|
||||
By default, someone with write access can have the action work on a pull request from a fork. If you don't need that, turn it off, so that the action itself never checks out a fork's code:
|
||||
|
||||
```yaml
|
||||
- uses: anthropics/claude-code-action@v1
|
||||
with:
|
||||
allow_fork_prs: "false"
|
||||
```
|
||||
|
||||
The action then skips a pull request whose branch is in another repository, or in a fork that was deleted. It does so for every event, including comments on the conversation, whoever opened the pull request and whether it is open or closed. It also skips `workflow_run` events for a fork's run. It logs a warning, checks nothing out and doesn't start Claude, and the step succeeds without Claude's outputs, so a required check that only runs the action passes. Any value other than `true` turns forks off, including an empty one.
|
||||
|
||||
For a comment on the conversation, the action asks GitHub where the branch is, after it has checked the commenter's write access. The token needs `pull-requests: read` for that. If the answer can't be read, the run fails before anything is checked out.
|
||||
|
||||
This covers what the action does with the event that started it. It doesn't cover:
|
||||
|
||||
- **Other steps.** A step that checks out a fork's code, such as `actions/checkout` with the head of a `pull_request_target` event, does so before the action can refuse. A step after the action still runs.
|
||||
- **Events that don't name a pull request**, such as `issues`, `workflow_dispatch`, `repository_dispatch` and `schedule`. A `workflow_run` event is judged by the run right before it, so one that follows a comment's run, or another `workflow_run`, counts as yours.
|
||||
- **Commands in a session.** On an issue, for example, Claude could fetch a fork's commits with commands that you allow or that auto mode's review passes, such as `git` or `gh`.
|
||||
- **Commits already in your repository**, such as a `pr-N` branch from an earlier run, or a fork's commits that someone pushed to a branch of yours.
|
||||
- **Text.** Issues and comments from outside contributors still reach Claude.
|
||||
|
||||
### Running code from pull requests
|
||||
|
||||
A command that runs repository code (`npm install`, `bun test`, `make`) runs whatever the checkout contains, in a job that holds your workflow's tokens. Tag mode checks out the pull request's head, so on a pull request from an outside contributor that code is theirs, even when a maintainer triggered the run.
|
||||
@@ -100,7 +122,7 @@ Job logs, and job and step names, are text the pull request controls. To turn of
|
||||
|
||||
Bots often open pull requests from branches in your own repository. Runs there usually need no approval and can get secrets, so these steps don't protect you in that case.
|
||||
|
||||
**Upgrading:** workflows that use a floating tag or branch such as `@v1` or `@main` get this behavior without changing anything. If a workflow relied on commands like `npm test` running on pull requests from outside contributors or bots, those commands are now denied, Claude's config and tool config come from your default branch or `base_branch` even if the pull request targets another branch, as described [above](#which-files-come-from-the-base-branch-on-pull-requests), and a `cd` no longer carries over to the next Bash command. The run still succeeds, so check the log for the warning. Set `restrict_untrusted_prs: false` to turn this off.
|
||||
**Upgrading:** workflows that use a floating tag or branch such as `@v1` or `@main` get this behavior without changing anything. If a workflow relied on commands like `npm test` running on pull requests from outside contributors or bots, those commands are now denied, Claude's config and tool config come from your default branch or `base_branch` even if the pull request targets another branch, as described [above](#which-files-come-from-the-base-branch-on-pull-requests), Git LFS files from the pull request stay pointer files if they aren't downloaded yet, and a `cd` no longer carries over to the next Bash command. The run still succeeds, so check the log for the warning. Set `restrict_untrusted_prs: false` to turn this off.
|
||||
|
||||
### What a session can leave behind
|
||||
|
||||
@@ -108,6 +130,8 @@ Steps that run after Claude, including post steps such as `actions/checkout`'s c
|
||||
|
||||
While Claude runs, and for the action's own git commands afterwards, git ignores `core.fsmonitor`. Git hooks are off for the action's own commits after the session, and from before the checkout on pull requests that `restrict_untrusted_prs` applies to. During the session these are set in the repository's git config and by the wrapper scripts. Global git config also sets `safe.bareRepository=explicit` for the session, so git won't use a repository it finds in a folder that has no `.git`. A workflow that has Claude work in a bare repository needs to pass `--git-dir`. If a run is cancelled before it restores this, the setting stays in the global config of a self-hosted runner that keeps its home directory. Git LFS uploads through a hook, so the action uploads objects itself for its own commits, but a push Claude makes on such a pull request won't include them.
|
||||
|
||||
The action's own git commands use `safe.bareRepository=explicit` too. If the action starts in a bare repository, it doesn't set this before the session, unless `restrict_untrusted_prs` applies. On pull requests that `restrict_untrusted_prs` applies to, the action also checks out the pull request with `GIT_LFS_SKIP_SMUDGE=1`, so files that Git LFS hasn't downloaded yet stay as pointer files. The variable is set for that checkout only.
|
||||
|
||||
Claude's wrapper scripts for `git add`, `git rm`, `git commit` and `git push` always work on the repository the action checked out, and take only a short list of flags, so `git add -f` is refused. They ignore settings from the environment: `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_CONFIG_*`, any other `GIT_*` variable except the author and committer ones, `XDG_CONFIG_HOME`, and a `HOME` changed during the session. A workflow that relies on one of those, such as pushing over SSH with `GIT_SSH_COMMAND`, can allow its own command in `claude_args`, such as `Bash(git push:*)`, which gives up these protections for that workflow.
|
||||
|
||||
This has limits:
|
||||
@@ -119,7 +143,7 @@ This has limits:
|
||||
|
||||
### `claude-code-action` vs `claude-code-base-action`
|
||||
|
||||
`claude-code-base-action` is a lower-level building block that installs and runs Claude Code with the inputs you provide. It does not perform actor permission checks, restrict commands on pull requests from outside contributors, or restore project configuration from the base ref. If you need those behaviors, use this action (`claude-code-action`). See the [base-action README](../base-action/README.md#trust-model) for details.
|
||||
`claude-code-base-action` is a lower-level building block that installs and runs Claude Code with the inputs you provide. It does not perform actor permission checks, refuse pull requests from forks, restrict commands on pull requests from outside contributors, or restore project configuration from the base ref. If you need those behaviors, use this action (`claude-code-action`). See the [base-action README](../base-action/README.md#trust-model) for details.
|
||||
|
||||
## Pull Request Creation
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ jobs:
|
||||
| `include_comments_by_actor` | Comma-separated list of actor usernames to INCLUDE in comments. Supports the `*[bot]` wildcard to match all bot accounts. Empty (default) includes all actors | No | "" |
|
||||
| `exclude_comments_by_actor` | Comma-separated list of actor usernames to EXCLUDE from comments. Supports the `*[bot]` wildcard to match all bot accounts. If an actor matches both lists, exclusion takes priority | No | "" |
|
||||
| `allowed_bots` | Comma-separated list of allowed bot usernames, or '\*' to allow all bots. Empty string (default) allows no bots. **⚠️ On public repos with `'*'`, external Apps may be able to invoke this action.** See [Security](./security.md) | No | "" |
|
||||
| `allow_fork_prs` | Whether to run on pull requests from forks, and on `workflow_run` events for a fork's run. With any value other than `true`, the action skips them. See [Security](./security.md#refusing-pull-requests-from-forks). | No | `true` |
|
||||
| `restrict_untrusted_prs` | On pull requests whose author does not have write access, deny commands that commonly run code from the checkout, even if `claude_args` allows them. See [Security](./security.md#running-code-from-pull-requests). | No | `true` |
|
||||
| `allowed_non_write_users` | **⚠️ RISKY**: Comma-separated list of usernames to allow without write permissions, or '\*' for all users. Only works with `github_token` input. See [Security](./security.md) | No | "" |
|
||||
| `path_to_claude_code_executable` | Optional path to a custom Claude Code executable. Skips automatic installation. Useful for Nix, custom containers, or specialized environments | No | "" |
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.326",
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.3.327",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
|
||||
@@ -6,6 +6,7 @@ export function collectActionInputsPresence(): string {
|
||||
base_branch: "",
|
||||
branch_prefix: "claude/",
|
||||
allowed_bots: "",
|
||||
allow_fork_prs: "true",
|
||||
restrict_untrusted_prs: "true",
|
||||
mode: "tag",
|
||||
model: "",
|
||||
|
||||
@@ -80,7 +80,12 @@ async function run() {
|
||||
`Preparing with mode: ${modeName} for event: ${context.eventName}`,
|
||||
);
|
||||
if (modeName === "tag") {
|
||||
await prepareTagMode({ context, octokit, githubToken });
|
||||
await prepareTagMode({
|
||||
context,
|
||||
octokit,
|
||||
githubToken,
|
||||
skipLfsDownloads: true,
|
||||
});
|
||||
} else {
|
||||
await prepareAgentMode({ context, octokit, githubToken });
|
||||
}
|
||||
|
||||
+27
-2
@@ -16,6 +16,10 @@ import {
|
||||
checkBotActorPullRequestAuthor,
|
||||
checkWritePermissions,
|
||||
} from "../github/validation/permissions";
|
||||
import {
|
||||
isCommentOnRefusedForkPr,
|
||||
isRefusedForkEvent,
|
||||
} from "../github/validation/fork-pr";
|
||||
import { getUntrustedPrDisallowedTools } from "../github/validation/untrusted-pr";
|
||||
import { createOctokit } from "../github/api/client";
|
||||
import type { Octokits } from "../github/api/client";
|
||||
@@ -98,7 +102,7 @@ async function installClaudeCode(): Promise<string> {
|
||||
return customExecutable;
|
||||
}
|
||||
|
||||
const claudeCodeVersion = "2.1.326";
|
||||
const claudeCodeVersion = "2.1.327";
|
||||
console.log(`Installing Claude Code v${claudeCodeVersion}...`);
|
||||
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
@@ -168,6 +172,9 @@ async function writeStepSummary(executionFile: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const FORK_REFUSED =
|
||||
"Skipped, because allow_fork_prs is not true and this pull request or workflow run is from a fork.";
|
||||
|
||||
async function run() {
|
||||
// Bun has read this by now, and it's only for the action's own scripts
|
||||
delete process.env.BUN_RUNTIME_TRANSPILER_CACHE_PATH;
|
||||
@@ -192,6 +199,13 @@ async function run() {
|
||||
// Phase 1: Prepare
|
||||
const actionInputsPresent = collectActionInputsPresence();
|
||||
context = parseGitHubContext();
|
||||
|
||||
// Before a token, which GitHub doesn't give to some of these events
|
||||
if (isRefusedForkEvent(context)) {
|
||||
core.warning(FORK_REFUSED);
|
||||
return;
|
||||
}
|
||||
|
||||
const modeName = detectMode(context);
|
||||
console.log(
|
||||
`Auto-detected mode: ${modeName} for event: ${context.eventName}`,
|
||||
@@ -246,6 +260,12 @@ async function run() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Before the action checks anything out
|
||||
if (await isCommentOnRefusedForkPr(octokit.rest, context)) {
|
||||
core.warning(FORK_REFUSED);
|
||||
return;
|
||||
}
|
||||
|
||||
const botActorAllowed = await checkBotActorPullRequestAuthor(
|
||||
octokit.rest,
|
||||
context,
|
||||
@@ -274,7 +294,12 @@ async function run() {
|
||||
);
|
||||
const prepareResult =
|
||||
modeName === "tag"
|
||||
? await prepareTagMode({ context, octokit, githubToken })
|
||||
? await prepareTagMode({
|
||||
context,
|
||||
octokit,
|
||||
githubToken,
|
||||
skipLfsDownloads: hooksOff,
|
||||
})
|
||||
: await prepareAgentMode({ context, octokit, githubToken });
|
||||
|
||||
commentId = prepareResult.commentId;
|
||||
|
||||
@@ -16,6 +16,7 @@ import type { Octokits } from "../api/client";
|
||||
import type { FetchDataResult } from "../data/fetcher";
|
||||
import { generateBranchName } from "../../utils/branch-template";
|
||||
import { fetchDepthArgs } from "./fetch-depth";
|
||||
import { forksAllowed } from "../validation/fork-pr";
|
||||
|
||||
/**
|
||||
* Extracts the first label from GitHub data, or returns undefined if no labels exist
|
||||
@@ -144,8 +145,8 @@ export function validateBranchName(branchName: string): void {
|
||||
*
|
||||
* @param args - Git command arguments (e.g., ["checkout", "branch-name"])
|
||||
*/
|
||||
function execGit(args: string[]): void {
|
||||
execFileSync("git", args, { stdio: "inherit", env: process.env });
|
||||
function execGit(args: string[], env: NodeJS.ProcessEnv = process.env): void {
|
||||
execFileSync("git", args, { stdio: "inherit", env });
|
||||
}
|
||||
|
||||
export type BranchInfo = {
|
||||
@@ -160,7 +161,8 @@ export async function setupBranch(
|
||||
octokits: Octokits,
|
||||
githubData: FetchDataResult,
|
||||
context: ParsedGitHubContext,
|
||||
triggerTime?: string,
|
||||
triggerTime: string | undefined,
|
||||
skipLfsDownloads: boolean,
|
||||
): Promise<BranchInfo> {
|
||||
const { owner, repo } = context.repository;
|
||||
const entityNumber = context.entityNumber;
|
||||
@@ -178,6 +180,11 @@ export async function setupBranch(
|
||||
);
|
||||
// Fall through to create a new branch like we do for issues
|
||||
} else {
|
||||
// run.ts has skipped these already.
|
||||
if (prData.isCrossRepository && !forksAllowed()) {
|
||||
throw new Error(`PR #${entityNumber} is from a fork`);
|
||||
}
|
||||
|
||||
// Handle open PR: Checkout the PR branch
|
||||
console.log("This is an open PR, checking out PR branch...");
|
||||
|
||||
@@ -241,7 +248,13 @@ export async function setupBranch(
|
||||
: branchName;
|
||||
console.log(`PR #${entityNumber}: pinning ${localBranch} to ${headSha}`);
|
||||
execGit(["fetch", "origin", ...depthArgs, headSha]);
|
||||
execGit(["checkout", "-B", localBranch, headSha, "--"]);
|
||||
execGit(
|
||||
["checkout", "-B", localBranch, headSha, "--"],
|
||||
// Files that Git LFS would download stay as pointer files.
|
||||
skipLfsDownloads
|
||||
? { ...process.env, GIT_LFS_SKIP_SMUDGE: "1" }
|
||||
: process.env,
|
||||
);
|
||||
|
||||
const checkedOut = execFileSync("git", ["rev-parse", "HEAD"], {
|
||||
encoding: "utf8",
|
||||
|
||||
@@ -38,6 +38,11 @@ const SESSION_STATE_FILES = [
|
||||
".restored-paths",
|
||||
];
|
||||
|
||||
const NO_IMPLICIT_BARE_REPOSITORY: [string, string] = [
|
||||
"safe.bareRepository",
|
||||
"explicit",
|
||||
];
|
||||
|
||||
// How many GIT_CONFIG_* entries were there before disableGitPrograms added any.
|
||||
let entriesBeforeAction: number | undefined;
|
||||
|
||||
@@ -251,7 +256,14 @@ export function disableGitPrograms({ hooks }: { hooks: boolean }): void {
|
||||
process.env[`GIT_CONFIG_VALUE_${i}`],
|
||||
);
|
||||
}
|
||||
for (const [key, value] of gitProgramSettings({ hooks })) {
|
||||
const settings = gitProgramSettings({ hooks });
|
||||
// A workflow may run the action in a bare repository, where this setting would stop git.
|
||||
const setting = NO_IMPLICIT_BARE_REPOSITORY.join("=");
|
||||
const stopsGit =
|
||||
gitOutput("rev-parse", "--git-dir") !== null &&
|
||||
gitOutput("-c", setting, "rev-parse", "--git-dir") === null;
|
||||
if (hooks || !stopsGit) settings.push(NO_IMPLICIT_BARE_REPOSITORY);
|
||||
for (const [key, value] of settings) {
|
||||
if (current.get(key) === value) continue;
|
||||
process.env[`GIT_CONFIG_KEY_${count}`] = key;
|
||||
process.env[`GIT_CONFIG_VALUE_${count}`] = value;
|
||||
@@ -330,8 +342,8 @@ const gitOutput = (...args: string[]): string | null => {
|
||||
* Moves the settings from disableGitPrograms out of the environment for the session.
|
||||
* Repository config and the wrappers keep them in force instead, and
|
||||
* snapshotSessionFiles puts the config back afterwards. Elsewhere the concern is a
|
||||
* repository git finds in a plain folder, with its own config. Git only reads
|
||||
* safe.bareRepository from global config or the command line.
|
||||
* repository git finds in a plain folder, with its own config. Git ignores
|
||||
* safe.bareRepository in repository config, so the session gets it from global config.
|
||||
*/
|
||||
export function prepareGitForSession({ hooks }: { hooks: boolean }): void {
|
||||
const count = Number.parseInt(process.env.GIT_CONFIG_COUNT ?? "", 10) || 0;
|
||||
@@ -356,7 +368,7 @@ export function prepareGitForSession({ hooks }: { hooks: boolean }): void {
|
||||
const gitDir = gitOutput("rev-parse", "--absolute-git-dir");
|
||||
const workTree = gitDir && gitOutput("rev-parse", "--show-toplevel");
|
||||
if (gitDir) setConfig("--local", gitProgramSettings({ hooks }));
|
||||
setConfig("--global", [["safe.bareRepository", "explicit"]]);
|
||||
setConfig("--global", [NO_IMPLICIT_BARE_REPOSITORY]);
|
||||
|
||||
try {
|
||||
if (hooks) writeSessionFile(".no-hooks", "");
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import { retryWithBackoff } from "../../utils/retry";
|
||||
import { toLookupError, type LookupError } from "./untrusted-pr";
|
||||
import {
|
||||
isEntityContext,
|
||||
isWorkflowRunEvent,
|
||||
type GitHubContext,
|
||||
} from "../context";
|
||||
|
||||
type Repository = { id?: number } | null | undefined;
|
||||
|
||||
// A deleted fork has no repository.
|
||||
const isSameRepository = (head: Repository, base: Repository): boolean =>
|
||||
typeof head?.id === "number" && head.id === base?.id;
|
||||
|
||||
// Only "true" allows forks, so a mistyped or empty value refuses them.
|
||||
export const forksAllowed = (): boolean =>
|
||||
(process.env.ALLOW_FORK_PRS ?? "true").trim().toLowerCase() === "true";
|
||||
|
||||
/**
|
||||
* Whether allow_fork_prs is off and the event says that it is about a fork's pull
|
||||
* request, or follows a workflow run of a fork's code. Needs no token. A comment on
|
||||
* a pull request's conversation doesn't say: see isCommentOnRefusedForkPr.
|
||||
*/
|
||||
export function isRefusedForkEvent(context: GitHubContext): boolean {
|
||||
if (forksAllowed()) return false;
|
||||
|
||||
if (isWorkflowRunEvent(context)) {
|
||||
const { workflow_run: run, repository } = context.payload;
|
||||
return !isSameRepository(run?.head_repository, repository);
|
||||
}
|
||||
if (isEntityContext(context) && "pull_request" in context.payload) {
|
||||
const { head, base } = context.payload.pull_request;
|
||||
return !isSameRepository(head.repo, base.repo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether allow_fork_prs is off and the event is a comment on the conversation of a
|
||||
* fork's pull request. Throws if that can't be found out.
|
||||
*/
|
||||
export async function isCommentOnRefusedForkPr(
|
||||
octokit: Octokit,
|
||||
context: GitHubContext,
|
||||
): Promise<boolean> {
|
||||
if (
|
||||
forksAllowed() ||
|
||||
!isEntityContext(context) ||
|
||||
!context.isPR ||
|
||||
"pull_request" in context.payload
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { owner, repo } = context.repository;
|
||||
const lookUp = async () => {
|
||||
try {
|
||||
return await octokit.pulls.get({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: context.entityNumber,
|
||||
});
|
||||
} catch (error) {
|
||||
throw toLookupError(error);
|
||||
}
|
||||
};
|
||||
const { data } = await retryWithBackoff(lookUp, {
|
||||
initialDelayMs: 1000,
|
||||
shouldRetry: (error) => (error as LookupError).retryable,
|
||||
}).catch((error: LookupError) => {
|
||||
// Only the bounded text from toLookupError reaches the log.
|
||||
throw new Error(
|
||||
`Could not find out whether pull request #${context.entityNumber} is from a fork (${error.message}). The token needs pull-requests: read.`,
|
||||
);
|
||||
});
|
||||
return !isSameRepository(data.head.repo, data.base.repo);
|
||||
}
|
||||
@@ -93,15 +93,15 @@ function getPrAuthor(context: ParsedGitHubContext): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
type LookupError = Error & { retryable: boolean };
|
||||
export type LookupError = Error & { retryable: boolean };
|
||||
|
||||
/**
|
||||
* Reduces a failed API call to its HTTP status, so that nothing else from the
|
||||
* error can reach the workflow log, and decides whether to try again. A 404 (not
|
||||
* a user account) or a plain 403 won't change, but GitHub also uses 403 for rate
|
||||
* limits. Whatever the outcome, a failed lookup counts as untrusted.
|
||||
* error can reach the workflow log, and decides whether to try again. A 404 or a
|
||||
* plain 403 won't change, but GitHub also uses 403 for rate
|
||||
* limits.
|
||||
*/
|
||||
function toLookupError(error: unknown): LookupError {
|
||||
export function toLookupError(error: unknown): LookupError {
|
||||
const { status, response } = error as {
|
||||
status?: number;
|
||||
response?: { headers?: Record<string, string | number | undefined> };
|
||||
|
||||
@@ -40,10 +40,12 @@ export async function prepareTagMode({
|
||||
context,
|
||||
octokit,
|
||||
githubToken,
|
||||
skipLfsDownloads,
|
||||
}: {
|
||||
context: GitHubContext;
|
||||
octokit: Octokits;
|
||||
githubToken: string;
|
||||
skipLfsDownloads: boolean;
|
||||
}) {
|
||||
// Tag mode only handles entity-based events
|
||||
if (!isEntityContext(context)) {
|
||||
@@ -87,6 +89,7 @@ export async function prepareTagMode({
|
||||
githubData,
|
||||
context,
|
||||
editedAt || triggerTime,
|
||||
skipLfsDownloads,
|
||||
);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
|
||||
@@ -68,6 +68,17 @@ describe("action metadata", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("should allow fork pull requests by default and pass the input to the run step", () => {
|
||||
const metadata = readMetadata("action.yml");
|
||||
|
||||
expect(metadata).toMatch(
|
||||
/^ allow_fork_prs:\n description: .+\n required: false\n default: "true"$/m,
|
||||
);
|
||||
expect(metadata).toMatch(
|
||||
/^ ALLOW_FORK_PRS: \$\{\{ inputs\.allow_fork_prs \}\}$/m,
|
||||
);
|
||||
});
|
||||
|
||||
test("should start each of the action's scripts with the same Bun options", () => {
|
||||
const commands = readMetadata("action.yml")
|
||||
.replace(/\\\n\s*/g, "")
|
||||
|
||||
@@ -180,7 +180,10 @@ describe("in a shallow checkout of the default branch", () => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const checkOutPullRequest = (isCrossRepository: boolean) =>
|
||||
const checkOutPullRequest = (
|
||||
isCrossRepository: boolean,
|
||||
skipLfsDownloads = false,
|
||||
) =>
|
||||
setupBranch(
|
||||
{} as any,
|
||||
{
|
||||
@@ -194,6 +197,8 @@ describe("in a shallow checkout of the default branch", () => {
|
||||
},
|
||||
} as any,
|
||||
mockPullRequestCommentContext,
|
||||
undefined,
|
||||
skipLfsDownloads,
|
||||
);
|
||||
|
||||
test("setupBranch says whether it checked out a fork", async () => {
|
||||
@@ -201,6 +206,23 @@ describe("in a shallow checkout of the default branch", () => {
|
||||
expect((await checkOutPullRequest(false)).isFork).toBe(false);
|
||||
});
|
||||
|
||||
test.each([true, false])(
|
||||
"setupBranch skips Git LFS downloads for its checkout only: %p",
|
||||
async (skip) => {
|
||||
const before = process.env.GIT_LFS_SKIP_SMUDGE;
|
||||
delete process.env.GIT_LFS_SKIP_SMUDGE;
|
||||
try {
|
||||
git(".", "config", "filter.show.smudge", 'echo "$GIT_LFS_SKIP_SMUDGE"');
|
||||
writeFileSync(".git/info/attributes", "change.txt filter=show\n");
|
||||
await checkOutPullRequest(true, skip);
|
||||
expect(readFileSync("change.txt", "utf8").trim()).toBe(skip ? "1" : "");
|
||||
expect(process.env.GIT_LFS_SKIP_SMUDGE).toBeUndefined();
|
||||
} finally {
|
||||
if (before !== undefined) process.env.GIT_LFS_SKIP_SMUDGE = before;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("the base can still be compared after restoring from another branch", async () => {
|
||||
await checkOutPullRequest(true);
|
||||
restoreConfigFromBase("trunk");
|
||||
|
||||
@@ -70,7 +70,7 @@ describe("setupBranch fetch depth", () => {
|
||||
inputs: { useCommitSigning, branchPrefix: "claude/" },
|
||||
});
|
||||
|
||||
await setupBranch(octokits, githubData, context);
|
||||
await setupBranch(octokits, githubData, context, undefined, false);
|
||||
|
||||
expect(git(["rev-parse", "--is-shallow-repository"]).trim()).toBe(
|
||||
"false",
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "fs";
|
||||
import { tmpdir } from "os";
|
||||
import { join } from "path";
|
||||
import type { GitHubContext, ParsedGitHubContext } from "../src/github/context";
|
||||
import { setupBranch } from "../src/github/operations/branch";
|
||||
import {
|
||||
isCommentOnRefusedForkPr,
|
||||
isRefusedForkEvent,
|
||||
} from "../src/github/validation/fork-pr";
|
||||
import {
|
||||
createMockAutomationContext,
|
||||
mockIssueCommentContext,
|
||||
mockIssueOpenedContext,
|
||||
mockPullRequestCommentContext,
|
||||
mockPullRequestOpenedContext,
|
||||
mockPullRequestReviewCommentContext,
|
||||
mockPullRequestReviewContext,
|
||||
} from "./mockContext";
|
||||
|
||||
const BASE = { id: 1 };
|
||||
const FORK = { id: 2 };
|
||||
type Head = { id: number } | null;
|
||||
|
||||
function octokitWith(reply: () => unknown) {
|
||||
const calls: unknown[] = [];
|
||||
const octokit = {
|
||||
pulls: {
|
||||
get: async (params: unknown) => {
|
||||
calls.push(params);
|
||||
return { data: reply() };
|
||||
},
|
||||
},
|
||||
} as any;
|
||||
return { octokit, calls };
|
||||
}
|
||||
|
||||
const pullRequest = (head: Head) => ({
|
||||
head: { repo: head },
|
||||
base: { repo: BASE },
|
||||
});
|
||||
|
||||
const withHead = (
|
||||
context: ParsedGitHubContext,
|
||||
head: Head,
|
||||
): ParsedGitHubContext => {
|
||||
const payload = context.payload as any;
|
||||
return {
|
||||
...context,
|
||||
payload: {
|
||||
...payload,
|
||||
pull_request: { ...payload.pull_request, ...pullRequest(head) },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const workflowRun = (head: Head | undefined): GitHubContext =>
|
||||
createMockAutomationContext({
|
||||
eventName: "workflow_run",
|
||||
payload: {
|
||||
workflow_run: { head_repository: head },
|
||||
repository: BASE,
|
||||
} as any,
|
||||
});
|
||||
|
||||
// What run.ts asks, in its order.
|
||||
const isRefusedForkPr = async (octokit: any, context: GitHubContext) =>
|
||||
isRefusedForkEvent(context) || isCommentOnRefusedForkPr(octokit, context);
|
||||
|
||||
describe("allow_fork_prs", () => {
|
||||
const saved = process.env.ALLOW_FORK_PRS;
|
||||
const { octokit: unused, calls: unusedCalls } = octokitWith(() => {
|
||||
throw new Error("unexpected call");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.ALLOW_FORK_PRS = "false";
|
||||
unusedCalls.length = 0;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (saved === undefined) delete process.env.ALLOW_FORK_PRS;
|
||||
else process.env.ALLOW_FORK_PRS = saved;
|
||||
});
|
||||
|
||||
const fork = withHead(mockPullRequestOpenedContext, FORK);
|
||||
|
||||
test.each(["true", "TRUE", " true "])(
|
||||
"allows forks when set to %p",
|
||||
async (value) => {
|
||||
process.env.ALLOW_FORK_PRS = value;
|
||||
expect(await isRefusedForkPr(unused, fork)).toBe(false);
|
||||
expect(await isRefusedForkPr(unused, mockPullRequestCommentContext)).toBe(
|
||||
false,
|
||||
);
|
||||
expect(await isRefusedForkPr(unused, workflowRun(FORK))).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
test("allows forks when action.yml didn't pass the input", async () => {
|
||||
delete process.env.ALLOW_FORK_PRS;
|
||||
expect(await isRefusedForkPr(unused, fork)).toBe(false);
|
||||
});
|
||||
|
||||
test.each(["false", "False", "", "no", "flase", "0"])(
|
||||
"refuses forks when set to %p",
|
||||
async (value) => {
|
||||
process.env.ALLOW_FORK_PRS = value;
|
||||
expect(await isRefusedForkPr(unused, fork)).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
test.each([
|
||||
["pull_request", mockPullRequestOpenedContext],
|
||||
["pull_request_review", mockPullRequestReviewContext],
|
||||
["pull_request_review_comment", mockPullRequestReviewCommentContext],
|
||||
])("%s: reads the head from the event", async (_event, context) => {
|
||||
const refused = (head: Head) =>
|
||||
isRefusedForkPr(unused, withHead(context, head));
|
||||
expect(await refused(FORK)).toBe(true);
|
||||
expect(await refused(null)).toBe(true);
|
||||
expect(await refused(BASE)).toBe(false);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[FORK, true],
|
||||
[null, true],
|
||||
[BASE, false],
|
||||
])("comment on a pull request with head %p: %p", async (head, expected) => {
|
||||
const { octokit, calls } = octokitWith(() => pullRequest(head));
|
||||
expect(await isRefusedForkPr(octokit, mockPullRequestCommentContext)).toBe(
|
||||
expected,
|
||||
);
|
||||
expect(calls).toEqual([
|
||||
{
|
||||
owner: mockPullRequestCommentContext.repository.owner,
|
||||
repo: mockPullRequestCommentContext.repository.repo,
|
||||
pull_number: mockPullRequestCommentContext.entityNumber,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("a comment fails when the pull request can't be read", async () => {
|
||||
const { octokit, calls } = octokitWith(() => {
|
||||
throw Object.assign(new Error("secret"), { status: 404 });
|
||||
});
|
||||
const refused = isRefusedForkPr(octokit, mockPullRequestCommentContext);
|
||||
await expect(refused).rejects.toThrow("is from a fork (HTTP 404)");
|
||||
expect(calls.length).toBe(1);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[FORK, true],
|
||||
[null, true],
|
||||
[undefined, true],
|
||||
[BASE, false],
|
||||
])("workflow_run of head %p: %p", async (head, expected) => {
|
||||
expect(await isRefusedForkPr(unused, workflowRun(head))).toBe(expected);
|
||||
});
|
||||
|
||||
test("issues and other events are not affected", async () => {
|
||||
for (const context of [
|
||||
mockIssueOpenedContext,
|
||||
mockIssueCommentContext,
|
||||
createMockAutomationContext({ eventName: "workflow_dispatch" }),
|
||||
createMockAutomationContext({ eventName: "schedule" }),
|
||||
]) {
|
||||
expect(await isRefusedForkPr(unused, context)).toBe(false);
|
||||
}
|
||||
expect(unusedCalls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
test("setupBranch refuses a fork when allow_fork_prs is off", async () => {
|
||||
const saved = process.env.ALLOW_FORK_PRS;
|
||||
process.env.ALLOW_FORK_PRS = "false";
|
||||
try {
|
||||
const data = { contextData: { state: "OPEN", isCrossRepository: true } };
|
||||
await expect(
|
||||
(setupBranch as any)({}, data, mockPullRequestCommentContext),
|
||||
).rejects.toThrow("is from a fork");
|
||||
} finally {
|
||||
if (saved === undefined) delete process.env.ALLOW_FORK_PRS;
|
||||
else process.env.ALLOW_FORK_PRS = saved;
|
||||
}
|
||||
});
|
||||
|
||||
describe("run.ts with allow_fork_prs: false", () => {
|
||||
// Returns the exit code, the output and the requests made. The directory is not a
|
||||
// git repository, so a run that goes on to check something out fails.
|
||||
async function run(eventName: string, event: object, pull?: object) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "fork-pr-"));
|
||||
const requests: string[] = [];
|
||||
const server = Bun.serve({
|
||||
port: 0,
|
||||
hostname: "127.0.0.1",
|
||||
fetch(request) {
|
||||
const { pathname } = new URL(request.url);
|
||||
requests.push(pathname);
|
||||
if (pathname.endsWith("/permission")) {
|
||||
return Response.json({ permission: "write" });
|
||||
}
|
||||
return pull && pathname.endsWith("/pulls/7")
|
||||
? Response.json(pull)
|
||||
: Response.json({}, { status: 404 });
|
||||
},
|
||||
});
|
||||
try {
|
||||
for (const file of ["output", "env"]) writeFileSync(join(dir, file), "");
|
||||
writeFileSync(join(dir, "event.json"), JSON.stringify(event));
|
||||
const child = Bun.spawn(
|
||||
[
|
||||
process.execPath,
|
||||
"run",
|
||||
join(import.meta.dir, "../src/entrypoints/run.ts"),
|
||||
],
|
||||
{
|
||||
cwd: dir,
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
HOME: dir,
|
||||
RUNNER_TEMP: dir,
|
||||
GITHUB_EVENT_NAME: eventName,
|
||||
GITHUB_EVENT_PATH: join(dir, "event.json"),
|
||||
GITHUB_REPOSITORY: "o/r",
|
||||
GITHUB_ACTOR: "writer",
|
||||
GITHUB_RUN_ID: "1",
|
||||
GITHUB_OUTPUT: join(dir, "output"),
|
||||
GITHUB_ENV: join(dir, "env"),
|
||||
GITHUB_API_URL: `http://127.0.0.1:${server.port}`,
|
||||
TRIGGER_PHRASE: "@claude",
|
||||
ALLOW_FORK_PRS: "false",
|
||||
// With no token, a run that asks for one fails.
|
||||
...(pull && { OVERRIDE_GITHUB_TOKEN: "t" }),
|
||||
},
|
||||
},
|
||||
);
|
||||
const [stdout, stderr, exitCode] = await Promise.all([
|
||||
new Response(child.stdout).text(),
|
||||
new Response(child.stderr).text(),
|
||||
child.exited,
|
||||
]);
|
||||
return { exitCode, log: stdout + stderr, requests };
|
||||
} finally {
|
||||
server.stop(true);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
const repository = { id: 1, name: "r", owner: { login: "o" } };
|
||||
const sender = { login: "writer", type: "User" };
|
||||
|
||||
test("skips a fork's event before it asks for a token", async () => {
|
||||
const result = await run("pull_request_review", {
|
||||
action: "submitted",
|
||||
repository,
|
||||
sender,
|
||||
review: { id: 1, body: "@claude", user: sender },
|
||||
pull_request: { number: 7, ...pullRequest(FORK) },
|
||||
});
|
||||
expect(result.log).toContain("Skipped, because allow_fork_prs");
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.requests).toEqual([]);
|
||||
});
|
||||
|
||||
test("skips a comment on a fork's pull request before it does anything else", async () => {
|
||||
const result = await run(
|
||||
"issue_comment",
|
||||
{
|
||||
action: "created",
|
||||
repository,
|
||||
sender,
|
||||
issue: { number: 7, pull_request: {}, user: { login: "outsider" } },
|
||||
comment: { id: 1, body: "@claude", user: sender },
|
||||
},
|
||||
pullRequest(FORK),
|
||||
);
|
||||
expect(result.log).toContain("Skipped, because allow_fork_prs");
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.requests).toEqual([
|
||||
"/repos/o/r/collaborators/writer/permission",
|
||||
"/repos/o/r/pulls/7",
|
||||
]);
|
||||
});
|
||||
|
||||
test("goes on with a comment on a pull request in this repository", async () => {
|
||||
const result = await run(
|
||||
"issue_comment",
|
||||
{
|
||||
action: "created",
|
||||
repository,
|
||||
sender,
|
||||
issue: { number: 7, pull_request: {}, user: { login: "outsider" } },
|
||||
comment: { id: 1, body: "@claude", user: sender },
|
||||
},
|
||||
pullRequest(BASE),
|
||||
);
|
||||
expect(result.log).not.toContain("Skipped, because allow_fork_prs");
|
||||
expect(result.requests.length).toBeGreaterThan(2);
|
||||
});
|
||||
});
|
||||
@@ -69,6 +69,7 @@ describe("Tag Mode", () => {
|
||||
context,
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads: false,
|
||||
});
|
||||
|
||||
expect(configureGitAuthSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -81,6 +82,21 @@ describe("Tag Mode", () => {
|
||||
expect(replaceCheckoutCredentialsSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.each([true, false])(
|
||||
"tells setupBranch whether to skip Git LFS downloads: %p",
|
||||
async (skipLfsDownloads) => {
|
||||
await prepareTagMode({
|
||||
context: { ...mockIssueCommentContext },
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads,
|
||||
});
|
||||
expect(branch.setupBranch).toHaveBeenCalledTimes(1);
|
||||
const call = (branch.setupBranch as any).mock.calls[0];
|
||||
expect(call[4]).toBe(skipLfsDownloads);
|
||||
},
|
||||
);
|
||||
|
||||
describe("push branch", () => {
|
||||
const savedPath = process.env.GITHUB_ACTION_PATH;
|
||||
let actionPath: string;
|
||||
@@ -104,6 +120,7 @@ describe("Tag Mode", () => {
|
||||
context: { ...mockIssueCommentContext },
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads: false,
|
||||
});
|
||||
expect(pinned()).toBe("claude/test");
|
||||
expect(process.env.CLAUDE_PUSH_BRANCH).toBeUndefined();
|
||||
@@ -120,6 +137,7 @@ describe("Tag Mode", () => {
|
||||
context: { ...mockIssueCommentContext },
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads: false,
|
||||
});
|
||||
expect(pinned()).toBe("feature");
|
||||
});
|
||||
@@ -149,6 +167,7 @@ describe("Tag Mode", () => {
|
||||
context: { ...mockIssueCommentContext },
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads: false,
|
||||
});
|
||||
return claudeArgs;
|
||||
};
|
||||
@@ -216,6 +235,7 @@ describe("Tag Mode", () => {
|
||||
context,
|
||||
octokit: {} as any,
|
||||
githubToken: "test-token",
|
||||
skipLfsDownloads: false,
|
||||
});
|
||||
|
||||
expect(configureGitAuthSpy).not.toHaveBeenCalled();
|
||||
|
||||
@@ -38,6 +38,8 @@ const KEYS = [
|
||||
"GIT_CONFIG_VALUE_1",
|
||||
"GIT_CONFIG_KEY_2",
|
||||
"GIT_CONFIG_VALUE_2",
|
||||
"GIT_CONFIG_KEY_3",
|
||||
"GIT_CONFIG_VALUE_3",
|
||||
// git exports these into hooks, such as a pre-commit hook running this suite.
|
||||
// If inherited, git would act on the enclosing repository, not the temp one.
|
||||
"GIT_DIR",
|
||||
@@ -221,7 +223,7 @@ describe("session guard", () => {
|
||||
|
||||
test("moves the action's settings from the environment to the repository", () => {
|
||||
disableGitPrograms({ hooks: true });
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("2");
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("3");
|
||||
const restore = snapshotSessionFiles(() =>
|
||||
prepareGitForSession({ hooks: true }),
|
||||
);
|
||||
@@ -444,14 +446,46 @@ describe("session guard", () => {
|
||||
|
||||
test("leaves hooks alone when not asked", () => {
|
||||
disableGitPrograms({ hooks: false });
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("1");
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("2");
|
||||
expect(process.env.GIT_CONFIG_KEY_0).toBe("core.fsmonitor");
|
||||
});
|
||||
|
||||
test.each([true, false])(
|
||||
"sets safe.bareRepository for the action's git commands (disable hooks: %p)",
|
||||
(hooks) => {
|
||||
disableGitPrograms({ hooks });
|
||||
expect(git("config", "safe.bareRepository").trim()).toBe("explicit");
|
||||
git("init", "-q", "--bare", join(dir, "repo", "folder"));
|
||||
expect(() => git("-C", "folder", "rev-parse", "--git-dir")).toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
test("finds a bare repository in the current directory when hooks stay on", () => {
|
||||
git("init", "-q", "--bare", join(dir, "bare.git"));
|
||||
process.chdir(join(dir, "bare.git"));
|
||||
disableGitPrograms({ hooks: false });
|
||||
expect(git("rev-parse", "--is-bare-repository").trim()).toBe("true");
|
||||
});
|
||||
|
||||
test("sets safe.bareRepository in a repository whose .git file names a bare one", () => {
|
||||
git("init", "-q", "--bare", join(dir, "tree", ".bare"));
|
||||
writeFileSync(join(dir, "tree", ".git"), "gitdir: ./.bare\n");
|
||||
process.chdir(join(dir, "tree"));
|
||||
disableGitPrograms({ hooks: false });
|
||||
expect(git("config", "safe.bareRepository").trim()).toBe("explicit");
|
||||
});
|
||||
|
||||
test("refuses a bare repository in the current directory when hooks are off", () => {
|
||||
git("init", "-q", "--bare", join(dir, "bare.git"));
|
||||
process.chdir(join(dir, "bare.git"));
|
||||
disableGitPrograms({ hooks: true });
|
||||
expect(() => git("rev-parse", "--is-bare-repository")).toThrow();
|
||||
});
|
||||
|
||||
test("does not add a setting twice", () => {
|
||||
disableGitPrograms({ hooks: true });
|
||||
disableGitPrograms({ hooks: true });
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("2");
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("3");
|
||||
});
|
||||
|
||||
test("keeps existing GIT_CONFIG entries", () => {
|
||||
@@ -459,7 +493,7 @@ describe("session guard", () => {
|
||||
process.env.GIT_CONFIG_KEY_0 = "user.name";
|
||||
process.env.GIT_CONFIG_VALUE_0 = "someone";
|
||||
disableGitPrograms({ hooks: true });
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("3");
|
||||
expect(process.env.GIT_CONFIG_COUNT).toBe("4");
|
||||
expect(process.env.GIT_CONFIG_KEY_0).toBe("user.name");
|
||||
expect(process.env.GIT_CONFIG_KEY_1).toBe("core.fsmonitor");
|
||||
expect(process.env.GIT_CONFIG_KEY_2).toBe("core.hooksPath");
|
||||
|
||||
@@ -67,9 +67,9 @@ describe("setupBranch generated branch name validation", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await expect(setupBranch(octokits, githubData, context)).rejects.toThrow(
|
||||
"process.exit called",
|
||||
);
|
||||
await expect(
|
||||
setupBranch(octokits, githubData, context, undefined, false),
|
||||
).rejects.toThrow("process.exit called");
|
||||
expect(exitCode).toBe(1);
|
||||
// Must fail on the name itself, not on a later git or API call.
|
||||
expect(loggedErrors.join("\n")).toContain(
|
||||
|
||||
Reference in New Issue
Block a user