-
Notifications
You must be signed in to change notification settings - Fork 6
125 lines (99 loc) · 3.25 KB
/
deploy.yml
File metadata and controls
125 lines (99 loc) · 3.25 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
name: Build and Deploy to PyPI
on:
push:
tags:
- 'v*.*.*'
jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Extract current tag
id: extract-tag
run: |
TAG_REF="${GITHUB_REF#refs/tags/}"
echo "tag=$TAG_REF" >> $GITHUB_OUTPUT
- name: Validate tag matches pyproject.toml version
run: |
TAG=${{ steps.extract-tag.outputs.tag }}
TAG_VERSION="${TAG#v}" # Strip the leading 'v'
FILE_VERSION=$(sed -nE 's/^version *= *"(.*)"/\1/p' pyproject.toml | xargs)
echo "Tag version: $TAG_VERSION"
echo "File version: $FILE_VERSION"
if [ "$TAG_VERSION" != "$FILE_VERSION" ]; then
echo "Version mismatch: Tag is $TAG_VERSION but pyproject.toml has $FILE_VERSION"
exit 1
fi
- name: Validate tag format
run: |
TAG=${{ steps.extract-tag.outputs.tag }}
if ! [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([ab][0-9]+)?$ ]]; then
echo "Invalid tag format. Expected vX.Y.Z or vX.Y.Z[a|b]N"
exit 1
fi
- name: Fetch all tags
run: |
git fetch --prune --unshallow || echo "Already unshallowed or failed, continuing"
git fetch --tags --quiet || echo "Failed to fetch tags, continuing"
- name: Ensure tag is newer than latest (unless pre-release)
run: |
CURRENT="${{ steps.extract-tag.outputs.tag }}"
LATEST=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+([ab][0-9]+)?$' | head -n 1)
echo "Current tag: $CURRENT"
echo "Latest tag: $LATEST"
python .github/scripts/validate_tag.py "$CURRENT" "$LATEST"
build:
needs: validate-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test-pypi:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Download built package
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Upload to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
pypi:
needs: test-pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Download built package
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}