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