-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (144 loc) · 4.81 KB
/
python-package.yml
File metadata and controls
165 lines (144 loc) · 4.81 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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 package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [ "created" ]
jobs:
build:
name: Lint code and build wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 build
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Build wheel
run: |
unzip tsnorm/dictionary/dictionary.zip -d tsnorm/dictionary
python -m build --wheel
- name: Upload wheel to artifacts
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/*.whl
test:
needs: build
runs-on: ubuntu-latest
name: Test on Python ${{ matrix.python_version }}
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Remove source code
run: rm -rf tsnorm
- name: Download wheel
uses: actions/download-artifact@v4.1.7
with:
name: wheel
- name: Install wheel and dependencies
run: |
python -m pip install --upgrade pip
python -m pip install *.whl
python -m pip install pytest
- name: Run tests
run: pytest
deploy-check:
needs: test
runs-on: ubuntu-latest
name: Check package version and tag
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- run: echo ${{ github.event_name }} ${{ github.event.action }} ${{ github.event.release.tag_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Download wheel
uses: actions/download-artifact@v4.1.7
with:
name: wheel
- name: Install wheel
run: pip install *.whl
- name: Check package version
run: python -c "import tsnorm as ts; v = ts.__version__; print(v); assert v == '${{ github.event.release.tag_name }}'"
deploy-github:
needs: deploy-check
runs-on: ubuntu-latest
name: Deploy wheel to Releases
if: github.event_name == 'release' && github.event.action == 'created'
permissions: write-all
steps:
- run: echo ${{ github.event_name }} ${{ github.event.action }}
- name: Download wheel
uses: actions/download-artifact@v4.1.7
with:
name: wheel
- name: Save wheel filename
run: echo WHEEL_FILENAME=$(ls -1 *.whl | head -1) | sed "s/\.whl//" >> $GITHUB_ENV
- name: Check saved wheel filename
run: echo ${{ env.WHEEL_FILENAME }}
- name: Remove wheel file extension
run: mv $(ls -1 *.whl | head -1) ${{ env.WHEEL_FILENAME }}
- name: Add asset
uses: PeerXu/upload-asset@v1
with:
file: ${{ env.WHEEL_FILENAME }}
with_tag: false
with_sha1: true
suffix: .whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-test:
needs: deploy-check
runs-on: ubuntu-latest
name: Deploy wheel to test PyPI
if: github.event_name == 'release' && github.event.action == 'created' && github.event.release.prerelease
steps:
- name: Download wheel
uses: actions/download-artifact@v4.1.7
with:
name: wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
packages_dir: ./
publish-prod:
needs: deploy-check
runs-on: ubuntu-latest
name: Deploy wheel to PyPI
if: github.event_name == 'release' && github.event.action == 'created' && !github.event.release.prerelease
steps:
- name: Download wheel
uses: actions/download-artifact@v4.1.7
with:
name: wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
packages_dir: ./