diff --git a/.github/workflows/update-android-sdk.yml b/.github/workflows/update-android-sdk.yml new file mode 100644 index 0000000..ba1cb44 --- /dev/null +++ b/.github/workflows/update-android-sdk.yml @@ -0,0 +1,80 @@ +name: Update Android SDK + +on: + workflow_dispatch: + inputs: + version: + description: "Android SDK version (e.g., 3.17.0)" + required: true + type: string + workflow_call: + inputs: + version: + description: "Android SDK version (e.g., 3.17.0)" + required: true + type: string + secrets: + token: + required: true + +jobs: + update-android-sdk: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Determine version + id: version + env: + INPUT_VERSION: ${{ inputs.version }} + run: | + VERSION="${INPUT_VERSION#v}" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "branch=chore/update-android-sdk-${VERSION}" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v4 + with: + ref: master + repository: atomicfi/atomic-transact-react-native + token: ${{ secrets.token || secrets.GITHUB_TOKEN }} + + - name: Update Android SDK version + env: + VERSION: ${{ steps.version.outputs.version }} + run: ./scripts/update-android-sdk.sh "$VERSION" + + - name: Check for changes + id: changes + run: | + if git diff --quiet && git diff --cached --quiet; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" + else + echo "has_changes=true" >> "$GITHUB_OUTPUT" + fi + + - name: Create Pull Request + if: steps.changes.outputs.has_changes == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.version.outputs.version }} + BRANCH: ${{ steps.version.outputs.branch }} + run: | + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git checkout -b "$BRANCH" + git add android/build.gradle + git commit -m "chore: upgrade Android SDK to ${VERSION}" + git push origin "$BRANCH" + + gh pr create \ + --title "chore: upgrade Android SDK to ${VERSION}" \ + --body "Automated upgrade of Android SDK Maven dependency to version ${VERSION}. + + **Release notes**: https://github.com/atomicfi/atomic-transact-android/releases/tag/${VERSION}" \ + --base master \ + --head "$BRANCH" \ + --reviewer atomicfi/sdk diff --git a/scripts/update-android-sdk.sh b/scripts/update-android-sdk.sh new file mode 100755 index 0000000..1a39386 --- /dev/null +++ b/scripts/update-android-sdk.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -euo pipefail + +# Updates the Android SDK (Maven) dependency version in build.gradle. +# Usage: ./scripts/update-android-sdk.sh +# Example: ./scripts/update-android-sdk.sh 3.17.0 + +VERSION="${1:?Usage: $0 }" + +# Strip leading 'v' if present +VERSION="${VERSION#v}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" +BUILD_GRADLE="${PROJECT_DIR}/android/build.gradle" + +if [ ! -f "$BUILD_GRADLE" ]; then + echo "Error: build.gradle not found at ${BUILD_GRADLE}" >&2 + exit 1 +fi + +CURRENT_VERSION=$(sed -n 's/.*def transact_version = "\([^"]*\)".*/\1/p' "$BUILD_GRADLE") + +if [ "$CURRENT_VERSION" = "$VERSION" ]; then + echo "Already at version ${VERSION}. Skipping." + exit 0 +fi + +echo "Updating Android SDK from ${CURRENT_VERSION} to ${VERSION}..." + +sed -i '' "s/def transact_version = \"${CURRENT_VERSION}\"/def transact_version = \"${VERSION}\"/" "$BUILD_GRADLE" + +# Verify the update +NEW_VERSION=$(sed -n 's/.*def transact_version = "\([^"]*\)".*/\1/p' "$BUILD_GRADLE") +if [ "$NEW_VERSION" != "$VERSION" ]; then + echo "Error: Version update failed. Expected ${VERSION}, got ${NEW_VERSION}" >&2 + exit 1 +fi + +echo "Android SDK updated to version ${VERSION} successfully."