From d79cfeac41274f48f6d32ec0691db2f3f927edba Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Sat, 11 Jan 2025 16:24:32 -0500 Subject: [PATCH 1/2] GH1090 Fix comment commands not checking out the correct branch --- .github/workflows/comment_commands.yml | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/comment_commands.yml b/.github/workflows/comment_commands.yml index c85cdca8e..fd8bad211 100644 --- a/.github/workflows/comment_commands.yml +++ b/.github/workflows/comment_commands.yml @@ -21,23 +21,10 @@ jobs: if: (github.event.issue.pull_request) && contains(fromJSON('["/pandas_nightly", "/pyright_strict", "/mypy_nightly"]'), github.event.comment.body) steps: - - uses: actions/checkout@v4 - - - name: Install project dependencies - uses: ./.github/setup - with: - os: ubuntu-latest - python-version: "3.11" - - - name: Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }} - # run the tests based on the value of the comment - id: tests-step - run: poetry run poe ${{ fromJSON(env.RUN_COMMAND)[github.event.comment.body] }} - - - name: Get head sha and store value + - name: Get head sha, branch name and store value # get the sha of the last commit to attach the results of the tests if: always() - id: get-sha + id: get-branch-info uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -48,6 +35,23 @@ jobs: pull_number: ${{ github.event.issue.number }} }) core.setOutput('sha', pr.data.head.sha) + core.setOutput('branch', pr.data.head.ref) + + - name: Checkout code on the correct branch + uses: actions/checkout@v4 + with: + ref: ${{ steps.get-branch-info.outputs.branch }} + + - name: Install project dependencies + uses: ./.github/setup + with: + os: ubuntu-latest + python-version: "3.11" + + - name: Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }} + # run the tests based on the value of the comment + id: tests-step + run: poetry run poe ${{ fromJSON(env.RUN_COMMAND)[github.event.comment.body] }} - name: Report results of the tests and publish # publish the results to a check run no matter the pass or fail @@ -58,7 +62,7 @@ jobs: script: | github.rest.checks.create({ name: '${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}', - head_sha: '${{ steps.get-sha.outputs.sha }}', + head_sha: '${{ steps.get-branch-info.outputs.sha }}', status: 'completed', conclusion: '${{ steps.tests-step.outcome }}', output: { From 09e002d625390b2ec6925a44838c4be4f073b463 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Sat, 11 Jan 2025 21:13:44 -0500 Subject: [PATCH 2/2] GH1090 Add comment to the workflow file --- .github/workflows/comment_commands.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/comment_commands.yml b/.github/workflows/comment_commands.yml index fd8bad211..328a27c62 100644 --- a/.github/workflows/comment_commands.yml +++ b/.github/workflows/comment_commands.yml @@ -40,13 +40,15 @@ jobs: - name: Checkout code on the correct branch uses: actions/checkout@v4 with: + # context is not aware which branch to checkout so it would otherwise + # default to main ref: ${{ steps.get-branch-info.outputs.branch }} - name: Install project dependencies uses: ./.github/setup with: os: ubuntu-latest - python-version: "3.11" + python-version: "3.12" - name: Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }} # run the tests based on the value of the comment