diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae6899b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +name: CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + push: + branches: + - main + +concurrency: + group: '${{ github.workflow }}-${{ github.ref_name }}' + cancel-in-progress: true + +jobs: + ci: + name: CI + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-13] + + runs-on: ${{matrix.os}} + container: ${{ matrix.os == 'ubuntu-latest' && 'ghcr.io/f3d-app/f3d-superbuild-ci' || null }} + + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + path: 'source' + fetch-depth: 0 + + - name: Checkout HelloWorld + uses: actions/checkout@v4 + with: + repository: f3d-app/HelloWorld + path: HelloWorld + ref: v2.0.1 + + - name: Install tools Windows + if: runner.os == 'Windows' + shell: cmd + run: choco install ninja + + - name: Setup msvc Windows + if: runner.os == 'Windows' + uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x64 + + - name: Use sccache action + uses: ./source/ + with: + key: MyKey-0 + + - name: Setup directories + working-directory: ${{github.workspace}}/HelloWorld + shell: bash + run: mkdir build + + - name: Configure + working-directory: ${{github.workspace}}/HelloWorld/build + shell: bash + run: > + cmake ../ + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + -DCMAKE_C_COMPILER_LAUNCHER=sccache + ${{ runner.os == 'Windows' && '-G Ninja' || null }} + + - name: Build + working-directory: ${{github.workspace}}/HelloWorld/build + shell: bash + run: cmake --build . + + - name: Show and check sccache + shell: bash + run: | + sccache --show-stats + sccache --show-stats | grep "Compile requests executed" | grep 1 | grep '' diff --git a/README.md b/README.md index 28dbb89..abffc27 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # sccache-setup-action + A github action to install and setup sccache to speed up your builds + +It installs (on Windows using `choco` and on MacOS using `brew`), recover a cached sccache cache using the github cache action +then setup and run a sccache server. + +On Linux, it assumes sccache is available. + +Example usage: + +``` + - name: Install and setup sccache + uses: f3d-app/sccache-setup-action@v1 + with: + key: MyKey-0 +``` + +Then during the configuration of your build, add sccache as a launcher, eg, for CMake: + +``` + - name: Configure + working-directory: ${{github.workspace}}/build + shell: bash + run: > + cmake ../source + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + -DCMAKE_C_COMPILER_LAUNCHER=sccache +``` + +Resulting caches can be seen in your actions tab. + +To check the sccache action is behaving as expected, it is possible to add the following at the end of your job: + +``` + - name: Stop and check sccache + shell: bash + run: sccache --show-stats +``` + +Please note sccache does not work with Visual Studio Generator on Windows but requires ninja-build in that case: +https://github.com/mozilla/sccache/issues/957 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..35d445d --- /dev/null +++ b/action.yml @@ -0,0 +1,42 @@ +name: 'Install and Setup sccache' +description: 'Install and setup sccache' +branding: + icon: 'arrow-up' + color: 'green' +inputs: + key: + description: 'Cache key to differentiate between caches' + required: true + +runs: + using: "composite" + steps: + + - name: Install sccache Windows + if: runner.os == 'Windows' + shell: cmd + run: choco install sccache + + - name: Install sccache MacOS + if: runner.os == 'macOS' + shell: bash + run: brew install sccache + + - name: Initialize sccache environnement + shell: bash + run: | + sccache --start-server + echo SCCACHE_CACHE=$(sccache --show-stats | grep Local | cut -d '"' -f2) >> $GITHUB_ENV + echo DATE_STRING=$(date +'%Y%m%d') >> $GITHUB_ENV + sccache --stop-server + + - name: Recover sccache cache + uses: actions/cache@v4 + with: + path: ${{env.SCCACHE_CACHE}} + key: sccache-cache-${{inputs.key}}-${{env.DATE_STRING}} + restore-keys: sccache-cache-${{inputs.key}} + + - name: Start sccache + shell: bash + run: sccache --start-server