cd #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: cd | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Tag in SemVer format" | |
| required: true | |
| type: string | |
| jobs: | |
| validation: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate main branch | |
| if: github.ref_name != github.event.repository.default_branch | |
| run: | | |
| echo "Branch is not main" | |
| exit 0 | |
| - name: Validate tag | |
| run: | | |
| echo "${{ github.event.inputs.version }}" | grep -P '^[0-9]+\.[0-9]+\.[0-9]+' | |
| android: | |
| runs-on: ubuntu-latest | |
| needs: validation | |
| defaults: | |
| run: | |
| working-directory: ./android | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: "aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android,i686-linux-android" | |
| - name: Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| cache-on-failure: "true" | |
| - uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cargo-ndk | |
| - name: Setup Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "18" | |
| distribution: "temurin" | |
| cache: gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Import GPG key | |
| uses: crazy-max/ghaction-import-gpg@v6 | |
| with: | |
| gpg_private_key: ${{ secrets.MAVEN_GPG_KEY }} | |
| - name: Populate local.properties | |
| run: echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties | |
| # Package is tied to spruceid/mobile-sdk-rs, and it was unused so ignoring it for now | |
| # - name: Publish package to GHCR | |
| # run: ./gradlew publishReleasePublicationToGitHubPackagesRepository | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # VERSION: ${{ github.event.inputs.version }} | |
| - name: Publish package to Central | |
| run: ./gradlew publishReleasePublicationToCentralPortal | |
| env: | |
| MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| VERSION: ${{ github.event.inputs.version }} | |
| ios: | |
| runs-on: macos-latest | |
| needs: validation | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/create-github-app-token@v1 | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.MONOREPO_GH_APP_ID }} | |
| private-key: ${{ secrets.MONOREPO_GH_APP_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: | | |
| sprucekit-mobile | |
| - name: Get GitHub App User ID | |
| id: get-user-id | |
| run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - run: | | |
| git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
| git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: "aarch64-apple-ios-sim,aarch64-apple-ios,x86_64-apple-ios" | |
| - name: Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| cache-on-failure: "true" | |
| # - uses: taiki-e/install-action@v2 | |
| # with: | |
| # tool: cargo-swift | |
| # - name: Install unreleased version of cargo-swift | |
| # run: cargo install --git https://github.com/antoniusnaumann/cargo-swift | |
| - name: Install static version of cargo-swift | |
| run: cargo install cargo-swift@^0.9 | |
| - name: Generate Swift package | |
| run: cargo swift package -p ios -n MobileSdkRs --release | |
| working-directory: rust | |
| - name: Compress XCFramework | |
| run: | | |
| zip -9 -r RustFramework.xcframework.zip rust/MobileSdkRs/RustFramework.xcframework | |
| echo "XCF_CHECKSUM=`swift package compute-checksum RustFramework.xcframework.zip`" >> $GITHUB_ENV | |
| - name: Update Swift Package definition | |
| run: | | |
| sed -i '' 's/binaryTarget.*/binaryTarget(name: "RustFramework", url: "https:\/\/github.com\/spruceid\/sprucekit-mobile\/releases\/download\/${{ github.event.inputs.version }}\/RustFramework.xcframework.zip", checksum: "${{ env.XCF_CHECKSUM }}"),/' Package.swift | |
| # If this fails due to a new commit on the main branch, it's a feature not a bug! | |
| # This way, there will be no confusion around what was included in the release. | |
| - name: Push changes and tag | |
| id: commit | |
| run: | | |
| git add Package.swift | |
| git commit -m "Release ${{ github.event.inputs.version }}" | |
| git push | |
| git tag ${{ github.event.inputs.version }} -m "${{ github.event.inputs.version }}" | |
| git push --tags | |
| - name: Create release and attach XCFramework binary artifact | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| artifacts: "RustFramework.xcframework.zip" | |
| tag: ${{ github.event.inputs.version }} | |
| name: ${{ github.event.inputs.version }} | |
| - name: Revert changes to Package.swift for local development | |
| if: steps.commit.outcome == 'success' | |
| run: | | |
| git revert --no-edit HEAD | |
| git push |