Skip to content

Commit b246fcf

Browse files
Modify optional workflows to be triggered by comments (#977)
* Modify optional workflows to be triggered by comments * Restore optional.yml * Restore optional.yml * GH613 Concentrate action in one with selector * GH613 Adding documentation to tests.md and workflow file * Fix typo in workflow file * PR feedback
1 parent d2798db commit b246fcf

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Comment Commands to Trigger CI
2+
on:
3+
issue_comment:
4+
types: created
5+
6+
permissions:
7+
checks: write
8+
9+
env:
10+
# store mapping of commands to use with poetry
11+
RUN_COMMAND: '{"/pandas_nightly": "pytest --nightly", "/pyright_strict": "pyright_strict", "/mypy_nightly": "mypy --mypy_nightly"}'
12+
# store mapping of labels to display in the check runs
13+
DISPLAY_COMMAND: '{"/pandas_nightly": "Pandas nightly tests", "/pyright_strict": "Pyright strict tests", "/mypy_nightly": "Mypy nightly tests"}'
14+
15+
jobs:
16+
optional_tests:
17+
name: "Optional tests run"
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 10
20+
# if more commands are added, they will need to be added here too as we don't have access to env at this stage
21+
if: (github.event.issue.pull_request) && contains(fromJSON('["/pandas_nightly", "/pyright_strict", "/mypy_nightly"]'), github.event.comment.body)
22+
23+
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
38+
# get the sha of the last commit to attach the results of the tests
39+
if: always()
40+
id: get-sha
41+
uses: actions/github-script@v7
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
const pr = await github.rest.pulls.get({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
pull_number: ${{ github.event.issue.number }}
49+
})
50+
core.setOutput('sha', pr.data.head.sha)
51+
52+
- name: Report results of the tests and publish
53+
# publish the results to a check run no matter the pass or fail
54+
if: always()
55+
uses: actions/github-script@v7
56+
with:
57+
github-token: ${{ secrets.GITHUB_TOKEN }}
58+
script: |
59+
github.rest.checks.create({
60+
name: '${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}',
61+
head_sha: '${{ steps.get-sha.outputs.sha }}',
62+
status: 'completed',
63+
conclusion: '${{ steps.tests-step.outcome }}',
64+
output: {
65+
title: 'Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}',
66+
summary: 'Results: ${{ steps.tests-step.outcome }}',
67+
text: 'See the actions run at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
68+
},
69+
owner: context.repo.owner,
70+
repo: context.repo.repo
71+
})

docs/tests.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Here are the most important options. Fore more details, please use `poe --help`.
66

77
- Run all tests (against both source and installed stubs): `poe test_all`
8-
- Run tests against the source code: `poe test`
8+
- Run tests against the source code: `poe test`
99
- Run only mypy: `poe mypy`
1010
- Run only pyright: `poe pyright`
1111
- Run only pytest: `poe pytest`
@@ -20,3 +20,9 @@ The following tests are **optional**. Some of them are run by the CI but it is o
2020
- Use mypy nightly to validate the annotations: `poe mypy --mypy_nightly`
2121
- Use pyright in full strict mode: `poe pyright_strict`
2222
- Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`
23+
24+
Among the tests above, the following can be run directly during a PR by commenting in the discussion.
25+
26+
- Run pytest against pandas nightly by commenting `/pandas_nightly`
27+
- Use mypy nightly to validate the annotations by commenting `/mypy_nightly`
28+
- Use pyright in full strict mode by commenting `/pyright_strict`

0 commit comments

Comments
 (0)