|
| 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 | + IOS=$(grep "stripe_version = " stripe-react-native.podspec \ |
| 46 | + | sed "s/.*'\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)'.*/\1/") |
| 47 | +
|
| 48 | + ANDROID=$(grep "^StripeSdk_stripeVersion=" android/gradle.properties \ |
| 49 | + | sed 's/StripeSdk_stripeVersion=//') |
| 50 | +
|
| 51 | + echo "ios=$IOS" >> $GITHUB_OUTPUT |
| 52 | + echo "android=$ANDROID" >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | + # ── Diff ─────────────────────────────────────────────────────────────── |
| 55 | + |
| 56 | + - name: Determine what needs updating |
| 57 | + id: diff |
| 58 | + run: | |
| 59 | + IOS_NEW="${{ steps.ios_latest.outputs.version }}" |
| 60 | + ANDROID_NEW="${{ steps.android_latest.outputs.version }}" |
| 61 | +
|
| 62 | + IOS_CHANGED=false |
| 63 | + ANDROID_CHANGED=false |
| 64 | +
|
| 65 | + [ "$IOS_NEW" != "${{ steps.current.outputs.ios }}" ] && IOS_CHANGED=true |
| 66 | + [ "$ANDROID_NEW" != "${{ steps.current.outputs.android }}" ] && ANDROID_CHANGED=true |
| 67 | +
|
| 68 | + echo "ios_changed=$IOS_CHANGED" >> $GITHUB_OUTPUT |
| 69 | + echo "android_changed=$ANDROID_CHANGED" >> $GITHUB_OUTPUT |
| 70 | + echo "ios_new=$IOS_NEW" >> $GITHUB_OUTPUT |
| 71 | + echo "android_new=$ANDROID_NEW" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + # ── Open PR if anything changed ──────────────────────────────────────── |
| 74 | + |
| 75 | + - name: Update files and open PR |
| 76 | + if: steps.diff.outputs.ios_changed == 'true' || steps.diff.outputs.android_changed == 'true' |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ secrets.NATIVE_SDK_BUMP_TOKEN }} |
| 79 | + IOS_NEW: ${{ steps.diff.outputs.ios_new }} |
| 80 | + ANDROID_NEW: ${{ steps.diff.outputs.android_new }} |
| 81 | + IOS_CHANGED: ${{ steps.diff.outputs.ios_changed }} |
| 82 | + ANDROID_CHANGED: ${{ steps.diff.outputs.android_changed }} |
| 83 | + run: | |
| 84 | + # Build a deterministic branch name from the new version(s) so the |
| 85 | + # workflow is idempotent — re-running when a PR is already open for |
| 86 | + # the same versions is a no-op. |
| 87 | + BRANCH="chore/bump-native-sdks" |
| 88 | + [ "$IOS_CHANGED" = "true" ] && BRANCH="${BRANCH}-ios-${IOS_NEW}" |
| 89 | + [ "$ANDROID_CHANGED" = "true" ] && BRANCH="${BRANCH}-android-${ANDROID_NEW}" |
| 90 | +
|
| 91 | + if gh pr list --state open --head "$BRANCH" --json number --jq '.[0].number' \ |
| 92 | + 2>/dev/null | grep -q '[0-9]'; then |
| 93 | + echo "PR already open for $BRANCH — nothing to do." |
| 94 | + exit 0 |
| 95 | + fi |
| 96 | +
|
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | + git checkout -b "$BRANCH" |
| 100 | +
|
| 101 | + TITLE_PARTS=() |
| 102 | + BODY_LINES=() |
| 103 | +
|
| 104 | + if [ "$IOS_CHANGED" = "true" ]; then |
| 105 | + sed -i \ |
| 106 | + "s/stripe_version = '[^']*'/stripe_version = '${IOS_NEW}'/" \ |
| 107 | + stripe-react-native.podspec |
| 108 | + git add stripe-react-native.podspec |
| 109 | + TITLE_PARTS+=("stripe-ios ${IOS_NEW}") |
| 110 | + BODY_LINES+=("- \`stripe-react-native.podspec\`: \`stripe_version\` → \`${IOS_NEW}\` ([release notes](https://github.com/stripe/stripe-ios/releases/tag/${IOS_NEW}))") |
| 111 | + fi |
| 112 | +
|
| 113 | + if [ "$ANDROID_CHANGED" = "true" ]; then |
| 114 | + sed -i \ |
| 115 | + "s/^StripeSdk_stripeVersion=.*/StripeSdk_stripeVersion=${ANDROID_NEW}/" \ |
| 116 | + android/gradle.properties |
| 117 | + git add android/gradle.properties |
| 118 | + TITLE_PARTS+=("stripe-android ${ANDROID_NEW}") |
| 119 | + BODY_LINES+=("- \`android/gradle.properties\`: \`StripeSdk_stripeVersion\` → \`${ANDROID_NEW}\` ([release notes](https://github.com/stripe/stripe-android/releases/tag/v${ANDROID_NEW}))") |
| 120 | + fi |
| 121 | +
|
| 122 | + TITLE="chore: bump $(IFS=', '; echo "${TITLE_PARTS[*]}")" |
| 123 | +
|
| 124 | + BODY="$(IFS=$'\n'; echo "${BODY_LINES[*]}") |
| 125 | +
|
| 126 | +_Automated by [\`bump-native-sdks\`](.github/workflows/bump-native-sdks.yml)_" |
| 127 | + |
| 128 | + git commit -m "$TITLE" |
| 129 | + git push origin "$BRANCH" |
| 130 | + |
| 131 | + gh pr create \ |
| 132 | + --title "$TITLE" \ |
| 133 | + --body "$BODY" \ |
| 134 | + --base master \ |
| 135 | + --head "$BRANCH" |
0 commit comments