-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (105 loc) · 3.97 KB
/
Copy pathpython-package.yml
File metadata and controls
107 lines (105 loc) · 3.97 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python multi version tests
run-name: >-
${{ github.event_name == 'schedule' && format('Schedule [{0}]', github.ref_name)
|| format('{0} [{1}]', github.event.head_commit.message || github.event.pull_request.title, github.ref_name) }}
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
schedule:
# Run every 05:00 AM
- cron: '0 5 * * *'
jobs:
pytest-version-check:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.decision.outputs.should_run }}
steps:
- uses: actions/checkout@v4
- name: Restore last version
id: cache-pytest
uses: actions/cache@v4
with:
path: last_pytest_version.txt
key: pytest-version-cache-${{ github.run_id }}
restore-keys: pytest-version-cache-
- name: Fetch Latest Pytest
id: pypi
run: |
LATEST=$(curl -s https://pypi.org/pypi/pytest/json | jq -r '.info.version')
echo "latest=$LATEST" >> $GITHUB_OUTPUT
[ -f last_pytest_version.txt ] && LAST=$(cat last_pytest_version.txt) || LAST="0.0.0"
echo "last=$LAST" >> $GITHUB_OUTPUT
- name: Determine if we should run
id: decision
run: |
if [[ "${{ github.event_name }}" != "schedule" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
elif [[ "${{ steps.pypi.outputs.latest }}" != "${{ steps.pypi.outputs.last }}" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
- name: Cancel if no update
if: steps.decision.outputs.should_run == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "No new pytest version. Cancelling and deleting run."
gh run delete ${{ github.run_id }}
test:
needs: pytest-version-check
if: needs.pytest-version-check.outputs.should_run == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
pytest-version: ['7.0.1', 'latest']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install testing dependencies
run: |
python -m pip install --upgrade pip
python -m pip install coverage deepdiff parameterized
- name: Install application dependencies
run: |
grep -v pytest requirements.txt > requirements_without_pytest.txt || true
if [ -s requirements_without_pytest.txt ]; then
pip install -r requirements_without_pytest.txt
fi
# Install pytest based on matrix pytest-version
if [[ '${{ matrix.pytest-version }}' == 'latest' ]]; then
pip install --upgrade pytest
else
pip install pytest==${{ matrix.pytest-version }}
fi
- name: Test with pytest
run: |
python tests_execution.py
- name: Update last pytest version
if: github.event_name == 'schedule' && success()
run: |
echo "${{ needs.pytest-version-check.outputs.latest }}" > last_pytest_version.txt
- name: Send lcov.info to coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage_report/lcov.info
parallel: true
finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Close Coveralls build
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true