-
Notifications
You must be signed in to change notification settings - Fork 5.4k
allow just recipes to be run directly from PR comments #7463
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,59 @@ | ||||||||||||||||||||||||||
| name: Run Command on Comment | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||
| issue_comment: | ||||||||||||||||||||||||||
| types: | ||||||||||||||||||||||||||
| - created | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||
| process_comment: | ||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||
| - name: Check if the comment contains the run command | ||||||||||||||||||||||||||
| id: check_comment | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| commands=echo '${{ github.event.comment.body }}' | grep -oPz '```run_this\n(just .*\n)*```\n' | | ||||||||||||||||||||||||||
| - uses: actions/checkout@v3 | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| - name: Install toolchain | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| uses: dtolnay/rust-toolchain@master | ||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||
| toolchain: ${{ env.RUST_VERSION }} | ||||||||||||||||||||||||||
| - uses: Swatinem/rust-cache@v2 | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||
| cache-provider: "warpbuild" | ||||||||||||||||||||||||||
| - name: Install just | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| run: cargo install just | ||||||||||||||||||||||||||
| - name: Execute the commands | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| id: execute_commands | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| echo "${{ steps.check_comment.outputs.commands }}" | while read line; do | ||||||||||||||||||||||||||
| echo "[$line]" | ||||||||||||||||||||||||||
| if [ "$line" = "\`\`\`run_this" ]; then | ||||||||||||||||||||||||||
| OUTPUT="" | ||||||||||||||||||||||||||
| elif [[ "$line" = "\`\`\`" ]]; then | ||||||||||||||||||||||||||
| echo "Results:" | ||||||||||||||||||||||||||
| echo "\`\`\`" | ||||||||||||||||||||||||||
| echo "$OUTPUT" | ||||||||||||||||||||||||||
| echo "\`\`\`" | ||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||
| NEWOUTPUT=$(bash -c "$line" 2>&1) | ||||||||||||||||||||||||||
| OUTPUT="$OUTPUT $NEWOUTPUT" | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||
| - name: Create commit comment | ||||||||||||||||||||||||||
| if: steps.check_comment.outputs.commands != '' | ||||||||||||||||||||||||||
| uses: peter-evans/commit-comment@v4 | ||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||
| body: | | ||||||||||||||||||||||||||
| Running: | ||||||||||||||||||||||||||
| ${{ steps.check_comment.outputs.commands }} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Results: | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| ${{ steps.execute_commands.outputs.OUTPUT }} | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
Comment on lines
+10
to
+59
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
Copilot AutofixAI 24 days ago The best way to fix this issue is to explicitly set a
The most conservative recommendation is to add the following block at the same level as permissions:
contents: writeAlternatively, if you wish to restrict permissions further and only give write at the job level (not globally), you can add the Action: Insert the following block between line 2 and line 3 in the permissions:
contents: writeNo additional imports or definitions are required for YAML workflows.
Suggested changeset
1
.github/workflows/pr-automation.yml
Copilot is powered by AI and may make mistakes. Always verify output.
Positive FeedbackNegative Feedback
Refresh and try again.
|
||||||||||||||||||||||||||
Check failure
Code scanning / CodeQL
Code injection Critical
Copilot Autofix
AI 24 days ago
How to fix:
Replace the direct interpolation of
${{ github.event.comment.body }}into the shell command with safe usage via environment variables.Detailed fix:
At the start of the step where we use
${{ github.event.comment.body }}, add anenv:block to assign its value to an environment variable, e.g.,COMMENT_BODY. Then, in therun:command, reference the value with proper shell variable syntax ("$COMMENT_BODY"). This allows the shell to safely parse the value regardless of its content and prevents opportunity for code injection or unintended expansion.Concrete changes:
env:field to assignCOMMENT_BODY: ${{ github.event.comment.body }}.echo '${{ github.event.comment.body }}'withecho "$COMMENT_BODY".