|
| 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 | + }) |
0 commit comments