|
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 | + # checks: write |
| 18 | + steps: |
| 19 | + - name: Get PR's branch name |
| 20 | + id: from-pr |
| 21 | + if: ${{ contains(github.event.comment.html_url, '/pull/') }} |
| 22 | + run: | |
| 23 | + PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }}) |
| 24 | + echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT" |
| 25 | + echo "onPR=true" >> "$GITHUB_OUTPUT" |
| 26 | + - name: Get current branch name |
| 27 | + id: from-branch |
| 28 | + if: ${{ !contains(github.event.comment.html_url, '/pull/') }} |
| 29 | + run: | |
| 30 | + echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT" |
| 31 | + echo "onPR=false" >> "$GITHUB_OUTPUT" |
| 32 | + outputs: |
| 33 | + branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }} |
| 34 | + onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }} |
| 35 | + |
| 36 | + # wip: |
| 37 | + # runs-on: ubuntu-latest |
| 38 | + # name: WIP |
| 39 | + # needs: [get-main-ref] |
| 40 | + # permissions: |
| 41 | + # checks: read |
| 42 | + # env: |
| 43 | + # GH_TOKEN: ${{ github.token }} |
| 44 | + # steps: |
| 45 | + # - name: print body |
| 46 | + # run: | |
| 47 | + # gh api \ |
| 48 | + # -H "Accept: application/vnd.github+json" \ |
| 49 | + # -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 50 | + # /repos/ShellMagick/commit-hooks/commits/${{ needs.get-main-ref.outputs.branch }}/check-suites > response.json |
| 51 | + # cat response.json |
| 52 | + |
| 53 | + coverage: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + name: Run tests on lowest supported Python version on Ubuntu |
| 56 | + needs: [get-main-ref] |
14 | 57 | steps:
|
15 | 58 | - name: Checkout current branch
|
16 | 59 | uses: actions/checkout@v4
|
17 | 60 | with:
|
18 |
| - ref: ${{ github.ref_name }} |
| 61 | + ref: ${{ needs.get-main-ref.outputs.branch }} |
19 | 62 | - uses: actions/setup-python@v5
|
20 | 63 | with:
|
21 | 64 | python-version: '3.9'
|
22 | 65 | - run: python -m pip install --upgrade setuptools virtualenv
|
23 | 66 | - run: pip install -r requirements-dev.txt
|
24 | 67 | - run: pytest --cov=hooks --cov-fail-under=100
|
25 | 68 |
|
26 |
| - main: |
| 69 | + type-check: |
| 70 | + if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }} |
27 | 71 | runs-on: ubuntu-latest
|
28 |
| - name: Run all tests, run static type analysis, coverage, and mutation tests |
29 |
| - needs: sanity-run |
| 72 | + name: Type checking |
| 73 | + needs: [get-main-ref] |
30 | 74 | steps:
|
31 | 75 | - name: Checkout current branch
|
32 | 76 | uses: actions/checkout@v4
|
33 | 77 | with:
|
34 |
| - ref: ${{ github.ref_name }} |
| 78 | + ref: ${{ needs.get-main-ref.outputs.branch }} |
35 | 79 | - uses: actions/setup-python@v5
|
36 | 80 | with:
|
37 |
| - python-version: '3.12' |
| 81 | + python-version: '3.9' |
38 | 82 | - run: python -m pip install --upgrade setuptools virtualenv
|
39 | 83 | - run: pip install -r requirements-dev.txt
|
40 | 84 | - run: mypy hooks
|
41 |
| - - run: pytest --cov=hooks --cov-fail-under=100 |
| 85 | + |
| 86 | + mutate: |
| 87 | + if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }} |
| 88 | + runs-on: ubuntu-latest |
| 89 | + name: Mutation tests |
| 90 | + needs: [get-main-ref, coverage] |
| 91 | + steps: |
| 92 | + - name: Checkout current branch |
| 93 | + uses: actions/checkout@v4 |
| 94 | + with: |
| 95 | + ref: ${{ needs.get-main-ref.outputs.branch }} |
| 96 | + - uses: actions/setup-python@v5 |
| 97 | + with: |
| 98 | + python-version: '3.12' |
| 99 | + - run: python -m pip install --upgrade setuptools virtualenv |
| 100 | + - run: pip install -r requirements-dev.txt |
| 101 | + - run: pytest --cov=hooks |
42 | 102 | - run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
|
43 | 103 |
|
44 | 104 | combos:
|
45 |
| - if: github.ref == 'refs/heads/main' |
| 105 | + if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }} |
46 | 106 | runs-on: ${{ matrix.os }}
|
47 |
| - name: ${{ matrix.os }} / ${{ matrix.env }} |
48 |
| - needs: main |
| 107 | + name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }} |
| 108 | + needs: [get-main-ref, coverage] |
49 | 109 | strategy:
|
50 | 110 | matrix:
|
51 | 111 | os: [windows-latest, ubuntu-latest, macos-latest]
|
|
61 | 121 | - name: Checkout current branch
|
62 | 122 | uses: actions/checkout@v4
|
63 | 123 | with:
|
64 |
| - ref: ${{ github.ref_name }} |
| 124 | + ref: ${{ needs.get-main-ref.outputs.branch }} |
65 | 125 | - uses: actions/setup-python@v5
|
66 | 126 | with:
|
67 | 127 | python-version: ${{ matrix.env }}
|
|
0 commit comments