-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (81 loc) · 2.54 KB
/
python-publish.yml
File metadata and controls
94 lines (81 loc) · 2.54 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
name: Build and publish to PyPI
on:
release:
types: [published]
workflow_dispatch:
jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
- name: Install build tools
run: python -m pip install --upgrade pip build twine
- name: Install project dependencies
run: python -m pip install .
- name: Read package version
id: version
run: |
python - <<'PY'
import os
import pathlib
import tomllib
version = tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"][
"version"
]
print(version)
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
f.write(f"version={version}\n")
PY
- name: Validate release tag matches version
if: github.event_name == 'release'
env:
TAG_NAME: ${{ github.event.release.tag_name }}
run: |
python - <<'PY'
import os
tag = os.environ["TAG_NAME"]
if tag.startswith("v"):
tag = tag[1:]
# `steps.version.outputs.version` is available via GHA expressions only, so re-read here.
import pathlib, tomllib
version = tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"]
if tag != version:
raise SystemExit(f"Release tag ({tag}) does not match pyproject.toml version ({version})")
print("Tag matches version:", tag)
PY
- name: Build sdist and wheel
run: python -m build --sdist --wheel --outdir dist/
- name: Python compile check
run: python -m py_compile seqchromloader/*.py tests/*.py
- name: Twine check
run: python -m twine check --strict dist/*
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release'
environment:
name: pypi
url: https://pypi.org/project/seqchromloader/
permissions:
id-token: write
contents: read
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/