-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (180 loc) · 5.76 KB
/
python-publish.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Upload Python Package
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- dev
push:
branches:
- dev
tags:
- 'v*.*.*'
env:
# Change this to invalidate existing cache.
CACHE_PREFIX: v0
PYTHON_PATH: ./
jobs:
checks:
name: Python ${{ matrix.python }} - ${{ matrix.task.name }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
python: ['3.10']
# task:
# - name: Test
# run: |
# pytest -v --color=yes tests/
include:
# - python: '3.10'
# task:
# name: Lint
# run: flake8 .
# - python: '3.10'
# task:
# name: Type check
# run: mypy .
- python: '3.10'
task:
name: Build
run: |
python setup.py check
python setup.py bdist_wheel sdist
# - python: '3.10'
# task:
# name: Style
# run: black --check .
# - python: '3.10'
# task:
# name: Docs
# run: cd docs && make html
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
- name: Install prerequisites
run: |
pip install --upgrade pip setuptools wheel virtualenv
- name: Set build variables
shell: bash
run: |
# Get the exact Python version to use in the cache key.
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV
echo "NODE_VERSION=$(node --version)" >> $GITHUB_ENV
# Use week number in cache key so we can refresh the cache weekly.
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV
- uses: actions/cache@v3
id: virtualenv-cache
with:
path: |
.venv
src/web/node_modules
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt') }}-${{ env.NODE_VERSION }}-${{ hashFiles('src/web/package-lock.json') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ env.NODE_VERSION }}
- name: Setup virtual environment (no cache hit)
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
run: |
test -d .venv || virtualenv -p $(which python) --copies --reset-app-data .venv
. .venv/bin/activate
pip install -e .[dev]
cd src/web
npm install
- name: Install editable (cache hit)
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
run: |
. .venv/bin/activate
pip install --no-deps -e .[dev]
- name: Show environment info
run: |
. .venv/bin/activate
which python
python --version
pip freeze
which node
node --version
- name: Build Web
run: |
cd src/web
npm run build
env:
CI: false
- name: ${{ matrix.task.name }}
run: |
. .venv/bin/activate
${{ matrix.task.run }}
- name: Upload package distribution files
if: matrix.task.name == 'Build'
uses: actions/upload-artifact@v2
with:
name: package
path: dist
- name: Clean up
if: always()
run: |
. .venv/bin/activate
pip uninstall -y my-package
release:
name: Release
runs-on: ubuntu-latest
needs: [checks]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v1
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install requirements
run: |
pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
- name: Prepare environment
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Download package distribution files
uses: actions/download-artifact@v2
with:
name: package
path: dist
- name: Generate release notes
run: |
python scripts/release_notes.py > ${{ github.workspace }}-RELEASE_NOTES.md
- name: Publish GitHub release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: ${{ github.workspace }}-RELEASE_NOTES.md
prerelease: ${{ contains(env.TAG, 'rc') }}
files: |
dist/*
- name: "Azure Log in"
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: "Publish package to PyPI"
run: |
pip install twine>=1.11.0
export TWINE_USERNAME=${{ secrets.PYPI_USERNAME }}
export TWINE_PASSWORD=$(az keyvault secret show --vault-name ${{ secrets.AZURE_KEYVAULE_USERNAME }} --name ${{ secrets.AZURE_PYPI_PASSWORD_NAME }} --query value -otsv)
export TWINE_REPOSITORY_URL=https://upload.pypi.org/legacy/
twine upload dist/*
- name: 'Azure Log out'
uses: azure/CLI@v1
with:
inlineScript: |
az logout
az cache purge
az account clear