Skip to content

Commit c0786f5

Browse files
committed
Refactor main pipeline
1 parent 891139c commit c0786f5

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

.github/workflows/main.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Testing pipeline
1+
name: Run tests
22

33
on:
44
push:
@@ -10,14 +10,33 @@ on:
1010
types: [created]
1111

1212
jobs:
13+
get-main-ref:
14+
runs-on: ubuntu-latest
15+
name: Get ref to check out (based on branch or PR)
16+
steps:
17+
- name: Get PR's branch name
18+
id: from-pr
19+
if: ${{ contains(github.event.comment.html_url, '/pull/') }}
20+
run: |
21+
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }})
22+
echo "branch=$(echo $PR | jq -r '.head.ref')"
23+
- name: Get current branch name
24+
id: from-branch
25+
if: ${{ !contains(github.event.comment.html_url, '/pull/') }}
26+
run: |
27+
echo "branch=${{ github.head_ref || github.ref_name }}"
28+
outputs:
29+
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }}
30+
1331
sanity-run:
1432
runs-on: ubuntu-latest
1533
name: Run tests on lowest supported Python version on Ubuntu as a sanity-check before doing anything else
34+
needs: get-main-ref
1635
steps:
1736
- name: Checkout current branch
1837
uses: actions/checkout@v4
1938
with:
20-
ref: ${{ github.head_ref || github.ref_name }}
39+
ref: ${{ needs.get-main-ref.outputs.branch }}
2140
- uses: actions/setup-python@v5
2241
with:
2342
python-version: '3.9'
@@ -29,12 +48,12 @@ jobs:
2948
if: ${{ (github.ref == 'refs/heads/main') || (contains(github.event.comment.html_url, '/pull/') && (contains(github.event.comment.body, '/full-build') || contains(github.event.comment.body, '/mutate'))) }}
3049
runs-on: ubuntu-latest
3150
name: Run all tests, run static type analysis, coverage, and mutation tests
32-
needs: sanity-run
51+
needs: [get-main-ref, sanity-run]
3352
steps:
3453
- name: Checkout current branch
3554
uses: actions/checkout@v4
3655
with:
37-
ref: ${{ github.head_ref || github.ref_name }}
56+
ref: ${{ needs.get-main-ref.outputs.branch }}
3857
- uses: actions/setup-python@v5
3958
with:
4059
python-version: '3.12'
@@ -48,7 +67,7 @@ jobs:
4867
if: ${{ (github.ref == 'refs/heads/main') || (contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/full-build')) }}
4968
runs-on: ${{ matrix.os }}
5069
name: ${{ matrix.os }} / ${{ matrix.env }}
51-
needs: main
70+
needs: [get-main-ref, main]
5271
strategy:
5372
matrix:
5473
os: [windows-latest, ubuntu-latest, macos-latest]
@@ -64,7 +83,7 @@ jobs:
6483
- name: Checkout current branch
6584
uses: actions/checkout@v4
6685
with:
67-
ref: ${{ github.head_ref || github.ref_name }}
86+
ref: ${{ needs.get-main-ref.outputs.branch }}
6887
- uses: actions/setup-python@v5
6988
with:
7089
python-version: ${{ matrix.env }}

0 commit comments

Comments
 (0)