Skip to content

Commit 366bcce

Browse files
committed
Refactor main pipeline
1 parent 730a8f0 commit 366bcce

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

.github/workflows/main.yml

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,111 @@
1-
name: Testing pipeline
1+
name: Typecheck & run tests
22

33
on:
44
push:
55
branches:
66
- 'main'
77
- 'feature/*'
88
- 'bugfix/*'
9+
issue_comment:
10+
types: [created]
911

1012
jobs:
11-
sanity-run:
13+
get-main-ref:
1214
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]
1457
steps:
1558
- name: Checkout current branch
1659
uses: actions/checkout@v4
1760
with:
18-
ref: ${{ github.ref_name }}
61+
ref: ${{ needs.get-main-ref.outputs.branch }}
1962
- uses: actions/setup-python@v5
2063
with:
2164
python-version: '3.9'
2265
- run: python -m pip install --upgrade setuptools virtualenv
2366
- run: pip install -r requirements-dev.txt
2467
- run: pytest --cov=hooks --cov-fail-under=100
2568

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')) }}
2771
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]
3074
steps:
3175
- name: Checkout current branch
3276
uses: actions/checkout@v4
3377
with:
34-
ref: ${{ github.ref_name }}
78+
ref: ${{ needs.get-main-ref.outputs.branch }}
3579
- uses: actions/setup-python@v5
3680
with:
37-
python-version: '3.12'
81+
python-version: '3.9'
3882
- run: python -m pip install --upgrade setuptools virtualenv
3983
- run: pip install -r requirements-dev.txt
4084
- 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
42102
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress
43103

44104
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')) }}
46106
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]
49109
strategy:
50110
matrix:
51111
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -61,7 +121,7 @@ jobs:
61121
- name: Checkout current branch
62122
uses: actions/checkout@v4
63123
with:
64-
ref: ${{ github.ref_name }}
124+
ref: ${{ needs.get-main-ref.outputs.branch }}
65125
- uses: actions/setup-python@v5
66126
with:
67127
python-version: ${{ matrix.env }}

0 commit comments

Comments
 (0)