-
Notifications
You must be signed in to change notification settings - Fork 3.6k
106 lines (90 loc) · 3.83 KB
/
Copy pathrelease-publish.yml
File metadata and controls
106 lines (90 loc) · 3.83 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
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Builds and publishes the package to PyPI from a release/v* branch.
# Supports both main (v2+) stable releases and v1 pre-releases (with auto PEP 440 version mapping).
# Creates a merge-back PR to sync changes back to the base branch (main or v1).
name: "Release: Publish to PyPi"
on:
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Validate branch
run: |
if [[ ! "${GITHUB_REF_NAME}" =~ ^release/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Error: Must run from a release/v* branch (e.g., release/v0.3.0 or release/v1.35.0-alpha.1)"
exit 1
fi
- uses: actions/checkout@v6
- name: Determine Release Type and Extract Version
id: version
run: |
BRANCH_NAME="${GITHUB_REF_NAME}"
VERSION="${BRANCH_NAME#release/v}"
# Check if this version matches the one in the v1 manifest to determine if it's a v1 release
if [ -f .github/.release-please-manifest-v1.json ] && jq -e --arg v "$VERSION" '.["."] == $v' .github/.release-please-manifest-v1.json &>/dev/null; then
echo "is_v1=true" >> $GITHUB_OUTPUT
echo "base_branch=v1" >> $GITHUB_OUTPUT
SEMVER="$VERSION"
echo "semver=$SEMVER" >> $GITHUB_OUTPUT
echo "Semver version (v1): $SEMVER"
# PEP 440 Conversion (e.g., 2.0.0-alpha.1 -> 2.0.0a1)
PEP440=$(echo "$SEMVER" | sed -E 's/-alpha\./a/; s/-beta\./b/; s/-rc\./rc/')
echo "pep440=$PEP440" >> $GITHUB_OUTPUT
echo "PEP 440 version (v1): $PEP440"
else
echo "is_v1=false" >> $GITHUB_OUTPUT
echo "base_branch=main" >> $GITHUB_OUTPUT
echo "semver=$VERSION" >> $GITHUB_OUTPUT
echo "pep440=$VERSION" >> $GITHUB_OUTPUT
echo "Semver version (main): $VERSION"
fi
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Update version.py with PEP 440 version (v1 only)
if: steps.version.outputs.is_v1 == 'true'
env:
PEP440_VERSION: ${{ steps.version.outputs.pep440 }}
run: |
sed -i "s/^__version__ = .*/__version__ = \"${PEP440_VERSION}\"/" src/google/adk/version.py
echo "Updated version.py to ${PEP440_VERSION}"
grep __version__ src/google/adk/version.py
- name: Build package
run: uv build
- name: Publish to PyPI
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish
- name: Create merge-back PR
env:
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
SEMVER_VERSION: ${{ steps.version.outputs.semver }}
PEP440_VERSION: ${{ steps.version.outputs.pep440 }}
BASE_BRANCH: ${{ steps.version.outputs.base_branch }}
run: |
gh pr create \
--base "$BASE_BRANCH" \
--head "${GITHUB_REF_NAME}" \
--title "chore: merge release v${PEP440_VERSION} to $BASE_BRANCH" \
--body "Syncs version bump and CHANGELOG from release v${SEMVER_VERSION} to $BASE_BRANCH."