Skip to content

Commit d6d3733

Browse files
author
crow
committed
Add prep-release automation and scripts
1 parent acb0976 commit d6d3733

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed

.github/workflows/prep-release.yml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Prepare Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
react_native_version:
7+
description: 'React Native Version (x.y.z)'
8+
required: true
9+
pattern: '^\d+\.\d+\.\d+$'
10+
proxy_version:
11+
description: 'Airship Framework Proxy Version (x.y.z)'
12+
required: true
13+
pattern: '^\d+\.\d+\.\d+$'
14+
ios_version:
15+
description: 'iOS SDK Version (x.y.z)'
16+
required: false
17+
pattern: '^\d+\.\d+\.\d+$'
18+
android_version:
19+
description: 'Android SDK Version (x.y.z)'
20+
required: false
21+
pattern: '^\d+\.\d+\.\d+$'
22+
draft:
23+
description: 'Create as draft PR'
24+
type: boolean
25+
default: false
26+
27+
permissions:
28+
contents: write
29+
pull-requests: write
30+
31+
jobs:
32+
prepare-release:
33+
runs-on: macos-latest
34+
timeout-minutes: 15
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
ref: main
40+
fetch-depth: 0
41+
token: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Run Updates
44+
run: |
45+
./scripts/update_version.sh "${{ github.event.inputs.react_native_version }}" || exit 1
46+
./scripts/update_proxy_version.sh "${{ github.event.inputs.proxy_version }}" || exit 1
47+
if [ -n "${{ github.event.inputs.ios_version }}" ] && [ -n "${{ github.event.inputs.android_version }}" ]; then
48+
./scripts/update_changelog.sh "${{ github.event.inputs.react_native_version }}" "${{ github.event.inputs.proxy_version }}" "${{ github.event.inputs.ios_version }}" "${{ github.event.inputs.android_version }}" || exit 1
49+
fi
50+
51+
- name: Verify Changes
52+
id: verify
53+
run: |
54+
CHANGED_FILES=$(git diff --name-only)
55+
if [ -z "$CHANGED_FILES" ]; then
56+
echo "No files were changed!"
57+
exit 1
58+
fi
59+
echo "Changed files:"
60+
echo "$CHANGED_FILES"
61+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
62+
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
63+
echo "EOF" >> $GITHUB_OUTPUT
64+
65+
- name: Create Pull Request
66+
id: create-pr
67+
uses: peter-evans/create-pull-request@v5
68+
with:
69+
token: ${{ secrets.GITHUB_TOKEN }}
70+
commit-message: |
71+
Release ${{ github.event.inputs.react_native_version }}
72+
title: "Release ${{ github.event.inputs.react_native_version }}"
73+
body: |
74+
- Framework Proxy: ${{ github.event.inputs.proxy_version }}
75+
- iOS SDK: ${{ github.event.inputs.ios_version }}
76+
- Android SDK: ${{ github.event.inputs.android_version }}
77+
78+
## Changed Files:
79+
```
80+
${{ steps.verify.outputs.changed_files }}
81+
```
82+
branch: release-${{ github.event.inputs.react_native_version }}
83+
base: main
84+
labels: |
85+
release
86+
automated pr
87+
draft: ${{ github.event.inputs.draft }}
88+
delete-branch: true
89+
90+
- name: Handle Success
91+
if: success() && steps.create-pr.outputs.pull-request-number
92+
run: |
93+
echo "Pull request created successfully"
94+
echo "PR Number: ${{ steps.create-pr.outputs.pull-request-number }}"
95+
echo "PR URL: ${{ steps.create-pr.outputs.pull-request-url }}"
96+
97+
- name: Slack Notification (Success)
98+
if: success() && steps.create-pr.outputs.pull-request-number
99+
uses: homoluctus/slatify@master
100+
with:
101+
type: success
102+
job_name: ":tada: React Native plugin release pull request generated :tada:"
103+
message: "@mobile-team A new React Native plugin release pull request for (v${{ github.event.inputs.react_native_version }}) is ready! :rocket:"
104+
url: ${{ secrets.MOBILE_SLACK_WEBHOOK }}
105+
106+
- name: Handle Failure
107+
if: failure()
108+
run: |
109+
echo "::error::Release preparation failed. Please check the logs above for details."
110+
exit 1
111+
112+
- name: Slack Notification (Failure)
113+
if: failure()
114+
uses: homoluctus/slatify@master
115+
with:
116+
type: failure
117+
job_name: ":disappointed: React Native Plugin Release Failed :disappointed:"
118+
message: "@crow The release preparation failed. Please check the workflow logs. :sob:"
119+
url: ${{ secrets.MOBILE_SLACK_WEBHOOK }}

scripts/update_changelog.sh

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
SCRIPT_DIRECTORY="$(dirname "$0")"
6+
ROOT_PATH=$SCRIPT_DIRECTORY/../
7+
8+
# First argument is always the version
9+
VERSION=$1
10+
shift
11+
12+
# Process remaining arguments as named parameters
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--ios)
16+
IOS_VERSION="$2"
17+
shift 2
18+
;;
19+
--android)
20+
ANDROID_VERSION="$2"
21+
shift 2
22+
;;
23+
*)
24+
echo "Unknown parameter: $1"
25+
exit 1
26+
;;
27+
esac
28+
done
29+
30+
if [ -z "$VERSION" ]; then
31+
echo "Error: Version is required"
32+
exit 1
33+
fi
34+
35+
RELEASE_DATE=$(date +"%B %-d, %Y")
36+
37+
# Determine release type based on version
38+
if [[ $VERSION =~ \.0\.0$ ]]; then
39+
RELEASE_TYPE="Major"
40+
elif [[ $VERSION =~ \.0$ ]]; then
41+
RELEASE_TYPE="Minor"
42+
else
43+
RELEASE_TYPE="Patch"
44+
fi
45+
46+
# Create changelog entry
47+
NEW_ENTRY="## Version $VERSION - $RELEASE_DATE\n\n"
48+
49+
if [ -n "$IOS_VERSION" ] || [ -n "$ANDROID_VERSION" ]; then
50+
NEW_ENTRY+="$RELEASE_TYPE release that updates"
51+
52+
if [ -n "$ANDROID_VERSION" ]; then
53+
NEW_ENTRY+=" the Android SDK to [$ANDROID_VERSION](https://github.com/urbanairship/android-library/releases/tag/$ANDROID_VERSION"
54+
fi
55+
56+
if [ -n "$IOS_VERSION" ] && [ -n "$ANDROID_VERSION" ]; then
57+
NEW_ENTRY+=" and"
58+
fi
59+
60+
if [ -n "$IOS_VERSION" ]; then
61+
NEW_ENTRY+=" the iOS SDK to [$IOS_VERSION](https://github.com/urbanairship/ios-library/releases/tag/$IOS_VERSION"
62+
fi
63+
64+
NEW_ENTRY+="\n\n### Changes\n"
65+
66+
if [ -n "$ANDROID_VERSION" ]; then
67+
NEW_ENTRY+="- Updated Android SDK to $ANDROID_VERSION"
68+
fi
69+
70+
if [ -n "$IOS_VERSION" ]; then
71+
NEW_ENTRY+="\n"
72+
NEW_ENTRY+="- Updated iOS SDK to $IOS_VERSION"
73+
fi
74+
75+
else
76+
NEW_ENTRY+="$RELEASE_TYPE release."
77+
fi
78+
79+
# Create temporary file with new content
80+
TEMP_FILE=$(mktemp)
81+
82+
# Add the header line
83+
echo "# React Native Module Changelog" > "$TEMP_FILE"
84+
echo -e "\n$NEW_ENTRY" >> "$TEMP_FILE"
85+
86+
# Append the rest of the existing changelog (skipping the header)
87+
tail -n +2 "$ROOT_PATH/CHANGELOG.md" >> "$TEMP_FILE"
88+
89+
# Replace original file with new content
90+
mv "$TEMP_FILE" "$ROOT_PATH/CHANGELOG.md"

scripts/update_proxy_version.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
SCRIPT_DIRECTORY="$(cd "$(dirname "$0")" && pwd)"
5+
ROOT_PATH="$SCRIPT_DIRECTORY/.."
6+
7+
PROXY_VERSION="$1"
8+
if [ -z "$PROXY_VERSION" ]; then
9+
echo "No proxy version supplied"
10+
exit 1
11+
fi
12+
13+
# Update Android gradle.properties
14+
sed -i.bak -E "s/(Airship_airshipProxyVersion=)([^$]*)/\1$PROXY_VERSION/" "$ROOT_PATH/android/gradle.properties"
15+
16+
# Update iOS podspec
17+
sed -i.bak -E "s/(s\.dependency *\"AirshipFrameworkProxy\", *\")([^\"]*)(\")/\1$PROXY_VERSION\3/" "$ROOT_PATH/react-native-airship.podspec"
18+
19+
find "$ROOT_PATH" -name "*.bak" -delete

0 commit comments

Comments
 (0)