Skip to content

Commit 3547cda

Browse files
GH1090 Fix comment commands not checking out the correct branch (#1094)
* GH1090 Fix comment commands not checking out the correct branch * GH1090 Add comment to the workflow file
1 parent 3f42941 commit 3547cda

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

.github/workflows/comment_commands.yml

+22-16
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,10 @@ jobs:
2121
if: (github.event.issue.pull_request) && contains(fromJSON('["/pandas_nightly", "/pyright_strict", "/mypy_nightly"]'), github.event.comment.body)
2222

2323
steps:
24-
- uses: actions/checkout@v4
25-
26-
- name: Install project dependencies
27-
uses: ./.github/setup
28-
with:
29-
os: ubuntu-latest
30-
python-version: "3.11"
31-
32-
- name: Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}
33-
# run the tests based on the value of the comment
34-
id: tests-step
35-
run: poetry run poe ${{ fromJSON(env.RUN_COMMAND)[github.event.comment.body] }}
36-
37-
- name: Get head sha and store value
24+
- name: Get head sha, branch name and store value
3825
# get the sha of the last commit to attach the results of the tests
3926
if: always()
40-
id: get-sha
27+
id: get-branch-info
4128
uses: actions/github-script@v7
4229
with:
4330
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -48,6 +35,25 @@ jobs:
4835
pull_number: ${{ github.event.issue.number }}
4936
})
5037
core.setOutput('sha', pr.data.head.sha)
38+
core.setOutput('branch', pr.data.head.ref)
39+
40+
- name: Checkout code on the correct branch
41+
uses: actions/checkout@v4
42+
with:
43+
# context is not aware which branch to checkout so it would otherwise
44+
# default to main
45+
ref: ${{ steps.get-branch-info.outputs.branch }}
46+
47+
- name: Install project dependencies
48+
uses: ./.github/setup
49+
with:
50+
os: ubuntu-latest
51+
python-version: "3.12"
52+
53+
- name: Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}
54+
# run the tests based on the value of the comment
55+
id: tests-step
56+
run: poetry run poe ${{ fromJSON(env.RUN_COMMAND)[github.event.comment.body] }}
5157

5258
- name: Report results of the tests and publish
5359
# publish the results to a check run no matter the pass or fail
@@ -58,7 +64,7 @@ jobs:
5864
script: |
5965
github.rest.checks.create({
6066
name: '${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}',
61-
head_sha: '${{ steps.get-sha.outputs.sha }}',
67+
head_sha: '${{ steps.get-branch-info.outputs.sha }}',
6268
status: 'completed',
6369
conclusion: '${{ steps.tests-step.outcome }}',
6470
output: {

0 commit comments

Comments
 (0)