Skip to content

Split commands.yml into running and saving #18688

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

T-Gro
Copy link
Member

@T-Gro T-Gro commented Jun 12, 2025

This PR restructures the GH actions into two jobs.
First one runs and executes arbitrary code, and is by nature unsafe. It ends with creating a diff patch, and does not have any write permissions to anything.
The second job is not user extensible, and applies the diff to the source branch of the PR.

The following comments in a PR can be used as commands to execute scripts which automate repository maintenance and make it part of the visible diff.

  • /run fantomas runs dotnet fantomas .
  • /run ilverify updates IL verification baseline
  • /run xlf refreshes localisation files for translatable strings
  • /run test-baseline ... runs tests with the TEST_UPDATE_BSL: 1 environment variable and an argument supplied filter (passed to dotnet test --filter ..). Its goal is to refresh baselines.

@edgarfgp , @auduchinok : Are there other types of content changes that would also made use of a command, and would not be covered by the above?

TODO - add channel for variables about outcome between jobs
Copy link
Contributor

✅ No release notes required

@T-Gro T-Gro marked this pull request as ready for review June 16, 2025 08:29
@T-Gro T-Gro requested a review from a team as a code owner June 16, 2025 08:29
@T-Gro T-Gro requested review from abonie, edgarfgp and auduchinok June 16, 2025 08:41
@edgarfgp
Copy link
Contributor

@T-Gro would be possible to include Re-running the CI ?

@T-Gro
Copy link
Member Author

T-Gro commented Jun 16, 2025

Will have to figure out how to do it without a dummy commit (my current naive idea) and without risks with exposing the access token. Will check how this is done elsewhere.

@vzarytovskii
Copy link
Member

vzarytovskii commented Jun 16, 2025

Will have to figure out how to do it without a dummy commit (my current naive idea) and without risks with exposing the access token. Will check how this is done elsewhere.

/azp run will rerun the CI, or was it removed?

@T-Gro
Copy link
Member Author

T-Gro commented Jun 16, 2025

/azp run will rerun the CI, or was it removed?

AFAIK it never worked for OSS contributors, who also do not have the "rerun" buttons when seeing the Checks tab on a PR.
@edgarfgp : What happens when you try /azp run please?

@edgarfgp
Copy link
Contributor

/azp run

Copy link

Commenter does not have sufficient privileges for PR 18688 in repo dotnet/fsharp

@edgarfgp
Copy link
Contributor

@T-Gro i get Commenter does not have sufficient privileges for PR 18688 in repo dotnet/fsharp

@T-Gro T-Gro requested review from mmitche and vzarytovskii June 18, 2025 07:33
@vzarytovskii
Copy link
Member

/azp run will rerun the CI, or was it removed?

AFAIK it never worked for OSS contributors, who also do not have the "rerun" buttons when seeing the Checks tab on a PR.

@edgarfgp : What happens when you try /azp run please?

Correct, but what if it's person's own PR? I thought arcade folks fixed it - that you can rerun own PR.

@edgarfgp
Copy link
Contributor

/azp run will rerun the CI, or was it removed?

AFAIK it never worked for OSS contributors, who also do not have the "rerun" buttons when seeing the Checks tab on a PR.
@edgarfgp : What happens when you try /azp run please?

Correct, but what if it's person's own PR? I thought arcade folks fixed it - that you can rerun own PR.

Tried in my own PR and did not work. See #18670 (comment)

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
command: ${{ steps.parse.outputs.command }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Crucial to verify that this command is always from the known set.
And gets not set if it is something else ( = the comment-pipeline must fail on unknown input0

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
command: ${{ steps.parse.outputs.command }}
arg: ${{ steps.parse.outputs.arguments }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crucial to verify:
This must be used in a safe way, especially in the second job.

"/run fantomas") dotnet fantomas . ;;
"/run xlf") dotnet build src/Compiler /t:UpdateXlf ;;
"/run ilverify") pwsh tests/ILVerify/ilverify.ps1 ;;
"/run test-baseline") dotnet test ./FSharp.Compiler.Service.sln --filter "${{ steps.parse.outputs.arguments }}" -c Release || true ;;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

This runs user-provided snippet and can pass other arguments to dotnet test, even run other script. This is still in the context of read-only permissions.

git config user.name "GH Actions"
git config user.email "actions@github.com"
git add -u
git commit -m "Apply patch from ${{ needs.detect-and-run.outputs.command }}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important: The command must be from a known set, otherwise this is shell injection.
The command is coming from the comment pipeline, only valid command will go trough.

_CurrentWorkflowID="$(gh api -X GET "$_UrlPath" | jq '.workflows[] | select(.name == '\""$GITHUB_WORKFLOW"\"') | .id')"
- name: Parse comment
id: parse
uses: dotnet/comment-pipeline@1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a dotnet fork of the pipeline instead of the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

4 participants