From 8f271c257514761bf5c3cef823be077df8c2b34f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 21 Aug 2024 16:51:30 -0700 Subject: [PATCH] Custom sccache support in CI --- .github/actions/setup/action.yml | 37 +++++++++++++++++++++++--------- .github/actions/setup/sccache.sh | 25 +++++++++++++++++++++ .github/workflows/build.yml | 12 ----------- 3 files changed, 52 insertions(+), 22 deletions(-) create mode 100755 .github/actions/setup/sccache.sh diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 09abb4ecb..2c11397b3 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -17,21 +17,38 @@ runs: with: python-version: "3.x" - - name: Set up sccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - variant: sccache - key: ${{ runner.os }}-${{ github.sha }} - restore-keys: ${{ runner.os }} - max-size: 10000M - - - name: Set up GNU make + - name: Install GNU make if: runner.os == 'macOS' shell: bash run: | brew install make echo 'GNUMAKE=gmake' >> "$GITHUB_ENV" + - name: Cache sccache + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.sccache + key: sccache-${{ runner.os }}-${{ github.sha }} + restore-keys: sccache-${{ runner.os }}- + + - name: Set up sccache + shell: bash + env: + SCCACHE_DIRECT: false + SCCACHE_DIR: ${{ github.workspace }}/.sccache + SCCACHE_CACHE_SIZE: 2G + SCCACHE_IDLE_TIMEOUT: 0 + run: | + bash $GITHUB_ACTION_PATH/sccache.sh + sccache --start-server + sccache -z + + - name: Show sccache stats + uses: gacts/run-and-post-run@v1 + with: + run: sccache -s + post: sccache -s + - name: Cache Gradle dependencies uses: actions/cache@v4 if: inputs.is-asset-build == 'true' @@ -73,5 +90,5 @@ runs: restore-keys: gradle-build-cache- - name: Set up NDK - run: python build.py -v ndk shell: bash + run: python build.py -v ndk diff --git a/.github/actions/setup/sccache.sh b/.github/actions/setup/sccache.sh new file mode 100755 index 000000000..95d3e1d85 --- /dev/null +++ b/.github/actions/setup/sccache.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Get latest sccache version +get_sccache_ver() { + curl -sL 'https://api.github.com/repos/mozilla/sccache/releases/latest' | jq -r .name +} + +# $1=variant +# $2=install_dir +# $3=exe +install_from_gh() { + local ver=$(curl -sL 'https://api.github.com/repos/mozilla/sccache/releases/latest' | jq -r .name) + local url="https://github.com/mozilla/sccache/releases/download/${ver}/sccache-${ver}-$1.tar.gz" + local dest="$2/$3" + curl -L "$url" | tar xz -O --wildcards "*/$3" > $dest + chmod +x $dest +} + +if [ $RUNNER_OS = "macOS" ]; then + brew install sccache +elif [ $RUNNER_OS = "Linux" ]; then + install_from_gh x86_64-unknown-linux-musl /usr/local/bin sccache +elif [ $RUNNER_OS = "Windows" ]; then + install_from_gh x86_64-pc-windows-msvc $USERPROFILE/.cargo/bin sccache.exe +fi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5bffb12fb..1f19e97d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,8 +18,6 @@ jobs: build: name: Build Magisk artifacts runs-on: macos-14 - env: - SCCACHE_DIRECT: false strategy: fail-fast: false steps: @@ -27,7 +25,6 @@ jobs: uses: actions/checkout@v4 with: submodules: "recursive" - fetch-depth: 0 - name: Setup environment uses: ./.github/actions/setup @@ -60,8 +57,6 @@ jobs: test-build: name: Test building on ${{ matrix.os }} runs-on: ${{ matrix.os }} - env: - SCCACHE_DIRECT: false strategy: fail-fast: false matrix: @@ -71,7 +66,6 @@ jobs: uses: actions/checkout@v4 with: submodules: "recursive" - fetch-depth: 0 - name: Setup environment uses: ./.github/actions/setup @@ -98,8 +92,6 @@ jobs: steps: - name: Check out uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Download build artifacts uses: actions/download-artifact@v4 @@ -140,8 +132,6 @@ jobs: steps: - name: Check out uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Download build artifacts uses: actions/download-artifact@v4 @@ -189,8 +179,6 @@ jobs: steps: - name: Check out uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Download build artifacts uses: actions/download-artifact@v4