-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (100 loc) · 3.34 KB
/
Copy pathrelease.yml
File metadata and controls
112 lines (100 loc) · 3.34 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
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
target:
description: "Where to publish"
required: true
default: "testpypi"
type: choice
options:
- testpypi
- pypi
jobs:
build:
name: Build sdist + wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tooling
run: pip install build
- name: Build distribution
run: python -m build
- name: Verify version matches tag
if: github.event_name == 'release'
run: |
PKG_VERSION=$(python -c 'import tomllib, pathlib; print(tomllib.loads(pathlib.Path("pyproject.toml").read_text())["project"]["version"])')
TAG="${GITHUB_REF##*/}"
# Strip leading "v" from tag if present (v26.4.0 → 26.4.0).
TAG_VERSION="${TAG#v}"
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
echo "::error::Tag $TAG (version $TAG_VERSION) does not match pyproject.toml version $PKG_VERSION"
exit 1
fi
- name: Upload distribution as artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test:
name: Run unit tests before publishing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[dev]"
# Skip the E2E tests in the release workflow — they need groupdocs-viewer-net
# (~193MB wheel) and CI already covers them. The publish path is gated on
# the rest of the suite passing.
- run: pytest --ignore=tests/test_e2e.py
publish-testpypi:
name: Publish to TestPyPI
needs: [build, test]
if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi'
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/groupdocs-viewer-net-ui
steps:
- name: Download distribution
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# TestPyPI commonly retains versions across re-uploads — skip if the
# version is already there instead of failing the workflow.
skip-existing: true
publish-pypi:
name: Publish to PyPI
needs: [build, test]
# Folded scalar (`>`) collapses the line breaks into spaces; literal `|`
# preserves them and has historically tripped GitHub's expression parser.
if: >
github.event_name == 'release' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/groupdocs-viewer-net-ui
steps:
- name: Download distribution
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}