-
Notifications
You must be signed in to change notification settings - Fork 157
203 lines (179 loc) · 6.3 KB
/
build.yaml
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
name: Build
on:
push:
branches:
- main # allow to trigger the workflow with tag push event
pull_request:
paths:
- setup.py
- setup.cfg
- pyproject.toml
- MANIFEST.in
- nvitop/version.py
- Dockerfile
- .github/workflows/build.yaml
release:
types:
- published
# Allow to trigger the workflow manually
workflow_dispatch:
inputs:
task:
description: "Task type"
type: choice
options:
- build-only
- build-and-publish
required: true
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-20.04
if: github.repository == 'XuehaiPan/nvitop'
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- name: Set up Python
id: py
uses: actions/setup-python@v5
with:
python-version: "3.7 - 3.12"
update-environment: true
- name: Set up Python 3.7
id: py37
uses: actions/setup-python@v5
with:
python-version: "3.7"
update-environment: false
- name: Check syntax (Python 3.7)
run: |
"${{ steps.py37.outputs.python-path }}" -m compileall nvitop
- name: Upgrade build dependencies
run: python -m pip install --upgrade pip setuptools wheel build
- name: Quick test
run: |
python -m venv venv &&
(
source venv/bin/activate &&
python -m pip install --upgrade pip setuptools pre-commit pylint[spelling] mypy typing-extensions &&
python -m pip install -r requirements.txt &&
python -m pip install -r nvitop-exporter/requirements.txt &&
python -m pre_commit install --install-hooks &&
python -m pre_commit run --all-files &&
python -c 'import nvitop' &&
python -m nvitop --version &&
python -m nvitop --help &&
python -m nvitop.select --version &&
python -m nvitop.select --help &&
(
cd nvitop-exporter &&
python -c 'import nvitop_exporter' &&
python -m nvitop_exporter --version &&
python -m nvitop_exporter --help
)
)
- name: Test docker build
run: |
docker build --tag nvitop:latest .
docker run --rm nvitop:latest --help
- name: Set __release__
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
run: |
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop/version.py
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop-exporter/nvitop_exporter/version.py
- name: Print version
run: |
python setup.py --version
python nvitop-exporter/setup.py --version
- name: Build sdist and wheels
run: |
python -m build --outdir dist .
python -m build --outdir dist nvitop-exporter
- name: List built sdist and wheels
run: ls -lh dist/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifact
path: dist/*
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs: [build]
if: |
github.repository == 'XuehaiPan/nvitop' && github.event_name != 'pull_request' &&
(github.event_name != 'workflow_dispatch' || github.event.inputs.task == 'build-and-publish') &&
(github.event_name != 'push' || startsWith(github.ref, 'refs/tags/'))
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
if: startsWith(github.ref, 'refs/tags/')
with:
python-version: "3.7 - 3.12"
update-environment: true
- name: Upgrade pip
run: |
python -m pip install --upgrade pip setuptools
- name: Set __release__
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
run: |
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop/version.py
sed -i -E 's/^__release__\s*=.*$/__release__ = True/' nvitop-exporter/nvitop_exporter/version.py
- name: Print version
run: |
python setup.py --version
python nvitop-exporter/setup.py --version
- name: Check consistency between the package version and release tag
if: startsWith(github.ref, 'refs/tags/')
run: |
RELEASE_TAG="${GITHUB_REF#refs/*/}"
PACKAGE_VER="v$(python setup.py --version)"
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
exit 1
fi
PACKAGE_VER="v$(python nvitop-exporter/setup.py --version)"
if [[ "${PACKAGE_VER}" != "${RELEASE_TAG}" ]]; then
echo "package ver. (${PACKAGE_VER}) != release tag. (${RELEASE_TAG})"
exit 1
fi
- name: Download built sdist and wheels
uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- name: Publish to TestPyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_UPLOAD_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true
print-hash: true
skip-existing: true
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_UPLOAD_TOKEN }}
verbose: true
print-hash: true
skip-existing: true