Skip to content
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

Modify optional workflows to be triggered by comments #977

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/comment_commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Comment Commands to Trigger CI
on:
issue_comment:
types: created

permissions:
checks: write

env:
# store mapping of commands to use with poetry
RUN_COMMAND: '{"/pandas_nightly": "pytest --nightly", "/pyright_strict": "pyright_strict", "/mypy_nightly": "mypy --mypy_nightly"}'
# store mapping of labels to display in the check runs
DISPLAY_COMMAND: '{"/pandas_nightly": "Pandas nightly tests", "/pyright_strict": "Pyright strict tests", "/mypy_nightly": "Mypy nightly tests"}'

jobs:
optional_tests:
name: "Optional tests run"
runs-on: ubuntu-latest
timeout-minutes: 10
# if more commands are added, they will need to be added here too as we don't have access to env at this stage
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
# get the sha of the last commit to attach the results of the tests
if: always()
id: get-sha
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.issue.number }}
})
core.setOutput('sha', pr.data.head.sha)

- name: Report results of the tests and publish
# publish the results to a check run no matter the pass or fail
if: always()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.checks.create({
name: '${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}',
head_sha: '${{ steps.get-sha.outputs.sha }}',
status: 'completed',
conclusion: '${{ steps.tests-step.outcome }}',
output: {
title: 'Run ${{ fromJSON(env.DISPLAY_COMMAND)[github.event.comment.body] }}',
summary: 'Results: ${{ steps.tests-step.outcome }}',
text: 'See the actions run at ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
},
owner: context.repo.owner,
repo: context.repo.repo
})
8 changes: 7 additions & 1 deletion docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Here are the most important options. Fore more details, please use `poe --help`.

- Run all tests (against both source and installed stubs): `poe test_all`
- Run tests against the source code: `poe test`
- Run tests against the source code: `poe test`
- Run only mypy: `poe mypy`
- Run only pyright: `poe pyright`
- Run only pytest: `poe pytest`
Expand All @@ -20,3 +20,9 @@ The following tests are **optional**. Some of them are run by the CI but it is o
- Use mypy nightly to validate the annotations: `poe mypy --mypy_nightly`
- Use pyright in full strict mode: `poe pyright_strict`
- 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`

Among the tests above, the following can be run directly during a PR by commenting in the discussion.

- Run pytest against pandas nightly by commenting `/pandas_nightly`
- Use mypy nightly to validate the annotations by commenting `/mypy_nightly`
- Use pyright in full strict mode by commenting `/pyright_strict`
Loading