-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (68 loc) · 2.4 KB
/
Copy pathtest.yml
File metadata and controls
79 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Unit Tests
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
check-permissions:
runs-on: ubuntu-latest
outputs:
can-run: ${{ steps.check.outputs.can-run }}
steps:
- name: Check if user can run tests
id: check
run: |
ASSOCIATION="${{ github.event.pull_request.author_association }}"
echo "PR author association: $ASSOCIATION"
# Check if PR author is owner, member, collaborator, or contributor
if [[ "$ASSOCIATION" == "OWNER" ]] || \
[[ "$ASSOCIATION" == "MEMBER" ]] || \
[[ "$ASSOCIATION" == "COLLABORATOR" ]] || \
[[ "$ASSOCIATION" == "CONTRIBUTOR" ]]; then
echo "can-run=true" >> $GITHUB_OUTPUT
echo "✅ User has permission to run tests"
else
echo "can-run=false" >> $GITHUB_OUTPUT
echo "❌ User does not have permission to run tests (association: $ASSOCIATION)"
fi
test:
needs: check-permissions
if: needs.check-permissions.outputs.can-run == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: |
poetry env use python${{ matrix.python-version }}
poetry install --with test,lint,typing
- name: Run unit tests
run: make test
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.python-version }}
path: |
.coverage
htmlcov/
retention-days: 7
test-status:
needs: check-permissions
if: needs.check-permissions.outputs.can-run == 'false'
runs-on: ubuntu-latest
steps:
- name: Tests skipped
run: |
echo "::warning::Tests were not run because the PR author (${{ github.event.pull_request.user.login }}) is not a repository owner, member, or collaborator."
echo "Repository owners can manually trigger tests by re-running this workflow."