forked from Draegerwerk/sdc11073
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (101 loc) · 3.85 KB
/
build.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Build package
on:
workflow_call:
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]
push:
branches:
- master
- v*
jobs:
build:
runs-on: ubuntu-latest
outputs:
WHL: ${{ steps.filenames.outputs.WHL }}
TARGZ: ${{ steps.filenames.outputs.TARGZ }}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Setup hatch
run: python -m pip install hatch
- name: Set new version
if: startsWith(github.ref, 'refs/tags/v')
run: |
python -m hatch version ${GITHUB_REF/refs\/tags\/v/}
- name: Build package
run: python -m hatch build
- name: Set filenames in output
id: filenames
run: |
echo WHL=$(echo dist/*.whl) >> $GITHUB_OUTPUT
echo TARGZ=$(echo dist/*.tar.gz) >> $GITHUB_OUTPUT
- name: Archive package
uses: actions/upload-artifact@v3
with:
name: distributions
path: dist
retention-days: 5
tests:
needs: build
strategy:
matrix:
python-version: [ "3.7", "3.8" , "3.9", "3.10", "3.11", "3.12" ]
os: [ ubuntu-latest, windows-latest ]
distribution: [ "${{ needs.build.outputs.WHL }}",
"${{ needs.build.outputs.TARGZ }}" ]
runs-on: ${{ matrix.os }}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: distributions
path: dist
- name: Install package and test dependencies
run: pip install ${{ matrix.distribution }}[test]
- name: Detect suffix on ubuntu
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
echo SUFFIX=$(python -c "import pathlib;p=pathlib.Path('${{ matrix.distribution }}');print('whl') if p.suffix=='.whl' else print('tar_gz')") >> $GITHUB_ENV
- name: Detect suffix on windows
if: ${{ matrix.os == 'windows-latest' }}
# https://github.com/actions/runner-images/issues/5251#issuecomment-1071030822
run: |
echo SUFFIX=$(python -c "import pathlib;p=pathlib.Path('${{ matrix.distribution }}');print('whl') if p.suffix=='.whl' else print('tar_gz')") | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Run pytest
run: >-
pytest
-n logical
--html=pytest_reports/unittest_report_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.html
--self-contained-html
--cov=$(python -c "import pathlib;import sdc11073;print(pathlib.Path(sdc11073.__file__).parent)")
--log-file pytest_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.log
- name: Archive test result
uses: actions/upload-artifact@v3
if: success() || failure() # upload artifacts also if test stage failed
with:
name: unittest_reports
path: pytest_reports/unittest_report_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.html
retention-days: 5
- name: Archive test log
uses: actions/upload-artifact@v3
if: success() || failure() # upload artifacts also if test stage failed
with:
name: pytest_logs
path: pytest_${{ matrix.os }}_py${{ matrix.python-version }}_${{ env.SUFFIX }}.log
retention-days: 5
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true