From 5ed943162eb8d3a88336cba3d190c0491270e2c6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 20 Nov 2024 14:59:42 +0700 Subject: [PATCH] chore: improve release & build artifacts workflow --- .github/workflows/build.yml | 107 ++++++++++++++++++++------------ .github/workflows/check-pr.yaml | 4 ++ .github/workflows/release.yaml | 80 +++++++++++++++++++----- .mac-setup.sh | 101 ++++++++++++++++++++---------- 4 files changed, 205 insertions(+), 87 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 993cf0b5..ea484e62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,22 +15,15 @@ on: commitSHA: description: "Commit SHA (leave blank for default branch)" required: false - machine: - description: "Machine to run on, e.g. macos-12, ubuntu-20.04" - required: false - default: "macos-12" - appleXcodeVersion: - description: "Apple Xcode version, e.g. Xcode_13.3.1.app" - required: false - default: "Xcode_13.3.1.app" - appleMacosxSdk: - description: "Apple MacOSX SDK, e.g. MacOSX12.3" - required: false - default: "MacOSX12.3" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.inputs.target }}-${{ github.event.inputs.commitSHA || github.ref }} + cancel-in-progress: true jobs: - build: - runs-on: ${{ github.event.inputs.machine }} + build-apple: + runs-on: macos-12 + if: github.event.inputs.target == 'apple' || github.event.inputs.target == 'all' steps: - name: Checkout Repository uses: actions/checkout@v4 @@ -48,42 +41,78 @@ jobs: - name: Build Setup run: make mac-setup - - - name: Build Android - if: github.event.inputs.target == 'android' || github.event.inputs.target == 'all' env: - APPLE_XCODE_APP_NAME: ${{ github.event.inputs.appleXcodeVersion }} - APPLE_MACOSX_SDK: ${{ github.event.inputs.appleMacosxSdk }} - run: make android - - - name: Upload Android Artifacts - uses: actions/upload-artifact@v3 - with: - name: android - path: ./release/android/*.tar.gz + TARGET: apple - name: Build Apple - if: github.event.inputs.target == 'apple' || github.event.inputs.target == 'all' env: - APPLE_XCODE_APP_NAME: ${{ github.event.inputs.appleXcodeVersion }} - APPLE_MACOSX_SDK: ${{ github.event.inputs.appleMacosxSdk }} + APPLE_XCODE_APP_NAME: Xcode_13.3.1.app + APPLE_MACOSX_SDK: MacOSX12.3 run: rm -f /usr/local/lib/libjpeg* ; make apple - name: Upload Apple Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: apple - path: ./release/apple/*.tar.gz + name: dotlottie-player.darwin.tar.gz + path: release/apple/dotlottie-player.darwin.tar.gz + if-no-files-found: error - - name: Build WASM - if: github.event.inputs.target == 'wasm' || github.event.inputs.target == 'all' + build-android: + runs-on: macos-latest + if: github.event.inputs.target == 'android' || github.event.inputs.target == 'all' + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.commitSHA || github.ref }} + + - uses: Homebrew/actions/setup-homebrew@master + - uses: ningenMe/setup-rustup@v1.1.0 + + - name: Install Make + run: brew install make + + - name: Build Setup + run: make mac-setup env: - APPLE_XCODE_APP_NAME: ${{ github.event.inputs.appleXcodeVersion }} - APPLE_MACOSX_SDK: ${{ github.event.inputs.appleMacosxSdk }} + TARGET: android + + - name: Build Android + run: make android + + - name: Upload Android Artifacts + uses: actions/upload-artifact@v4 + with: + name: dotlottie-player.android.tar.gz + path: release/android/dotlottie-player.android.tar.gz + if-no-files-found: error + + build-wasm: + runs-on: macos-latest + if: github.event.inputs.target == 'wasm' || github.event.inputs.target == 'all' + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.commitSHA || github.ref }} + + - uses: Homebrew/actions/setup-homebrew@master + - uses: ningenMe/setup-rustup@v1.1.0 + + - name: Install Make + run: brew install make + + - name: Build Setup + run: make mac-setup + env: + TARGET: wasm + + - name: Build WASM run: make wasm - name: Upload WASM Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: wasm - path: ./release/wasm/*.tar.gz + name: dotlottie-player.wasm.tar.gz + path: release/wasm/dotlottie-player.wasm.tar.gz + if-no-files-found: error diff --git a/.github/workflows/check-pr.yaml b/.github/workflows/check-pr.yaml index 8761d718..03177e98 100644 --- a/.github/workflows/check-pr.yaml +++ b/.github/workflows/check-pr.yaml @@ -6,6 +6,10 @@ on: push: branches: [main] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: check-pr: if: github.head_ref != 'release' diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c512270b..bfc4487f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,12 +1,18 @@ name: Release + on: pull_request: types: [closed] branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - build-artifacts: - if: github.head_ref == 'release' && github.event.pull_request.merged == true + build-apple: runs-on: macos-12 + if: github.head_ref == 'release' && github.event.pull_request.merged == true steps: - uses: actions/checkout@v4 - uses: Homebrew/actions/setup-homebrew@master @@ -14,36 +20,82 @@ jobs: with: xcode-version: "13.3.1" - uses: ningenMe/setup-rustup@v1.1.0 + - name: Install Make run: brew install make + - name: Build Setup run: make mac-setup - - name: Build Artifacts + env: + TARGET: apple + + - name: Build Apple env: APPLE_XCODE_APP_NAME: Xcode_13.3.1.app APPLE_MACOSX_SDK: MacOSX12.3 - run: make all - - name: Upload Artifact - uses: actions/upload-artifact@v4.0.0 - with: - name: dotlottie-player.android.tar.gz - path: release/android/dotlottie-player.android.tar.gz - if-no-files-found: error - - name: Upload Artifact - uses: actions/upload-artifact@v4.0.0 + run: rm -f /usr/local/lib/libjpeg* ; make apple + + - name: Upload Apple Artifacts + uses: actions/upload-artifact@v4 with: name: dotlottie-player.darwin.tar.gz path: release/apple/dotlottie-player.darwin.tar.gz if-no-files-found: error - - name: Upload Artifact + + build-android: + runs-on: macos-latest + if: github.head_ref == 'release' && github.event.pull_request.merged == true + steps: + - uses: actions/checkout@v4 + - uses: Homebrew/actions/setup-homebrew@master + - uses: ningenMe/setup-rustup@v1.1.0 + + - name: Install Make + run: brew install make + + - name: Build Setup + run: make mac-setup + env: + TARGET: android + + - name: Build Android + run: make android + + - name: Upload Android Artifacts uses: actions/upload-artifact@v4.0.0 + with: + name: dotlottie-player.android.tar.gz + path: release/android/dotlottie-player.android.tar.gz + if-no-files-found: error + + build-wasm: + runs-on: macos-latest + if: github.head_ref == 'release' && github.event.pull_request.merged == true + steps: + - uses: actions/checkout@v4 + - uses: Homebrew/actions/setup-homebrew@master + - uses: ningenMe/setup-rustup@v1.1.0 + + - name: Install Make + run: brew install make + + - name: Build Setup + run: make mac-setup + env: + TARGET: wasm + + - name: Build WASM + run: make wasm + + - name: Upload WASM Artifacts + uses: actions/upload-artifact@v4 with: name: dotlottie-player.wasm.tar.gz path: release/wasm/dotlottie-player.wasm.tar.gz if-no-files-found: error release: - needs: [build-artifacts] + needs: [build-apple, build-android, build-wasm] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.mac-setup.sh b/.mac-setup.sh index 937e09f7..d450c6a5 100755 --- a/.mac-setup.sh +++ b/.mac-setup.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +TARGET=${TARGET:-all} + +echo "Target: ${TARGET}" + SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" # Formatting @@ -42,57 +46,86 @@ check_for rustup "https://rustup.rs" "\ 1. Choose the ${GREEN}default${NC} installation option 2. Either logout & login after the installation, or execute: ${YELLOW}source \"\$HOME/.cargo/env\"" -echo "Installing v1.4.1 of Meson..." -curl https://raw.githubusercontent.com/Homebrew/homebrew-core/2f89922685ce82af272fe045178f63bfb3bc7289/Formula/m/meson.rb > meson.rb +echo "Installing v1.6.0 of Meson..." +curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8ae7edfa2242b04dc01562dcb4536df60191593c/Formula/m/meson.rb > meson.rb brew install meson.rb echo "Installing brew package(s) ..." -brew install android-ndk \ - cmake \ +brew install cmake \ nasm \ ninja \ pkg-config \ + conan \ ktlint \ - swiftformat \ - conan + swiftformat + +if [[ "${TARGET}" == "android" || "${TARGET}" == "all" ]]; then + brew install android-ndk +fi rustup component add rust-src echo echo "Installing rust target(s) ..." -rustup target add aarch64-linux-android \ - armv7-linux-androideabi \ - x86_64-linux-android \ - i686-linux-android \ - aarch64-apple-darwin \ - x86_64-apple-darwin \ - aarch64-apple-ios \ - x86_64-apple-ios \ - aarch64-apple-ios-sim \ - wasm32-unknown-emscripten - -echo "Installing nightly toolchain" -rustup install nightly -rustup component add rust-src --toolchain nightly -rustup target add wasm32-unknown-emscripten --toolchain nightly - -echo -echo "Installing cargo dependencies" -cargo install uniffi-bindgen-cpp \ - --git https://github.com/NordSecurity/uniffi-bindgen-cpp \ - --tag "${UNIFFI_BINDGEN_CPP_VERSION}" +case "${TARGET}" in + android) + rustup target add aarch64-linux-android \ + armv7-linux-androideabi \ + x86_64-linux-android \ + i686-linux-android + ;; + apple) + rustup target add aarch64-apple-darwin \ + x86_64-apple-darwin \ + aarch64-apple-ios \ + x86_64-apple-ios \ + aarch64-apple-ios-sim + ;; + wasm) + rustup target add wasm32-unknown-emscripten + ;; + all) + rustup target add aarch64-linux-android \ + armv7-linux-androideabi \ + x86_64-linux-android \ + i686-linux-android \ + aarch64-apple-darwin \ + x86_64-apple-darwin \ + aarch64-apple-ios \ + x86_64-apple-ios \ + aarch64-apple-ios-sim \ + wasm32-unknown-emscripten + ;; + *) + echo "${RED}Invalid target specified: ${TARGET}${NC}" + exit 1 + ;; +esac echo echo "Setting up project ..." make deps -echo -echo "Setting up emsdk" -cd "${SCRIPT_DIR}/deps/modules/emsdk" || die "Could not find Emscripten SDK under ${RED}deps/modules/emsdk${NC}!" -./emsdk install "${EMSDK_VERSION}" -./emsdk activate "${EMSDK_VERSION}" -cd "${SCRIPT_DIR}/deps/modules/emsdk/upstream/emscripten" || die "Could not find Emscripten under ${RED}deps/modules/emsdk/upstream/emscripten${NC}!" -npm install +if [[ "${TARGET}" == "wasm" || "${TARGET}" == "all" ]]; then + echo "Installing nightly toolchain" + rustup install nightly + rustup component add rust-src --toolchain nightly + rustup target add wasm32-unknown-emscripten --toolchain nightly + + echo + echo "Installing cargo dependencies" + cargo install uniffi-bindgen-cpp \ + --git https://github.com/NordSecurity/uniffi-bindgen-cpp \ + --tag "${UNIFFI_BINDGEN_CPP_VERSION}" + + echo + echo "Setting up emsdk" + cd "${SCRIPT_DIR}/deps/modules/emsdk" || die "Could not find Emscripten SDK under ${RED}deps/modules/emsdk${NC}!" + ./emsdk install "${EMSDK_VERSION}" + ./emsdk activate "${EMSDK_VERSION}" + cd "${SCRIPT_DIR}/deps/modules/emsdk/upstream/emscripten" || die "Could not find Emscripten under ${RED}deps/modules/emsdk/upstream/emscripten${NC}!" + npm install +fi echo echo "Disabling unneeded webp features"