-
Notifications
You must be signed in to change notification settings - Fork 1k
228 lines (203 loc) · 8.28 KB
/
beta-release.yml
File metadata and controls
228 lines (203 loc) · 8.28 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: Beta Release (PyPI Pre-release)
concurrency:
group: beta-release
cancel-in-progress: true
on:
push:
branches:
- beta
paths:
- "Server/**"
- "MCPForUnity/**"
jobs:
update_unity_beta_version:
name: Update Unity package to beta version
runs-on: ubuntu-latest
# Avoid running when the workflow's own automation merges the PR
# created by this workflow (prevents a version-bump loop).
if: github.actor != 'github-actions[bot]'
permissions:
contents: write
pull-requests: write
outputs:
unity_beta_version: ${{ steps.version.outputs.unity_beta_version }}
version_updated: ${{ steps.commit.outputs.updated }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: beta
- name: Generate beta version for Unity package
id: version
shell: bash
run: |
set -euo pipefail
# Read current Unity package version
CURRENT_VERSION=$(jq -r '.version' MCPForUnity/package.json)
echo "Current Unity package version: $CURRENT_VERSION"
# Check if already a beta version - increment beta number
if [[ "$CURRENT_VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)-beta\.([0-9]+)$ ]]; then
BASE_VERSION="${BASH_REMATCH[1]}"
BETA_NUM="${BASH_REMATCH[2]}"
NEXT_BETA=$((BETA_NUM + 1))
BETA_VERSION="${BASE_VERSION}-beta.${NEXT_BETA}"
echo "Incrementing beta number: $CURRENT_VERSION -> $BETA_VERSION"
elif [[ "$CURRENT_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
# Stable version - bump patch and add -beta.1 suffix
# This ensures beta is "newer" than stable (9.3.2-beta.1 > 9.3.1)
# The release workflow decides final bump type (patch/minor/major)
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
NEXT_PATCH=$((PATCH + 1))
BETA_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-beta.1"
echo "Converting stable to beta: $CURRENT_VERSION -> $BETA_VERSION"
else
echo "Error: Could not parse version '$CURRENT_VERSION'" >&2
exit 1
fi
# Always output the computed version
echo "unity_beta_version=$BETA_VERSION" >> "$GITHUB_OUTPUT"
# Only skip update if computed version matches current (no change needed)
if [[ "$BETA_VERSION" == "$CURRENT_VERSION" ]]; then
echo "Version unchanged, skipping update"
echo "needs_update=false" >> "$GITHUB_OUTPUT"
else
echo "Version will be updated: $CURRENT_VERSION -> $BETA_VERSION"
echo "needs_update=true" >> "$GITHUB_OUTPUT"
fi
- name: Update Unity package.json with beta version
if: steps.version.outputs.needs_update == 'true'
env:
BETA_VERSION: ${{ steps.version.outputs.unity_beta_version }}
shell: bash
run: |
set -euo pipefail
# Update package.json version
jq --arg v "$BETA_VERSION" '.version = $v' MCPForUnity/package.json > tmp.json
mv tmp.json MCPForUnity/package.json
echo "Updated MCPForUnity/package.json:"
jq '.version' MCPForUnity/package.json
- name: Commit to temporary branch and create PR
id: commit
if: steps.version.outputs.needs_update == 'true'
env:
GH_TOKEN: ${{ github.token }}
BETA_VERSION: ${{ steps.version.outputs.unity_beta_version }}
shell: bash
run: |
set -euo pipefail
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
if git diff --quiet MCPForUnity/package.json; then
echo "No changes to commit"
echo "updated=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Create a temporary branch for the version update
BRANCH="beta-version-${BETA_VERSION}-${GITHUB_RUN_ID}"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
git checkout -b "$BRANCH"
git add MCPForUnity/package.json
git commit -m "chore: update Unity package to beta version ${BETA_VERSION}"
git push origin "$BRANCH"
# Check if PR already exists
if gh pr view "$BRANCH" >/dev/null 2>&1; then
echo "PR already exists for $BRANCH"
PR_NUMBER=$(gh pr view "$BRANCH" --json number -q '.number')
else
PR_URL=$(gh pr create \
--base beta \
--head "$BRANCH" \
--title "chore: update Unity package to beta version ${BETA_VERSION}" \
--body "Automated beta version bump for the Unity package.")
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
fi
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "updated=true" >> "$GITHUB_OUTPUT"
- name: Auto-merge version bump PR
if: steps.commit.outputs.updated == 'true' && steps.commit.outputs.pr_number != ''
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ steps.commit.outputs.pr_number }}
shell: bash
run: |
set -euo pipefail
gh pr merge "$PR_NUMBER" --merge --delete-branch
publish_pypi_prerelease:
name: Publish beta to PyPI (pre-release)
runs-on: ubuntu-latest
# Avoid double-publish when the bot merges the version bump PR
if: github.actor != 'github-actions[bot]'
environment:
name: pypi
url: https://pypi.org/p/mcpforunityserver
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: beta
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
enable-cache: true
cache-dependency-glob: "Server/uv.lock"
- name: Generate beta version
id: version
shell: bash
run: |
set -euo pipefail
RAW_VERSION=$(grep -oP '(?<=version = ")[^"]+' Server/pyproject.toml)
echo "Raw version: $RAW_VERSION"
# Check if already a beta/prerelease version
if [[ "$RAW_VERSION" =~ (a|b|rc|\.dev|\.post)[0-9]+$ ]]; then
IS_PRERELEASE=true
# Strip the prerelease suffix to get base version
BASE_VERSION=$(echo "$RAW_VERSION" | sed -E 's/(a|b|rc|\.dev|\.post)[0-9]+$//')
else
IS_PRERELEASE=false
BASE_VERSION="$RAW_VERSION"
fi
# Validate we have a proper X.Y.Z format
if ! [[ "$BASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Could not parse version '$RAW_VERSION' -> '$BASE_VERSION'" >&2
exit 1
fi
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
# Only bump patch if coming from stable; keep same base if already prerelease
if [[ "$IS_PRERELEASE" == "true" ]]; then
# Already on a beta series - keep the same base version
NEXT_PATCH="$PATCH"
echo "Already prerelease, keeping base: $BASE_VERSION"
else
# Stable version - bump patch to ensure beta is "newer"
NEXT_PATCH=$((PATCH + 1))
echo "Stable version, bumping patch: $PATCH -> $NEXT_PATCH"
fi
BETA_NUMBER="$(date +%Y%m%d%H%M%S)"
BETA_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}b${BETA_NUMBER}"
echo "Base version: $BASE_VERSION"
echo "Beta version: $BETA_VERSION"
echo "beta_version=$BETA_VERSION" >> "$GITHUB_OUTPUT"
- name: Update version for beta release
env:
BETA_VERSION: ${{ steps.version.outputs.beta_version }}
shell: bash
run: |
set -euo pipefail
sed -i "s/^version = .*/version = \"${BETA_VERSION}\"/" Server/pyproject.toml
echo "Updated pyproject.toml:"
grep "^version" Server/pyproject.toml
- name: Build a binary wheel and a source tarball
shell: bash
run: uv build
working-directory: ./Server
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: Server/dist/