From 4ed873e4b791a7d49521888781e57a7ede488318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20B=C3=A9dard?= Date: Tue, 18 Jun 2024 16:10:41 -0400 Subject: [PATCH] ci: publish to cloudsmith and cocoapods --- .github/workflows/publish.yml | 279 +++++++++++++++++++++------------- Slauth.podspec | 10 +- wrappers/swift/build.sh | 2 +- 3 files changed, 182 insertions(+), 109 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9d045ac..684853e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,6 +1,7 @@ name: Publish Package on: + push: workflow_dispatch: inputs: beta: @@ -8,13 +9,18 @@ on: default: false required: true type: boolean + android: + description: Publish an android version (maven) + default: true + required: true + type: boolean rust: description: Publish a rust version (crates.io) default: true required: true type: boolean - android: - description: Publish an android version (maven) + swift: + description: Publish a swift version (cocoapods) default: true required: true type: boolean @@ -25,126 +31,193 @@ on: type: boolean jobs: - build-wasm: - environment: npm-publish - if: ${{ inputs.wasm }} - runs-on: ubuntu-latest + # build-wasm: + # environment: npm-publish + # if: ${{ inputs.wasm }} + # runs-on: ubuntu-latest + + # steps: + # - name: Checkout repo + # uses: actions/checkout@v4 + + # - name: Checkout action + # uses: actions/checkout@v4 + # with: + # repository: Devolutions/actions + # path: actions + # ref: v2 + # token: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} + + # - name: Setup wasm + # run: | + # curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + # wasm-pack --version + + # - name: Build + # run: sh build.sh + # working-directory: wrappers/wasm + + # - name: Upload artifact + # uses: actions/upload-artifact@v4 + # with: + # name: wasm + # path: dist/bundler + + # - name: Setup .npmrc config file + # uses: ./actions/npmrc-setup + # with: + # github_token: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} + + # - name: Publish + # run: npm publish --tag ${{ inputs.beta && 'beta' || 'latest' }} + # working-directory: dist/bundler + + # - run: rm $HOME/.npmrc + + # - name: Configure NPM + # run: npm config set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" + + # - name: Publish + # run: npm publish --tag ${{ inputs.beta && 'beta' || 'latest' }} + # working-directory: dist/bundler + + # - name: Update Artifactory Cache + # run: gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="slauth" + # env: + # GH_TOKEN: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} + + # build-android: + # environment: cloudsmith-publish + # if: ${{ inputs.android }} + # runs-on: ubuntu-latest + + # steps: + # - name: Checkout repo + # uses: actions/checkout@v4 + + # - name: Set up JDK 1.8 + # uses: actions/setup-java@v4 + # with: + # java-version: 8 + # distribution: adopt + + # - name: Setup Android + # run: | + # wget https://dl.google.com/android/repository/android-ndk-r23b-linux.zip + # unzip android-ndk-r23b-linux.zip + # export ANDROID_NDK_HOME=$GITHUB_WORKSPACE/android-ndk-r23b + # echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV + # echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH + # echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android" >> $GITHUB_ENV::LIBRARY_PATH + # echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android" >> $GITHUB_ENV::LD_LIBRARY_PATH + # rustup target add aarch64-linux-android + # rustup target add x86_64-linux-android + # rustup target add x86_64-unknown-linux-gnu + + # - name: Build + # run: sh wrappers/android/build.sh + + # - name: Create local.properties + # run: echo "sdk.dir=$ANDROID_HOME" > local.properties + + # - name: Allow gradlew to run + # run: chmod +x gradlew + + # - name: Package .aar + # run: ./gradlew clean assembleRelease + # env: + # CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} + # CLOUDSMITH_USERNAME: bot-devolutions + + # - run: ./gradlew publish + # env: + # CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} + # CLOUDSMITH_USERNAME: bot-devolutions + + # - name: Upload .aar artifact + # uses: actions/upload-artifact@v4 + # with: + # name: android + # path: wrappers/android/build/outputs/aar/slauth-release.aar + + # build-rust: + # environment: crates-publish + # if: ${{ inputs.rust }} + # runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v4 + + # - name: Publish + # run: cargo publish + # env: + # CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + build-swift: + environment: cocoapods-publish + runs-on: macos-latest steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Checkout action - uses: actions/checkout@v4 - with: - repository: Devolutions/actions - path: actions - ref: v2 - token: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} - - - name: Setup wasm + - name: Setup rust run: | - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - wasm-pack --version - - - name: Build - run: sh build.sh - working-directory: wrappers/wasm - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: wasm - path: dist/bundler - - - name: Setup .npmrc config file - uses: ./actions/npmrc-setup - with: - github_token: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} - - - name: Publish - run: npm publish --tag ${{ inputs.beta && 'beta' || 'latest' }} - working-directory: dist/bundler - - - run: rm $HOME/.npmrc + rustup target add aarch64-apple-ios + rustup target add x86_64-apple-ios + cargo install cargo-lipo - - name: Configure NPM - run: npm config set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" + - name: Build iOS libraries + run: sh wrappers/swift/build.sh - - name: Publish - run: npm publish --tag ${{ inputs.beta && 'beta' || 'latest' }} - working-directory: dist/bundler - - - name: Update Artifactory Cache - run: gh workflow run update-artifactory-cache.yml --repo Devolutions/scheduled-tasks --field package_name="slauth" - env: - GH_TOKEN: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }} - - build-android: - environment: cloudsmith-publish - if: ${{ inputs.android }} - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v4 + - name: Setup CocoaPods Trunk Token + run: | + echo -e "machine trunk.cocoapods.org\n login bot@devolutions.net\n password ${{ secrets.COCOAPODS_TRUNK_TOKEN }}" > ~/.netrc + chmod 0600 ~/.netrc - - name: Set up JDK 1.8 - uses: actions/setup-java@v4 - with: - java-version: 8 - distribution: adopt + - run: cat ~/.netrc - - name: Setup Android + - name: Verify CocoaPods Trunk Token run: | - wget https://dl.google.com/android/repository/android-ndk-r23b-linux.zip - unzip android-ndk-r23b-linux.zip - export ANDROID_NDK_HOME=$GITHUB_WORKSPACE/android-ndk-r23b - echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV - echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH - echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android" >> $GITHUB_ENV::LIBRARY_PATH - echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android" >> $GITHUB_ENV::LD_LIBRARY_PATH - rustup target add aarch64-linux-android - rustup target add x86_64-linux-android - rustup target add x86_64-unknown-linux-gnu - - - name: Build + pod trunk me || echo "Invalid token" + + - name: Setup version + id: version run: | - cd wrappers/android - sh build.sh + VERSION=$(grep -E "^\s*s\.version\s*=\s*['\"][0-9]+\.[0-9]+\.[0-9]+['\"]" Slauth.podspec | awk -F"[\"\']" '{print $2}') + echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Create local.properties + - name: Push to a new branch run: | - echo "sdk.dir=$ANDROID_HOME" > local.properties + git checkout --orphan release/cocoapods-v${{ steps.version.outputs.version }} + git rm -rf . + git checkout devops/cloudsmith-cocoapods -- LICENSE wrappers/swift/classes slauth.h Slauth.podspec - - run: chmod +x gradlew + git add LICENSE wrappers/swift/classes/** slauth.h Slauth.podspec + find target/universal/release -name "*.a" -exec git add {} \; + find target/x86_64-apple-ios/release -name "*.a" -exec git add {} \; + find target/aarch64-apple-ios/release -name "*.a" -exec git add {} \; - - name: Package .aar - run: ./gradlew clean assembleRelease - env: - CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} - CLOUDSMITH_USERNAME: bot-devolutions + git commit -m "Set up CocoaPods release branch" + git push origin release/cocoapods-v${{ steps.version.outputs.version }} - - run: ./gradlew publish + git tag '${{ steps.version.outputs.version }}' + git push --tags env: - CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} - CLOUDSMITH_USERNAME: bot-devolutions + GITHUB_TOKEN: ${{ github.token }} - - name: Upload .aar artifact - uses: actions/upload-artifact@v4 - with: - name: android - path: wrappers/android/build/outputs/aar/slauth-release.aar + # - name: Update Podspec + # run: sed -i '' "s|:branch => '.*'|:branch => 'release/cocoapods-v${{ steps.version.outputs.branch_name }}'|" Slauth.podspec - build-rust: - environment: crates-publish - if: ${{ inputs.rust }} - runs-on: ubuntu-latest + - name: Validate podspec + run: pod spec lint --skip-import-validation --use-libraries --allow-warnings - steps: - - uses: actions/checkout@v4 + # - name: Publish to CocoaPods + # run: pod trunk push Slauth.podspec --skip-import-validation --use-libraries --allow-warnings + # env: + # COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} - - name: Publish - run: cargo publish - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: Delete branch + run: | + git switch master + git branch -D release/cocoapods-v${{ steps.version.outputs.version }} diff --git a/Slauth.podspec b/Slauth.podspec index a0cab4e..aacdc07 100644 --- a/Slauth.podspec +++ b/Slauth.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'Slauth' s.version = '0.7.6' - s.summary = 'A Swift wrapper aroud Slauth Rust crate' + s.summary = 'A Swift wrapper around Slauth Rust crate' s.description = <<-DESC TODO: Add long description of the pod here. DESC @@ -9,11 +9,11 @@ TODO: Add long description of the pod here. s.homepage = 'https://github.com/Devolutions/Slauth.git' s.license = { :type => 'MIT', :file => './LICENSE' } s.author = { 'Devolutions' => 'lfauvel@devolutions.net' } - s.source = { :git => 'https://github.com/Devolutions/Slauth.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/Devolutions/Slauth.git', :tag => '0.0.0' } s.swift_version = '5.0' - s.ios.deployment_target = '11.0' - + s.ios.deployment_target = '17.0' + s.source_files = 'wrappers/swift/classes/**/*', 'slauth.h' - s.vendored_libraries = 'target/universal/release/*.a', 'target/x86_64-apple-io/release/*.a', 'target/aarch64-apple-ios/release/*.a' + s.vendored_libraries = 'target/universal/release/*.a', 'target/x86_64-apple-io/release/*.a', 'target/aarch64-apple-ios/release/*.a' end diff --git a/wrappers/swift/build.sh b/wrappers/swift/build.sh index 9713b30..71a000d 100755 --- a/wrappers/swift/build.sh +++ b/wrappers/swift/build.sh @@ -1,4 +1,4 @@ cargo lipo --release mv target/universal/release/libslauth.a target/universal/release/libslauth_universal.a mv target/x86_64-apple-ios/release/libslauth.a target/x86_64-apple-ios/release/libslauth_x86.a -mv target/aarch64-apple-ios/release/libslauth.a target/aarch64-apple-ios/release/libslauth_arm64.a \ No newline at end of file +mv target/aarch64-apple-ios/release/libslauth.a target/aarch64-apple-ios/release/libslauth_arm64.a