Skip to content

Create Unity Release PR #9

Create Unity Release PR

Create Unity Release PR #9

name: Create Unity Release PR
on:
workflow_dispatch:
inputs:
bump_command:
description: "Version bump type (major, minor, patch, specify)"
required: true
type: choice
options:
- major
- minor
- patch
- specify
postfix:
description: "Optional postfix (e.g. preview, beta, or specific version when using 'specify')"
required: false
type: string
permissions:
contents: write
pull-requests: write
jobs:
compose-unity-release:
name: Compose Unity Release
runs-on: ubuntu-latest
timeout-minutes: 30
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUMP_COMMAND: ${{ github.event.inputs.bump_command }}
POSTFIX: ${{ github.event.inputs.postfix }}
steps:
- name: 📦 Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Display Configuration
run: |
echo "============================================"
echo "🎮 Unity SDK Release Composition"
echo "🧩 Bump Command: $BUMP_COMMAND"
echo "🏷️ Postfix: $POSTFIX"
echo "============================================"
- name: Prepare Environment
run: |
brew install gh jq || true
gh auth status || gh auth login --with-token <<< "$GH_TOKEN"
- name: Run composeRelease.sh
run: |
chmod +x ./composeRelease.sh
if [[ -n "$POSTFIX" ]]; then
./composeRelease.sh "$BUMP_COMMAND" "$POSTFIX" || echo "composeRelease.sh failed, continuing to patch manually"
else
./composeRelease.sh "$BUMP_COMMAND" || echo "composeRelease.sh failed, continuing to patch manually"
fi
- name: Detect New Version
id: version
run: |
VERSION=$(cat OneSignalExample/Assets/OneSignal/VERSION)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "✅ Detected new version: $VERSION"
- name: 💾 Apply Version Changes and Commit
run: |
set -e
VERSION=${{ env.VERSION }}
echo "🔧 Updating version references to $VERSION"
git fetch origin "release/$VERSION"
git checkout "release/$VERSION" || git checkout -b "release/$VERSION"
# Extract current version for replacement
CURRENT=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?' OneSignalExample/Assets/OneSignal/VERSION | head -n 1)
echo "Detected previous version: $CURRENT"
# 1️⃣ Update OneSignal.cs
sed -i '' "s/Version = \".*\";/Version = \"$VERSION\";/" com.onesignal.unity.core/Runtime/OneSignal.cs
# 2️⃣ Update OneSignalPlatform.cs header
OLD_HEADER=$(printf "%02d%02d%02d" $(echo $CURRENT | tr '.' ' '))
NEW_HEADER=$(printf "%02d%02d%02d" $(echo $VERSION | tr '.' ' '))
sed -i '' "s/VersionHeader = \".*\";/VersionHeader = \"$NEW_HEADER\";/" com.onesignal.unity.core/Runtime/OneSignalPlatform.cs
# 3️⃣ Update UIApplication+OneSignalUnity.mm iOS header
sed -i '' "s/setSdkVersion:@\".*\"];$/setSdkVersion:@\"$NEW_HEADER\"];/" com.onesignal.unity.ios/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm
# 4️⃣ Update all package.json versions
find . -path "*/package.json" -exec sed -i '' "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" {} \;
find . -path "*/package.json" -exec sed -i '' "s/\"com.onesignal.unity.core\": \".*\"/\"com.onesignal.unity.core\": \"$VERSION\"/" {} \;
# 5️⃣ Update packages-lock.json
sed -i '' "s/\"com.onesignal.unity.core\": \".*\"/\"com.onesignal.unity.core\": \"$VERSION\"/" OneSignalExample/Packages/packages-lock.json
# 6️⃣ Update .asmdef version expressions
find OneSignalExample/Assets/OneSignal -name "*.asmdef" -exec sed -i '' "s/\"expression\": \".*\"/\"expression\": \"$VERSION\"/" {} \;
# 7️⃣ Update CHANGELOG.md section
CHANGELOG="OneSignalExample/Assets/OneSignal/CHANGELOG.md"
if grep -q "\[Unreleased\]" "$CHANGELOG"; then
sed -i '' "s/## \[Unreleased\]/## [Unreleased]\n## [$VERSION]/" "$CHANGELOG"
fi
echo "✅ Version updates applied."
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore(release): update version files for $VERSION" || echo "No changes to commit"
git push origin "release/$VERSION"
- name: 🔍 Confirm PR Exists
run: |
PR_URL=$(gh pr list --head "release/$VERSION" --json url --jq '.[0].url')
if [[ -n "$PR_URL" ]]; then
echo "✅ Release PR found: $PR_URL"
else
echo "⚠️ No PR found. composeRelease.sh should have created one."
echo "If missing, create manually from release/$VERSION → main."
fi