Skip to content

Commit 2ad8714

Browse files
committed
test on the working branch
1 parent f3b9c25 commit 2ad8714

File tree

1 file changed

+232
-70
lines changed

1 file changed

+232
-70
lines changed
Lines changed: 232 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,272 @@
11
name: Create Unity Release PR
22

33
on:
4+
push:
5+
branches:
6+
- "ci-unity"
47
workflow_dispatch:
58
inputs:
6-
version:
7-
description: 'New Unity SDK version (e.g. 5.4.0-alpha01 or 3.2.1)'
8-
type: string
9+
release-type:
10+
description: "Release type"
911
required: true
10-
base_branch:
11-
description: 'Target branch for the PR (e.g. main for regular releases, 5.4-main for patch releases)'
12-
type: string
13-
required: false
14-
default: 'main'
12+
default: "stable"
13+
type: choice
14+
options:
15+
- Current
16+
- Beta
17+
- Alpha
18+
1519

1620
permissions:
1721
contents: write
1822
pull-requests: write
1923

2024
jobs:
21-
create-unity-release:
25+
bump-version:
2226
runs-on: ubuntu-latest
2327

24-
env:
25-
VERSION: ${{ github.event.inputs.version }}
26-
BASE_BRANCH: ${{ github.event.inputs.base_branch || 'main' }}
27-
BRANCH: release/${{ github.event.inputs.version }}
28-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
3028
steps:
31-
- name: 📋 Display Configuration
32-
run: |
33-
echo "============================================"
34-
echo "🎮 Creating Unity SDK Release"
35-
echo "📦 Version: $VERSION"
36-
echo "🎯 Base Branch (PR Target): $BASE_BRANCH"
37-
echo "🌿 Release Branch (to create): $BRANCH"
38-
echo "============================================"
39-
40-
- name: ✅ Validate Base Branch
41-
run: |
42-
if [[ "$BASE_BRANCH" == "main" ]]; then
43-
echo "✅ Valid base branch: main"
44-
elif [[ "$BASE_BRANCH" =~ ^[0-9]+\.[0-9]+-main$ ]]; then
45-
echo "✅ Valid base branch: $BASE_BRANCH"
46-
else
47-
echo "❌ ERROR: Invalid base branch '$BASE_BRANCH'"
48-
echo ""
49-
echo "Base branch must be either:"
50-
echo " - 'main' (for regular releases)"
51-
echo " - 'X.Y-main' (for patch lines, e.g., 5.4-main)"
52-
exit 1
53-
fi
54-
5529
- name: Checkout repository
56-
uses: actions/checkout@v4
30+
uses: actions/checkout@v5
5731
with:
5832
fetch-depth: 0
5933
fetch-tags: true
34+
35+
- name: Get current SDK version
36+
id: current_version
37+
run: |
38+
CURRENT_VERSION=$(grep "bundleVersion:" ProjectSettings/ProjectSettings.asset | sed 's/.*bundleVersion: //')
39+
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
6040
41+
- name: Get last release commit
42+
id: last_commit
43+
run: |
44+
LAST_RELEASE_DATE=$(git show -s --format=%cI "${{ steps.current_version.outputs.current }}")
45+
echo "date=$LAST_RELEASE_DATE" >> $GITHUB_OUTPUT
46+
6147
- name: Create release branch from base
6248
run: |
6349
if git ls-remote --exit-code --heads origin "$BRANCH"; then
6450
echo "Deleting remote branch $BRANCH"
6551
git push origin --delete "$BRANCH"
6652
fi
6753
68-
echo "Creating release branch $BRANCH from $BASE_BRANCH"
69-
git checkout -b "$BRANCH" origin/$BASE_BRANCH
54+
echo "Creating release branch $BRANCH from main"
55+
git checkout -b "$BRANCH" origin/main
56+
57+
- name: Get merged PRs since last release
58+
id: get_prs
59+
uses: actions/github-script@v8
60+
with:
61+
script: |
62+
const lastReleaseDate = '${{ steps.last_commit.outputs.date }}';
63+
64+
// Get merged PRs
65+
const { data: prs } = await github.rest.pulls.list({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
state: 'closed',
69+
base: 'main',
70+
per_page: 100
71+
});
72+
73+
// Filter and process PRs
74+
const mergedPrs = prs
75+
.filter(pr => pr.merged_at && new Date(pr.merged_at) > new Date(lastReleaseDate))
76+
.map(pr => ({
77+
number: pr.number,
78+
title: pr.title,
79+
}));
80+
core.setOutput('prs', JSON.stringify(mergedPrs));
81+
82+
const hasFeatures = mergedPrs.some(pr => /^feat/i.test(pr.title));
83+
core.setOutput('isFeature', hasFeatures);
84+
85+
- name: Calculate new version
86+
id: new_version
87+
run: |
88+
CURRENT="${{ steps.current_version.outputs.current }}"
89+
RELEASE_TYPE="${{ inputs.release-type }}"
90+
IS_FEATURE='${{ steps.get_prs.outputs.isFeature }}'
91+
92+
# Extract base version and determine current pre-release type
93+
if [[ "$CURRENT" =~ -alpha\. ]]; then
94+
BASE_VERSION="${CURRENT%-alpha.*}"
95+
PRERELEASE_NUM="${CURRENT##*-alpha.}"
96+
PRERELEASE_TYPE="alpha"
97+
elif [[ "$CURRENT" =~ -beta\. ]]; then
98+
BASE_VERSION="${CURRENT%-beta.*}"
99+
PRERELEASE_NUM="${CURRENT##*-beta.}"
100+
PRERELEASE_TYPE="beta"
101+
else
102+
BASE_VERSION="$CURRENT"
103+
PRERELEASE_TYPE="stable"
104+
fi
105+
106+
# Helper function to bump version
107+
bump_version() {
108+
local base=$1
109+
local is_feature=$2
110+
local major=${base:0:2}
111+
local minor=${base:2:2}
112+
local patch=${base:4:2}
113+
114+
if [[ "$is_feature" == "true" ]]; then
115+
minor=$(printf "%02d" $((10#$minor + 1)))
116+
patch="00"
117+
else
118+
patch=$(printf "%02d" $((10#$patch + 1)))
119+
fi
120+
121+
echo "${major}${minor}${patch}"
122+
}
123+
124+
# Determine new version based on current and desired release types
125+
if [[ "$RELEASE_TYPE" == "Alpha" ]]; then
126+
if [[ "$PRERELEASE_TYPE" == "alpha" ]]; then
127+
# Increment alpha number
128+
NEW_VERSION="$BASE_VERSION-alpha.$((PRERELEASE_NUM + 1))"
129+
else
130+
# New alpha release from stable or beta
131+
NEW_VERSION="$(bump_version "$BASE_VERSION" "$IS_FEATURE")-alpha.1"
132+
fi
133+
elif [[ "$RELEASE_TYPE" == "Beta" ]]; then
134+
if [[ "$PRERELEASE_TYPE" == "beta" ]]; then
135+
# Increment beta number
136+
NEW_VERSION="$BASE_VERSION-beta.$((PRERELEASE_NUM + 1))"
137+
elif [[ "$PRERELEASE_TYPE" == "alpha" ]]; then
138+
# Promote alpha to beta
139+
NEW_VERSION="$BASE_VERSION-beta.1"
140+
else
141+
# New beta release from stable
142+
NEW_VERSION="$(bump_version "$BASE_VERSION" "$IS_FEATURE")-beta.1"
143+
fi
144+
else
145+
# Release type is Current (stable)
146+
if [[ "$PRERELEASE_TYPE" != "stable" ]]; then
147+
# Promote pre-release to stable
148+
NEW_VERSION="$BASE_VERSION"
149+
else
150+
# Bump stable version
151+
NEW_VERSION="$(bump_version "$CURRENT" "$IS_FEATURE")"
152+
fi
153+
fi
154+
155+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
156+
157+
- name: Create release branch
158+
run: |
159+
git checkout -b rel/${{ steps.new_version.outputs.version }}
160+
git push -u origin rel/${{ steps.new_version.outputs.version }}
70161
162+
- name: Create temp branch
163+
if: inputs.release-type == 'Alpha' || inputs.release-type == 'Beta'
164+
run: |
165+
git checkout -b release-${{ steps.new_version.outputs.version }}
166+
git push -u origin release-${{ steps.new_version.outputs.version }}
167+
168+
# Unity specific steps
71169
- name: Run composeRelease.sh
72170
run: |
73171
chmod +x ./composeRelease.sh
74172
./composeRelease.sh $VERSION
75173
shell: bash
76174

77-
- name: Commit and Push version bump
175+
- name: Check native SDK version changes
176+
id: native_deps
78177
run: |
79-
git config user.name "github-actions[bot]"
80-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
178+
# Get the current plugin.xml
179+
CURRENT_PLUGIN=$(cat plugin.xml)
81180
82-
if git diff --quiet; then
83-
echo "No version changes detected."
84-
else
85-
git commit -am "chore(release): prepare Unity SDK v$VERSION"
86-
git push origin "$BRANCH"
181+
# Extract current Android SDK version
182+
ANDROID_VERSION=$(echo "$CURRENT_PLUGIN" | grep -oP 'com\.onesignal:OneSignal:\K[0-9.]+' | head -1)
183+
184+
# Extract current iOS SDK version
185+
IOS_VERSION=$(echo "$CURRENT_PLUGIN" | grep -oP 'OneSignalXCFramework.*spec="\K[0-9.]+' | head -1)
186+
187+
# Get previous plugin.xml from HEAD~1 (before the commit we just made)
188+
PREVIOUS_PLUGIN=$(git show HEAD~1:plugin.xml)
189+
190+
# Extract previous Android SDK version
191+
PREVIOUS_ANDROID=$(echo "$PREVIOUS_PLUGIN" | grep -oP 'com\.onesignal:OneSignal:\K[0-9.]+' | head -1)
192+
193+
# Extract previous iOS SDK version
194+
PREVIOUS_IOS=$(echo "$PREVIOUS_PLUGIN" | grep -oP 'OneSignalXCFramework.*spec="\K[0-9.]+' | head -1)
195+
196+
# Build output for native dependency changes
197+
NATIVE_UPDATES=""
198+
if [[ "$ANDROID_VERSION" != "$PREVIOUS_ANDROID" && ! -z "$PREVIOUS_ANDROID" ]]; then
199+
printf -v NATIVE_UPDATES '%sANDROID_UPDATE=true\nANDROID_FROM=%s\nANDROID_TO=%s\n' "$NATIVE_UPDATES" "$PREVIOUS_ANDROID" "$ANDROID_VERSION"
87200
fi
88201
89-
- name: Generate PR Body
90-
run: |
91-
echo "## 🎮 Unity SDK Release v$VERSION" > pr_body.md
92-
echo "" >> pr_body.md
93-
echo "**Summary:**" >> pr_body.md
94-
echo "- Automated release PR created by CI." >> pr_body.md
95-
echo "- Includes version bumps and changelog updates performed by composeRelease.sh." >> pr_body.md
96-
echo "" >> pr_body.md
97-
echo "**Next Steps:**" >> pr_body.md
98-
echo "1. Review and approve this PR." >> pr_body.md
99-
echo "2. Merge into \`$BASE_BRANCH\`." >> pr_body.md
100-
echo "3. Verify the generated draft GitHub release and attach the updated *.unitypackage if needed." >> pr_body.md
101-
echo "" >> pr_body.md
102-
echo "_This PR was auto-generated by create-unity-release CI._" >> pr_body.md
103-
104-
- name: Create Pull Request
202+
if [[ "$IOS_VERSION" != "$PREVIOUS_IOS" && ! -z "$PREVIOUS_IOS" ]]; then
203+
printf -v NATIVE_UPDATES '%sIOS_UPDATE=true\nIOS_FROM=%s\nIOS_TO=%s\n' "$NATIVE_UPDATES" "$PREVIOUS_IOS" "$IOS_VERSION"
204+
fi
205+
206+
# Output the variables
207+
echo "$NATIVE_UPDATES" >> $GITHUB_OUTPUT
208+
209+
- name: Generate release notes
210+
id: release_notes
211+
uses: actions/github-script@v8
212+
with:
213+
script: |
214+
// Trim whitespace from PR titles
215+
const prs = JSON.parse('${{ steps.get_prs.outputs.prs }}').map(pr => ({
216+
...pr,
217+
title: pr.title.trim()
218+
}));
219+
220+
// Categorize PRs
221+
const features = prs.filter(pr => /^feat/i.test(pr.title));
222+
const fixes = prs.filter(pr => /^fix/i.test(pr.title));
223+
const improvements = prs.filter(pr => /^(perf|refactor|chore)/i.test(pr.title));
224+
225+
// Helper function to build section
226+
const buildSection = (title, prs) => {
227+
if (prs.length === 0) return '';
228+
let section = `### ${title}\n\n`;
229+
prs.forEach(pr => {
230+
section += `- ${pr.title} (#${pr.number})\n`;
231+
});
232+
return section + '\n';
233+
};
234+
235+
let releaseNotes = `Channels: ${{ inputs.release-type }}\n\n`;
236+
releaseNotes += buildSection('🚀 New Features', features);
237+
releaseNotes += buildSection('🐛 Bug Fixes', fixes);
238+
releaseNotes += buildSection('✨ Improvements', improvements);
239+
240+
// Check for native dependency changes
241+
const hasAndroidUpdate = '${{ steps.native_deps.outputs.ANDROID_UPDATE }}' === 'true';
242+
const hasIosUpdate = '${{ steps.native_deps.outputs.IOS_UPDATE }}' === 'true';
243+
244+
if (hasAndroidUpdate || hasIosUpdate) {
245+
releaseNotes += '\n### 🛠️ Native Dependency Updates\n\n';
246+
if (hasAndroidUpdate) {
247+
releaseNotes += `- Update Android SDK from ${{ steps.native_deps.outputs.ANDROID_FROM }} to ${{ steps.native_deps.outputs.ANDROID_TO }}\n`;
248+
releaseNotes += `- See [release notes](https://github.com/OneSignal/OneSignal-Android-SDK/releases) for full details\n`;
249+
}
250+
if (hasIosUpdate) {
251+
releaseNotes += `- Update iOS SDK from ${{ steps.native_deps.outputs.IOS_FROM }} to ${{ steps.native_deps.outputs.IOS_TO }}\n`;
252+
releaseNotes += `- See [release notes](https://github.com/OneSignal/OneSignal-iOS-SDK/releases) for full details\n`;
253+
}
254+
releaseNotes += '\n';
255+
}
256+
257+
core.setOutput('notes', releaseNotes);
258+
259+
- name: Create release PR
105260
run: |
261+
NEW_VERSION="${{ steps.new_version.outputs.version }}"
262+
263+
# Write release notes to file to avoid shell interpretation
264+
cat > release_notes.md << 'EOF'
265+
${{ steps.release_notes.outputs.notes }}
266+
EOF
267+
106268
gh pr create \
107-
--title "Release Unity SDK v$VERSION" \
108-
--body-file pr_body.md \
109-
--head "$BRANCH" \
110-
--base "$BASE_BRANCH"
269+
--title "Release $NEW_VERSION" \
270+
--body-file release_notes.md \
271+
--base main \
272+
--reviewer jkasten2

0 commit comments

Comments
 (0)