Skip to content
Merged
84 changes: 84 additions & 0 deletions .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,93 @@ on:
- beta
paths:
- "Server/**"
- "MCPForUnity/**"

jobs:
update_unity_beta_version:
name: Update Unity package to beta version
runs-on: ubuntu-latest
permissions:
contents: 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"

# Strip any existing pre-release suffix for safe parsing
# e.g., "9.3.1-beta.1" -> "9.3.1"
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-[a-zA-Z]+\.[0-9]+$//')

# Validate we have a proper X.Y.Z format before arithmetic
if ! [[ "$BASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Could not parse version '$CURRENT_VERSION' -> '$BASE_VERSION'" >&2
exit 1
fi

# Check if already a beta version
if [[ "$CURRENT_VERSION" == *"-beta."* ]]; then
echo "Already a beta version, keeping: $CURRENT_VERSION"
echo "unity_beta_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
echo "already_beta=true" >> "$GITHUB_OUTPUT"
else
# Create beta version with semver format (e.g., 9.4.0-beta.1)
# Bump minor version to ensure beta is "newer" than stable
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
NEXT_MINOR=$((MINOR + 1))
BETA_VERSION="${MAJOR}.${NEXT_MINOR}.0-beta.1"
echo "Generated Unity beta version: $BETA_VERSION"
echo "unity_beta_version=$BETA_VERSION" >> "$GITHUB_OUTPUT"
echo "already_beta=false" >> "$GITHUB_OUTPUT"
fi

- name: Update Unity package.json with beta version
if: steps.version.outputs.already_beta != '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 and push beta version
id: commit
if: steps.version.outputs.already_beta != 'true'
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"
else
git add MCPForUnity/package.json
git commit -m "chore: update Unity package to beta version ${{ steps.version.outputs.unity_beta_version }}"
git push origin beta
echo "updated=true" >> "$GITHUB_OUTPUT"
fi

publish_pypi_prerelease:
name: Publish beta to PyPI (pre-release)
needs: update_unity_beta_version
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -25,6 +108,7 @@ jobs:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: beta

- name: Install uv
uses: astral-sh/setup-uv@v7
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,50 @@ jobs:
ref: main
fetch-depth: 0

- name: Merge beta into main
shell: bash
run: |
set -euo pipefail
git config user.name "GitHub Actions"
git config user.email "actions@github.com"

# Fetch beta branch
git fetch origin beta

# Check if beta has changes not in main
if git merge-base --is-ancestor origin/beta HEAD; then
echo "beta is already merged into main. Nothing to merge."
else
echo "Merging beta into main..."
git merge origin/beta --no-edit -m "chore: merge beta into main for release"
echo "Beta merged successfully."
fi

- name: Strip beta suffix from version if present
shell: bash
run: |
set -euo pipefail
CURRENT_VERSION=$(jq -r '.version' "MCPForUnity/package.json")
echo "Current version: $CURRENT_VERSION"

# Strip beta/alpha/rc suffix if present (e.g., "9.4.0-beta.1" -> "9.4.0")
if [[ "$CURRENT_VERSION" == *"-"* ]]; then
STABLE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-[a-zA-Z]+\.[0-9]+$//')
# Validate we have a proper X.Y.Z format after stripping
if ! [[ "$STABLE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Could not parse version '$CURRENT_VERSION' -> '$STABLE_VERSION'" >&2
exit 1
fi
echo "Stripping prerelease suffix: $CURRENT_VERSION -> $STABLE_VERSION"
jq --arg v "$STABLE_VERSION" '.version = $v' MCPForUnity/package.json > tmp.json
mv tmp.json MCPForUnity/package.json

# Also update pyproject.toml
sed -i "s/^version = .*/version = \"${STABLE_VERSION}\"/" Server/pyproject.toml
else
echo "Version is already stable: $CURRENT_VERSION"
fi

- name: Compute new version
id: compute
shell: bash
Expand Down
Loading