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