1
+ # This workflow will install Python dependencies, run tests and lint with a single version of Python
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3
+
4
+ name : Python application
5
+
6
+ on :
7
+ push :
8
+ pull_request :
9
+ branches : [ "main" ]
10
+ schedule :
11
+ - cron : ' 0 2 * * 3'
12
+
13
+ permissions :
14
+ contents : read
15
+
16
+
17
+ jobs :
18
+ format :
19
+ runs-on : ubuntu-latest
20
+ steps :
21
+ - uses : actions/checkout@v4
22
+ - uses : psf/black@stable
23
+ lint :
24
+ name : Lint with ruff
25
+ runs-on : ubuntu-latest
26
+ steps :
27
+ - uses : actions/checkout@v4
28
+
29
+ - uses : actions/setup-python@v5
30
+ with :
31
+ python-version : " 3.11"
32
+ - name : Install ruff
33
+ run : |
34
+ pip install ruff
35
+ - name : Lint with ruff
36
+ run : |
37
+ # stop the build if there are Python syntax errors or undefined names
38
+ ruff check .
39
+ test :
40
+ name : Test
41
+ runs-on : ubuntu-latest
42
+ strategy :
43
+ matrix :
44
+ python-version : ["3.11", "3.12"]
45
+ steps :
46
+ - uses : actions/checkout@v4
47
+ - name : Set up Python ${{ matrix.python-version }}
48
+ uses : actions/setup-python@v5
49
+ with :
50
+ python-version : ${{ matrix.python-version }}
51
+ cache : ' pip' # caching pip dependencies
52
+ cache-dependency-path : ' **/pyproject.toml'
53
+ - name : Install dependencies
54
+ run : |
55
+ python -m pip install --upgrade pip
56
+ pip install pytest
57
+ pip install -e .
58
+ - name : Run tests
59
+ run : python -m pytest tests
60
+
61
+ build_source_dist :
62
+ name : Build source distribution
63
+ if : startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags')
64
+ runs-on : ubuntu-latest
65
+ steps :
66
+ - uses : actions/checkout@v4
67
+
68
+ - uses : actions/setup-python@v5
69
+ with :
70
+ python-version : " 3.10"
71
+
72
+ - name : Install build
73
+ run : python -m pip install build
74
+
75
+ - name : Run build
76
+ run : python -m build --sdist
77
+
78
+ - uses : actions/upload-artifact@v4
79
+ with :
80
+ path : ./dist/*.tar.gz
81
+ # Needed in case of building packages with external binaries (e.g. Cython, RUst-extensions, etc.)
82
+ # build_wheels:
83
+ # name: Build wheels on ${{ matrix.os }}
84
+ # if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags')
85
+ # runs-on: ${{ matrix.os }}
86
+ # strategy:
87
+ # matrix:
88
+ # os: [ubuntu-20.04, windows-2019, macOS-10.15]
89
+
90
+ # steps:
91
+ # - uses: actions/checkout@v4
92
+
93
+ # - uses: actions/setup-python@v5
94
+ # with:
95
+ # python-version: "3.10"
96
+
97
+ # - name: Install cibuildwheel
98
+ # run: python -m pip install cibuildwheel==2.3.1
99
+
100
+ # - name: Build wheels
101
+ # run: python -m cibuildwheel --output-dir wheels
102
+
103
+ # - uses: actions/upload-artifact@v4
104
+ # with:
105
+ # path: ./wheels/*.whl
106
+
107
+ publish :
108
+ name : Publish package
109
+ if : startsWith(github.ref, 'refs/tags')
110
+ needs :
111
+ - format
112
+ - lint
113
+ - test
114
+ - build_source_dist
115
+ # - build_wheels
116
+ runs-on : ubuntu-latest
117
+
118
+ steps :
119
+ - uses : actions/download-artifact@v4
120
+ with :
121
+ name : artifact
122
+ path : ./dist
123
+
124
+ - uses : pypa/gh-action-pypi-publish@release/v1
125
+ with :
126
+ # remove repository key to set the default to pypi (not test.pypi.org)
127
+ repository-url : https://test.pypi.org/legacy/
128
+ user : __token__
129
+ password : ${{ secrets.PYPI_API_TOKEN }}
0 commit comments