Skip to content

Commit

Permalink
Custom sccache support in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Aug 21, 2024
1 parent 7cf56b4 commit 8f271c2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
37 changes: 27 additions & 10 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions .github/actions/setup/sccache.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ jobs:
build:
name: Build Magisk artifacts
runs-on: macos-14
env:
SCCACHE_DIRECT: false
strategy:
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0

- name: Setup environment
uses: ./.github/actions/setup
Expand Down Expand Up @@ -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:
Expand All @@ -71,7 +66,6 @@ jobs:
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0

- name: Setup environment
uses: ./.github/actions/setup
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f271c2

Please sign in to comment.