Skip to content

Commit f0ab924

Browse files
committed
update create_release logic
1 parent fa3801c commit f0ab924

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

.github/workflows/create-release.yml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# - Creates release PR w/ expected release notes
55

66
# NOTE: For calls from Native SDKS, do not pass `android_from`, `android_to`, `ios_from`, or `ios_to`
7-
# Use `version_from` and `version_to` instead.
7+
# Use `target_branch` and `release_branch` instead.
88
name: Create SDK Release
99

1010
on:
@@ -14,14 +14,11 @@ on:
1414
required: true
1515
type: string
1616
description: Name of the release branch
17-
version_from:
18-
required: true
19-
type: string
20-
description: The previous version (e.g., 5.2.14)
21-
version_to:
22-
required: true
17+
target_branch:
18+
required: false
2319
type: string
24-
description: The new version being released (e.g., 5.2.15)
20+
description: The branch to target for the release PR (e.g. 5.4.0-main)
21+
default: main
2522

2623
android_from:
2724
required: false
@@ -56,13 +53,22 @@ jobs:
5653
steps:
5754
- uses: actions/checkout@v5
5855
with:
59-
ref: ${{ inputs.release_branch }}
56+
ref: ${{ inputs.target_branch }}
6057
fetch-depth: 0
6158

59+
- name: Extract version_to from release_branch
60+
id: release_version
61+
run: |
62+
# Extract version from release_branch format: rel/version_to
63+
VERSION_TO="${{ inputs.release_branch }}"
64+
VERSION_TO="${VERSION_TO#rel/}"
65+
echo "version_to=$VERSION_TO" >> $GITHUB_OUTPUT
66+
6267
- name: Get last release commit
6368
id: last_commit
6469
run: |
65-
CURRENT_VERSION="${{ inputs.version_from }}"
70+
# Get the last tag from the current branch
71+
CURRENT_VERSION=$(git describe --tags --abbrev=0)
6672
LAST_RELEASE_DATE=$(git show -s --format=%cI "$CURRENT_VERSION")
6773
echo "date=$LAST_RELEASE_DATE" >> $GITHUB_OUTPUT
6874
@@ -73,11 +79,8 @@ jobs:
7379
script: |
7480
const lastReleaseDate = '${{ steps.last_commit.outputs.date }}';
7581
const releaseBranch = '${{ inputs.release_branch }}';
76-
const version = '${{ inputs.version_to }}';
77-
78-
// Determine release type from version
79-
const releaseType = version.includes('-alpha') ? 'Alpha' :
80-
version.includes('-beta') ? 'Beta' : 'Current';
82+
const targetBranch = '${{ inputs.target_branch }}';
83+
const version = '${{ steps.release_version.outputs.version_to }}';
8184
8285
// Get the creation date of the release branch (when it diverged from main)
8386
const { data: branchInfo } = await github.rest.repos.getBranch({
@@ -87,22 +90,19 @@ jobs:
8790
});
8891
const branchCreatedAt = branchInfo.commit.commit.committer.date;
8992
90-
// For Current: Get PRs merged to main since last release but BEFORE release branch was created
91-
// For Alpha/Beta: Use releaseBranch as base
92-
const baseBranch = (releaseType === 'Alpha' || releaseType === 'Beta') ? releaseBranch : 'main';
93+
// Get PRs merged to target branch since last release
9394
const { data: prs } = await github.rest.pulls.list({
9495
owner: context.repo.owner,
9596
repo: context.repo.repo,
9697
state: 'closed',
97-
base: baseBranch,
98+
base: targetBranch,
9899
per_page: 100
99100
});
100101
101102
const mergedPrs = prs
102103
.filter(pr =>
103104
pr.merged_at &&
104-
new Date(pr.merged_at) > new Date(lastReleaseDate) &&
105-
(releaseType === 'Current' ? new Date(pr.merged_at) <= new Date(branchCreatedAt) : true)
105+
new Date(pr.merged_at) > new Date(lastReleaseDate)
106106
)
107107
.map(pr => ({
108108
number: pr.number,
@@ -223,7 +223,7 @@ jobs:
223223
};
224224
225225
// Determine release type from version
226-
const version = '${{ inputs.version_to }}';
226+
const version = '${{ steps.release_version.outputs.version_to }}';
227227
const releaseType = version.includes('-alpha') ? 'Alpha' :
228228
version.includes('-beta') ? 'Beta' : 'Current';
229229
@@ -257,16 +257,11 @@ jobs:
257257
258258
- name: Create release PR
259259
run: |
260-
NEW_VERSION="${{ inputs.version_to }}"
260+
# Checkout the release branch
261+
git checkout ${{ inputs.release_branch }}
261262
262-
# Determine release type and base branch from version
263-
if [[ "$NEW_VERSION" =~ -alpha ]]; then
264-
BASE_BRANCH="${{ inputs.release_branch }}"
265-
elif [[ "$NEW_VERSION" =~ -beta ]]; then
266-
BASE_BRANCH="${{ inputs.release_branch }}"
267-
else
268-
BASE_BRANCH="main"
269-
fi
263+
NEW_VERSION="${{ steps.release_version.outputs.version_to }}"
264+
TARGET_BRANCH="${{ inputs.target_branch }}"
270265
271266
# Write release notes to file to avoid shell interpretation
272267
cat > release_notes.md << 'EOF'
@@ -276,4 +271,4 @@ jobs:
276271
gh pr create \
277272
--title "chore: Release $NEW_VERSION" \
278273
--body-file release_notes.md \
279-
--base "$BASE_BRANCH"
274+
--base "$TARGET_BRANCH"

0 commit comments

Comments
 (0)