Repository navigation
181 lines (158 loc) · 5.84 KB
/
Copy pathpython-package.yml
File metadata and controls
181 lines (158 loc) · 5.84 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Python Package
# Builds the naja-schematic wheel/sdist (Python backend + the WASM viewer
# bundle), tests it against published najaeda, and on a `v<version>`
# tag publishes it to PyPI.
#
# Publishing uses PyPI trusted publishing (no token): the PyPI project must
# list this repository, this workflow file and the `pypi` environment as a
# trusted publisher.
#
# The `colab` job guards the README's Open-in-Colab badge (see below); the
# weekly run catches it breaking without a push here (a new najaeda or
# anywidget, naja's tutorial benchmarks moving).
on:
push:
branches: [ main ]
tags: [ "v*" ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
# imgui for the build, naja only for its version header
# (CMakeLists.txt reads NajaVersion.h.in); not recursive.
submodules: true
- name: Set up Emscripten
uses: mymindstorm/setup-emsdk@v14
with:
version: latest
- name: Build the viewer bundle
run: |
emcmake cmake -S . -B build-wasm-module \
-DCMAKE_BUILD_TYPE=Release \
-DNAJA_SCHEMATIC_WASM_MODULE=ON
cmake --build build-wasm-module -j
cp build-wasm-module/naja-schematic.js python/naja_schematic/static/
cp LICENSE python/LICENSE
- name: Check the tag matches the package version
if: startsWith(github.ref, 'refs/tags/v')
run: |
version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' python/naja_schematic/__init__.py)
test "v$version" = "${GITHUB_REF_NAME}" || {
echo "Tag ${GITHUB_REF_NAME} does not match __version__ $version"; exit 1; }
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build wheel and sdist
run: |
python -m pip install build
python -m build python --outdir dist
- name: Check the bundle is in both archives
run: |
unzip -l dist/*.whl | grep -q 'naja_schematic/static/naja-schematic.js'
tar tzf dist/*.tar.gz | grep -q 'naja_schematic/static/naja-schematic.js'
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
python-version: [ "3.10", "3.13" ]
# Oldest najaeda the package declares support for, and the newest.
najaeda: [ "==0.7.29", "" ]
steps:
- name: Checkout code
uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install the built wheel
shell: bash
run: |
python -m pip install "$(ls dist/*.whl)[test]" "najaeda${{ matrix.najaeda }}"
- name: Run tests against the installed package
# From outside python/, so the tests import the installed wheel
# rather than the source tree.
working-directory: ${{ runner.temp }}
run: python -m pytest -v ${{ github.workspace }}/python/tests
- name: Smoke-test the CLI
shell: bash
run: |
echo '{"request":"load_root"}' \
| naja-schematic --xilinx --verilog python/tests/data/design.v --stdio \
| grep -q '"root_response"'
publish:
needs: [ build, test ]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
colab:
# What the Open-in-Colab badge gives a user: the notebook on this branch,
# run as Colab runs it -- nothing preinstalled, its own
# `%pip install -U naja-schematic` fetching the release from PyPI. On a
# tag it runs after publishing and must get the version just released;
# otherwise it uses the current release, so a notebook edit that needs
# an unreleased API fails here rather than in Colab.
needs: publish
if: >-
!cancelled() && (needs.publish.result == 'success' ||
(needs.publish.result == 'skipped' && !startsWith(github.ref, 'refs/tags/v')))
runs-on: ubuntu-latest
env:
PIP_NO_CACHE_DIR: "1"
steps:
- name: Checkout code
uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
# Colab's runtime Python.
python-version: "3.12"
- name: Install the notebook runner only
run: python -m pip install pytest nbformat nbclient ipykernel
- name: Pick the release to expect
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
version=${GITHUB_REF_NAME#v}
# A fresh upload takes a moment to show up on the index.
for i in $(seq 30); do
pip download -q --no-deps -d "$RUNNER_TEMP/dl" \
"naja-schematic==$version" && break
[ "$i" = 30 ] && { echo "naja-schematic $version not on PyPI"; exit 1; }
sleep 20
done
else
version=latest
fi
echo "NAJA_SCHEMATIC_COLAB_CHECK=$version" >> "$GITHUB_ENV"
- name: Run the Colab notebook against PyPI
# From outside python/ and without conftest.py (which imports
# najaeda): the notebook installs everything itself.
working-directory: ${{ runner.temp }}
run: >-
python -m pytest -v --noconftest
${{ github.workspace }}/python/tests/test_notebook.py