-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (81 loc) · 3.3 KB
/
release.yml
File metadata and controls
96 lines (81 loc) · 3.3 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
name: Release on Merge
on:
pull_request:
types: [closed]
branches: [main]
jobs:
check-release-branch:
runs-on: ubuntu-latest
# This if clause ensures the job only runs when the PR is merged
# and the branch starts with release/
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
outputs:
valid_release: ${{ steps.validate.outputs.valid_release }}
version: ${{ steps.validate.outputs.version }}
steps:
- name: Validate release branch and extract version
id: validate
run: |
BRANCH="${{ github.event.pull_request.head.ref }}"
if [[ "$BRANCH" =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}"
echo "valid_release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Branch name valid for release: $BRANCH"
else
echo "valid_release=false" >> "$GITHUB_OUTPUT"
echo "version=" >> "$GITHUB_OUTPUT"
echo "Branch '$BRANCH' does not match release/X.Y.Z (semver) pattern. Skipping release."
fi
do-release:
needs: check-release-branch
if: needs.check-release-branch.outputs.valid_release == 'true'
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.check-release-branch.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check Version Consistency
id: version_check
run: |
BRANCH_VERSION="${{ env.VERSION }}"
# Safely extract __version__ from the file regardless of single or double quotes,
# e.g. __version__ = '1.0.0' or __version__ = "1.0.0"
CODE_VERSION=$(grep -Po "__version__\s*=\s*['\"]\K[^'\"]+" src/docbuild/__about__.py)
echo ":notice title=Branch version::$BRANCH_VERSION"
echo ":notice title=Code version::$CODE_VERSION"
if [ "$BRANCH_VERSION" != "$CODE_VERSION" ]; then
echo "::error file=src/docbuild/__about__.py::Release branch version ($BRANCH_VERSION) does not match code version ($CODE_VERSION) in __about__.py."
echo "ERROR: Version mismatch detected! The release branch name must exactly match the __version__ in the code."
exit 1
fi
echo "Version check passed: $BRANCH_VERSION matches $CODE_VERSION."
- name: Setup uv
id: setup-uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
enable-cache: true
cache-suffix: "docbuild"
- name: Print the installed version
run: |
echo "uv version is ${{ steps.setup-uv.outputs.uv-version }}"
- name: Tag new release
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag "${{ env.VERSION }}"
git push origin "${{ env.VERSION }}"
- name: Build wheel
run: uv build --wheel
- name: Generate GitHub Release & Upload wheel
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.VERSION }}
generate_release_notes: true
files: dist/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}