-
Notifications
You must be signed in to change notification settings - Fork 3
118 lines (101 loc) · 3.33 KB
/
publish.yml
File metadata and controls
118 lines (101 loc) · 3.33 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
name: Release
# Dynamic run name that appears in the GitHub UI
run-name: Release version ${{ github.ref_name }} of the SDK
on:
workflow_dispatch:
# ensures only a single instance of this release workflow is running at any one time
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: true
env:
PACKAGE_NAME: "msgspec-ext"
TEST_PYPI_URL: "https://test.pypi.org/pypi"
PYPI_URL: "https://pypi.org/pypi"
jobs:
get_tag_details:
name: Get Tag Details
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.release.outputs.tag_name }}
new_version: ${{ steps.release.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all history
- name: Check if a tag is selected
run: |
if [ "${{ github.ref_type }}" != "tag" ]; then
echo "Error: Workflow must be triggered with a tag selected. Current ref_type is ${{ github.ref_type }}."
exit 1
fi
TAG_NAME=${{ github.ref_name }}
echo "Selected tag is $TAG_NAME"
- name: Extract version from tag
id: release
run: |
TAG_NAME=${{ github.ref_name }}
# Validate tag format
if [[ ! $TAG_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+(a[0-9]+|b[0-9]+|rc[0-9]+)?$ ]]; then
echo "Invalid tag format. Tag must be in the format vX.Y.Z, vX.Y.ZaN, vX.Y.ZbN, or vX.Y.ZrcN."
exit 1
fi
NEW_VERSION=${TAG_NAME#v}
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "Tag name is $TAG_NAME"
echo "Version is $NEW_VERSION"
setup_build_and_publish:
name: Build Package and Publish to PyPI
needs: [get_tag_details]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for trusted publishing to PyPI
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@8f1d388b4b83ba56ec25d3787080bc053a2512e8 # v6
with:
version: "0.7.3"
- name: Install dependencies
run: uv sync --locked
- name: Build source and wheel distribution
run: |
uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v5
with:
name: dist
path: dist/*
if-no-files-found: error
- name: Publish to PyPI
run: uv publish
github_release:
name: Create GitHub Release
needs: [get_tag_details, setup_build_and_publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Create GitHub Release
id: create_release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{ needs.get_tag_details.outputs.tag_name }} dist/* --title ${{ needs.get_tag_details.outputs.tag_name }} --generate-notes