Repository navigation
125 lines (108 loc) · 4.29 KB
/
Copy pathrelease.yml
File metadata and controls
125 lines (108 loc) · 4.29 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
name: Release
# Every push to main builds and validates the distributions, so a packaging
# mistake surfaces at merge time rather than at release time. Publishing to PyPI
# happens when a GitHub Release is published: PyPI versions are immutable and
# unique, so a release has to be tied to a version tag rather than to every merge.
on:
push:
branches: ["main"]
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: Build and check distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# setuptools_scm derives the version from the tags, it needs all of them
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build tooling
run: python -m pip install --upgrade build twine
- name: Build sdist and wheel
run: python -m build
- name: Check distribution metadata
run: python -m twine check dist/*
- name: Check the precomputed response norms are packaged
# they are loaded from inside the installed package, so a wheel without
# them silently falls back to simulating naturalistic stimuli responses
run: |
python - <<'PY'
import glob, sys, tarfile, zipfile
expected = "flyvis/data/responses_norm.h5"
wheel = glob.glob("dist/*.whl")[0]
sdist = glob.glob("dist/*.tar.gz")[0]
in_wheel = expected in zipfile.ZipFile(wheel).namelist()
in_sdist = any(
name.split("/", 1)[-1] == expected for name in tarfile.open(sdist).getnames()
)
print(f"{expected} in wheel: {in_wheel}, in sdist: {in_sdist}")
if not (in_wheel and in_sdist):
sys.exit(f"{expected} is missing from the distributions")
PY
- name: Check the version matches the release tag
if: github.event_name == 'release'
run: |
python - <<'PY'
import glob, os, sys
tag = os.environ["TAG"].lstrip("v")
built = glob.glob("dist/*.whl")[0].split("/")[-1].split("-")[1]
print(f"tag: {tag}, built version: {built}")
if built != tag:
sys.exit(
f"built version {built} does not match release tag {tag}; "
"the release must point at an annotated version tag"
)
PY
env:
TAG: ${{ github.event.release.tag_name }}
- name: Smoke test the wheel
run: |
python -m venv /tmp/smoke
/tmp/smoke/bin/pip install --upgrade pip
/tmp/smoke/bin/pip install dist/*.whl
/tmp/smoke/bin/python - <<'PY'
from flyvis.analysis import response_norms
norms = response_norms.read_response_norms(
response_norms.PRECOMPUTED_FILE, "flow/0000"
)
assert norms is not None, f"{response_norms.PRECOMPUTED_FILE} is not installed"
assert len(norms.model_names) == 50, norms
assert len(norms.checkpoint_hashes) == 50, norms
print("installed package ships constants for", norms)
PY
# `flyvis --help` prints the help and exits 1, because a bare invocation
# selects no command. Check what it prints rather than its status, which
# also verifies that the command registry survived packaging.
/tmp/smoke/bin/flyvis --help > /tmp/smoke-help.txt 2>&1 || true
grep -q "responses-norm" /tmp/smoke-help.txt
echo "installed console script lists the expected commands"
- uses: actions/upload-artifact@v4
with:
name: distributions
path: dist/
publish:
name: Publish to PyPI
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
# Configure this environment name in the PyPI trusted publisher, and add
# required reviewers here if releases should be approved by a human.
environment:
name: pypi
url: https://pypi.org/p/flyvis
permissions:
# required for trusted publishing, no API token needs to be stored
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: distributions
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1