|
1 |
| -name: Testing pipeline |
| 1 | +name: Typecheck & run tests |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | branches:
|
6 | 6 | - 'main'
|
7 | 7 | - 'feature/*'
|
8 | 8 | - 'bugfix/*'
|
| 9 | + issue_comment: |
| 10 | + types: [created] |
9 | 11 |
|
10 | 12 | jobs:
|
11 |
| - sanity-run: |
| 13 | + get-command: |
12 | 14 | runs-on: ubuntu-latest
|
13 |
| - name: Run tests on lowest supported Python version on Ubuntu as a sanity-check before doing anything else |
| 15 | + name: Get ref to check out (based on branch or PR) |
| 16 | + permissions: |
| 17 | + statuses: write |
| 18 | + steps: |
| 19 | + - name: Are we triggered by a known comment-command? |
| 20 | + id: get-command |
| 21 | + run: | |
| 22 | + doTypeCheck=${{ contains(github.event.comment.body, '/type-check') }} |
| 23 | + echo "doTypeCheck=$doTypeCheck" >> "$GITHUB_OUTPUT" |
| 24 | + doMutate=${{ contains(github.event.comment.body, '/mutate') }} |
| 25 | + echo "doMutate=$doMutate" >> "$GITHUB_OUTPUT" |
| 26 | + doCombos=${{ contains(github.event.comment.body, '/combos') }} |
| 27 | + echo "doCombos=$doCombos" >> "$GITHUB_OUTPUT" |
| 28 | + doAll=${{ contains(github.event.comment.body, '/all-tests') }} |
| 29 | + echo "doAll=$doAll" >> "$GITHUB_OUTPUT" |
| 30 | + commentCommand=false |
| 31 | + if [ "$doTypeCheck" = "true" ]; then |
| 32 | + commentCommand=true |
| 33 | + command="type-check" |
| 34 | + elif [ "$doMutate" = "true" ]; then |
| 35 | + commentCommand=true |
| 36 | + command="mutate" |
| 37 | + elif [ "$doCombos" = "true" ]; then |
| 38 | + commentCommand=true |
| 39 | + command="combos" |
| 40 | + elif [ "$doAll" = "true" ]; then |
| 41 | + commentCommand=true |
| 42 | + command="all" |
| 43 | + fi |
| 44 | + echo "commentCommand=$commentCommand" >> "$GITHUB_OUTPUT" |
| 45 | + echo "command=$command" >> "$GITHUB_OUTPUT" |
| 46 | + - name: Get PR's branch name |
| 47 | + id: from-pr |
| 48 | + if: ${{ steps.get-command.outputs.commentCommand == 'true' }} |
| 49 | + run: | |
| 50 | + PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }}) |
| 51 | + echo "onPR=true" >> "$GITHUB_OUTPUT" |
| 52 | + echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT" |
| 53 | + echo "sha=$(echo $PR | jq -r '.head.sha')" >> "$GITHUB_OUTPUT" |
| 54 | + - name: Bind check in PR |
| 55 | + id: bind-pr |
| 56 | + if: ${{ steps.get-command.outputs.commentCommand == 'true' }} |
| 57 | + uses: myrotvorets/[email protected] |
| 58 | + with: |
| 59 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + sha: ${{ steps.from-pr.outputs.sha }} |
| 61 | + status: pending |
| 62 | + context: Run based on PR comment (${{ steps.get-command.outputs.command }}) |
| 63 | + - name: Get current branch name |
| 64 | + id: from-branch |
| 65 | + if: ${{ steps.get-command.outputs.commentCommand != 'true' }} |
| 66 | + run: | |
| 67 | + echo "onPR=false" >> "$GITHUB_OUTPUT" |
| 68 | + echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT" |
| 69 | + echo "sha=..." >> "$GITHUB_OUTPUT" |
| 70 | + outputs: |
| 71 | + commentCommand: ${{ steps.get-command.outputs.commentCommand }} |
| 72 | + command: ${{ steps.get-command.outputs.command }} |
| 73 | + doTypeCheck: ${{ steps.get-command.outputs.doTypeCheck }} |
| 74 | + doMutate: ${{ steps.get-command.outputs.doMutate }} |
| 75 | + doCombos: ${{ steps.get-command.outputs.doCombos }} |
| 76 | + doAll: ${{ steps.get-command.outputs.doAll }} |
| 77 | + onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }} |
| 78 | + branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }} |
| 79 | + sha: ${{ steps.from-pr.outputs.sha || steps.from-branch.outputs.sha }} |
| 80 | + |
| 81 | + coverage: |
| 82 | + runs-on: ubuntu-latest |
| 83 | + name: Check coverage |
| 84 | + needs: [get-command] |
14 | 85 | steps:
|
15 | 86 | - name: Checkout current branch
|
16 | 87 | uses: actions/checkout@v4
|
17 | 88 | with:
|
18 |
| - ref: ${{ github.ref_name }} |
| 89 | + ref: ${{ needs.get-command.outputs.branch }} |
19 | 90 | - uses: actions/setup-python@v5
|
20 | 91 | with:
|
21 | 92 | python-version: '3.9'
|
22 | 93 | - run: python -m pip install --upgrade setuptools virtualenv
|
23 | 94 | - run: pip install -r requirements-dev.txt
|
24 | 95 | - run: pytest --cov=hooks --cov-fail-under=100
|
25 | 96 |
|
26 |
| - main: |
| 97 | + type-check: |
| 98 | + if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doTypeCheck == 'true' || needs.get-command.outputs.doAll == 'true' }} |
27 | 99 | runs-on: ubuntu-latest
|
28 |
| - name: Run all tests, run static type analysis, coverage, and mutation tests |
29 |
| - needs: sanity-run |
| 100 | + name: Type checking |
| 101 | + needs: [get-command] |
30 | 102 | steps:
|
31 | 103 | - name: Checkout current branch
|
32 | 104 | uses: actions/checkout@v4
|
33 | 105 | with:
|
34 |
| - ref: ${{ github.ref_name }} |
| 106 | + ref: ${{ needs.get-command.outputs.branch }} |
35 | 107 | - uses: actions/setup-python@v5
|
36 | 108 | with:
|
37 |
| - python-version: '3.12' |
| 109 | + python-version: '3.9' |
38 | 110 | - run: python -m pip install --upgrade setuptools virtualenv
|
39 | 111 | - run: pip install -r requirements-dev.txt
|
40 | 112 | - run: mypy hooks
|
41 |
| - - run: pytest --cov=hooks --cov-fail-under=100 |
| 113 | + |
| 114 | + mutate: |
| 115 | + if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doMutate == 'true' || needs.get-command.outputs.doAll == 'true' }} |
| 116 | + runs-on: ubuntu-latest |
| 117 | + name: Mutation tests |
| 118 | + needs: [get-command, coverage] |
| 119 | + steps: |
| 120 | + - name: Checkout current branch |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + ref: ${{ needs.get-command.outputs.branch }} |
| 124 | + - uses: actions/setup-python@v5 |
| 125 | + with: |
| 126 | + python-version: '3.12' |
| 127 | + - run: python -m pip install --upgrade setuptools virtualenv |
| 128 | + - run: pip install -r requirements-dev.txt |
| 129 | + - run: pytest --cov=hooks |
42 | 130 | - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
|
43 | 131 |
|
44 | 132 | combos:
|
45 |
| - if: github.ref == 'refs/heads/main' |
| 133 | + if: ${{ (needs.get-command.outputs.onPR != 'true' && github.ref == 'refs/heads/main') || needs.get-command.outputs.doCombos == 'true' || needs.get-command.outputs.doAll == 'true' }} |
46 | 134 | runs-on: ${{ matrix.os }}
|
47 |
| - name: ${{ matrix.os }} / ${{ matrix.env }} |
48 |
| - needs: main |
| 135 | + name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }} |
| 136 | + needs: [get-command] |
49 | 137 | strategy:
|
50 | 138 | matrix:
|
51 | 139 | os: [windows-latest, ubuntu-latest, macos-latest]
|
52 | 140 | env: ['3.9', '3.10', '3.11', '3.12']
|
53 | 141 | exclude:
|
54 |
| - # exclude the sanity-run combo, no need to re-run it |
| 142 | + # exclude the coverage combo, no need to re-run it |
55 | 143 | - os: ubuntu-latest
|
56 | 144 | env: '3.9'
|
57 |
| - # exclude the main combo, no need to re-run it |
| 145 | + # exclude the mutate combo, no need to re-run it |
58 | 146 | - os: ubuntu-latest
|
59 | 147 | env: '3.12'
|
60 | 148 | steps:
|
61 | 149 | - name: Checkout current branch
|
62 | 150 | uses: actions/checkout@v4
|
63 | 151 | with:
|
64 |
| - ref: ${{ github.ref_name }} |
| 152 | + ref: ${{ needs.get-command.outputs.branch }} |
65 | 153 | - uses: actions/setup-python@v5
|
66 | 154 | with:
|
67 | 155 | python-version: ${{ matrix.env }}
|
68 | 156 | - run: python -m pip install --upgrade setuptools virtualenv
|
69 | 157 | - run: pip install -r requirements-dev.txt
|
70 | 158 | - run: pytest
|
| 159 | + |
| 160 | + update-pr: |
| 161 | + if: ${{ always() }} |
| 162 | + runs-on: ubuntu-latest |
| 163 | + name: Report back in PR when triggered by comment |
| 164 | + permissions: |
| 165 | + statuses: write |
| 166 | + needs: [get-command, type-check, mutate, combos] |
| 167 | + steps: |
| 168 | + - name: Set final commit status |
| 169 | + uses: myrotvorets/[email protected] |
| 170 | + if: ${{ needs.get-command.outputs.commentCommand == 'true' }} |
| 171 | + with: |
| 172 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + sha: ${{ needs.get-command.outputs.sha }} |
| 174 | + status: ${{ job.status }} |
| 175 | + context: Run based on PR comment (${{ needs.get-command.outputs.command }}) |
0 commit comments