Skip to content

Commit dbb7589

Browse files
Add bump-native-sdks workflow
1 parent d789848 commit dbb7589

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Bump native SDK versions
2+
3+
on:
4+
schedule:
5+
- cron: '0 9 * * 1-5' # 9am UTC, Mon–Fri
6+
workflow_dispatch: # allow manual runs from the Actions UI
7+
8+
jobs:
9+
bump:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
# Use a PAT so the resulting PR triggers pull_request CI workflows.
19+
# GITHUB_TOKEN-created PRs intentionally don't trigger other workflows.
20+
token: ${{ secrets.NATIVE_SDK_BUMP_TOKEN }}
21+
22+
# ── Fetch latest release versions ─────────────────────────────────────
23+
24+
- name: Fetch latest stripe-ios release
25+
id: ios_latest
26+
env:
27+
GH_TOKEN: ${{ secrets.NATIVE_SDK_BUMP_TOKEN }}
28+
run: |
29+
VERSION=$(gh api repos/stripe/stripe-ios/releases/latest --jq '.tag_name' | sed 's/^v//')
30+
echo "version=$VERSION" >> $GITHUB_OUTPUT
31+
32+
- name: Fetch latest stripe-android release
33+
id: android_latest
34+
env:
35+
GH_TOKEN: ${{ secrets.NATIVE_SDK_BUMP_TOKEN }}
36+
run: |
37+
VERSION=$(gh api repos/stripe/stripe-android/releases/latest --jq '.tag_name' | sed 's/^v//')
38+
echo "version=$VERSION" >> $GITHUB_OUTPUT
39+
40+
# ── Read current pinned versions ───────────────────────────────────────
41+
42+
- name: Read current pinned versions
43+
id: current
44+
run: |
45+
# Extracts "25.17.0" from: stripe_version = '25.17.0'
46+
IOS=$(grep "stripe_version = " stripe-react-native.podspec \
47+
| sed "s/.*'\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)'.*/\1/")
48+
49+
# Extracts "23.10.3" from: StripeSdk_stripeVersion=23.10.3
50+
ANDROID=$(grep "^StripeSdk_stripeVersion=" android/gradle.properties \
51+
| sed 's/StripeSdk_stripeVersion=//')
52+
53+
echo "ios=$IOS" >> $GITHUB_OUTPUT
54+
echo "android=$ANDROID" >> $GITHUB_OUTPUT
55+
56+
# ── Diff ───────────────────────────────────────────────────────────────
57+
58+
- name: Determine what needs updating
59+
id: diff
60+
run: |
61+
IOS_NEW="${{ steps.ios_latest.outputs.version }}"
62+
ANDROID_NEW="${{ steps.android_latest.outputs.version }}"
63+
64+
IOS_CHANGED=false
65+
ANDROID_CHANGED=false
66+
67+
[ "$IOS_NEW" != "${{ steps.current.outputs.ios }}" ] && IOS_CHANGED=true
68+
[ "$ANDROID_NEW" != "${{ steps.current.outputs.android }}" ] && ANDROID_CHANGED=true
69+
70+
echo "ios_changed=$IOS_CHANGED" >> $GITHUB_OUTPUT
71+
echo "android_changed=$ANDROID_CHANGED" >> $GITHUB_OUTPUT
72+
echo "ios_new=$IOS_NEW" >> $GITHUB_OUTPUT
73+
echo "android_new=$ANDROID_NEW" >> $GITHUB_OUTPUT
74+
75+
# ── Open PR if anything changed ────────────────────────────────────────
76+
77+
- name: Update files and open PR
78+
if: steps.diff.outputs.ios_changed == 'true' || steps.diff.outputs.android_changed == 'true'
79+
env:
80+
GH_TOKEN: ${{ secrets.NATIVE_SDK_BUMP_TOKEN }}
81+
IOS_NEW: ${{ steps.diff.outputs.ios_new }}
82+
ANDROID_NEW: ${{ steps.diff.outputs.android_new }}
83+
IOS_CHANGED: ${{ steps.diff.outputs.ios_changed }}
84+
ANDROID_CHANGED: ${{ steps.diff.outputs.android_changed }}
85+
run: |
86+
# Build a deterministic branch name from the new version(s) so the
87+
# workflow is idempotent — re-running when a PR is already open for
88+
# the same versions is a no-op.
89+
BRANCH="chore/bump-native-sdks"
90+
[ "$IOS_CHANGED" = "true" ] && BRANCH="${BRANCH}-ios-${IOS_NEW}"
91+
[ "$ANDROID_CHANGED" = "true" ] && BRANCH="${BRANCH}-android-${ANDROID_NEW}"
92+
93+
if gh pr list --state open --head "$BRANCH" --json number --jq '.[0].number' \
94+
2>/dev/null | grep -q '[0-9]'; then
95+
echo "PR already open for $BRANCH — nothing to do."
96+
exit 0
97+
fi
98+
99+
git config user.name "github-actions[bot]"
100+
git config user.email "github-actions[bot]@users.noreply.github.com"
101+
git checkout -b "$BRANCH"
102+
103+
TITLE_PARTS=()
104+
BODY_LINES=()
105+
106+
if [ "$IOS_CHANGED" = "true" ]; then
107+
sed -i \
108+
"s/stripe_version = '[^']*'/stripe_version = '${IOS_NEW}'/" \
109+
stripe-react-native.podspec
110+
git add stripe-react-native.podspec
111+
TITLE_PARTS+=("stripe-ios ${IOS_NEW}")
112+
BODY_LINES+=("- \`stripe-react-native.podspec\`: \`stripe_version\` → \`${IOS_NEW}\` ([release notes](https://github.com/stripe/stripe-ios/releases/tag/${IOS_NEW}))")
113+
fi
114+
115+
if [ "$ANDROID_CHANGED" = "true" ]; then
116+
sed -i \
117+
"s/^StripeSdk_stripeVersion=.*/StripeSdk_stripeVersion=${ANDROID_NEW}/" \
118+
android/gradle.properties
119+
git add android/gradle.properties
120+
TITLE_PARTS+=("stripe-android ${ANDROID_NEW}")
121+
BODY_LINES+=("- \`android/gradle.properties\`: \`StripeSdk_stripeVersion\` → \`${ANDROID_NEW}\` ([release notes](https://github.com/stripe/stripe-android/releases/tag/v${ANDROID_NEW}))")
122+
fi
123+
124+
TITLE="chore: bump $(IFS=', '; echo "${TITLE_PARTS[*]}")"
125+
126+
BODY="$(IFS=$'\n'; echo "${BODY_LINES[*]}")
127+
128+
_Automated by [\`bump-native-sdks\`](.github/workflows/bump-native-sdks.yml)_"
129+
130+
git commit -m "$TITLE"
131+
git push origin "$BRANCH"
132+
133+
gh pr create \
134+
--title "$TITLE" \
135+
--body "$BODY" \
136+
--base master \
137+
--head "$BRANCH"

0 commit comments

Comments
 (0)