Guides
Migrating to BuildJet Cache
The BuildJet cache action is designed with user-friendliness at its core, no need to set up your own object storage or learn a new syntax. It is compatible with any runner - official, self-hosted, or BuildJet, and no matter the runner used, BuildJet doubles the free storage, providing 20 GB/repo/week storage space for free. Just like with GitHub Actions cache, when you consumed your free storage quota, we'll simply remove the oldest entry to make room for the new one.
To fully understand the reason why we built a GitHub Actions cache alternative, and its benefits read our launch post.
Migrating actions/cache
actions
Migrating to BuildJet's cache from actions/cache
is a straightforward process. The two caching systems are fully compatible; simply replace actions/cache
with buildjet/cache
in your workflow. Once done, you'll be able to leverage BuildJet's superior reliability and speed.
yaml1...-- uses: actions/cache@v3+- uses: buildjet/cache@v34with:5path: ~/.npm6key: buildjet-node-${{ hashFiles('**/package-lock.json') }}7restore-keys: |8buildjet-node-9...
Furthermore, if you're using actions/cache/restore
and actions/cache/save
, you simply need to replace with buildjet/cache/restore
or buildjet/cache/save
respectively.
As BuildJet is fully compatible with actions/cache
, we simply refer to the official documentation actions/cache documentation for the detailed instructions. You can find the official documentation here.
Migrating actions/setup-*
actions
BuildJet also provides a drop-in replacement for most popular setup actions. Today, BuildJet has compatible setup actions for setup-node, setup-python, setup-ruby, setup-java, setup-go and setup-dotnet. They all have the same syntax as their official counterparts, but uses BuildJet's reliable & fast cache under the hood.
Simply replace actions/setup-*
with buildjet/setup-*
in your workflow, and you're good to go. To fully take advantage of the new BuildJet cache in your setup action, make sure you enable caching in the setup action by setting the cache property to npm
(or pip
, gradle
, bundler
, etc.). Please check the documentation in of your setup action.
Please note that we only support the latest version of each setup action. If you're using an older version, you'll need to upgrade, or use the BuildJet cache directly.
For example (using setup-node
):
yaml1...2- name: Setup node-uses: actions/setup-node@v3+uses: buildjet/setup-node@v35with:6node-version: 14+cache: npm8...
If we don't support your setup action, or you're not using one, you can still use BuildJet's cache to cache your dependencies. You just specify the path to the directory you want to cache, and a key to identify the cache. Here is a list of examples for popular languages and tools, that don't have an official BuildJet setup-*
action.
Rust
Cargo
yaml1- uses: buildjet/cache@v32with:3path: |4~/.cargo/bin/5~/.cargo/registry/index/6~/.cargo/registry/cache/7~/.cargo/git/db/8target/9key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
PHP
Composer
yaml1- name: Get Composer Cache Directory2id: composer-cache3run: |4echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT5- uses: buildjet/cache@v36with:7path: ${{ steps.composer-cache.outputs.dir }}8key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}9restore-keys: |10${{ runner.os }}-composer-
Deno
yaml1- uses: buildjet/cache@v32with:3path: |4~/.deno5~/.cache/deno6key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
Swift
Carthage
yaml1- uses: buildjet/cache@v32with:3path: Carthage4key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}5restore-keys: |6${{ runner.os }}-carthage-
CocoaPods
yaml1- uses: buildjet/cache@v32with:3path: Pods4key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}5restore-keys: |6${{ runner.os }}-pods-
Swift Package Manager
yaml1- uses: buildjet/cache@v32with:3path: .build4key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}5restore-keys: |6${{ runner.os }}-spm-
Mint
yaml1env:2MINT_PATH: .mint/lib3MINT_LINK_PATH: .mint/bin4steps:5- uses: buildjet/cache@v36with:7path: .mint8key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}9restore-keys: |10${{ runner.os }}-mint-
Elixir
Mix
yaml1- uses: buildjet/cache@v32with:3path: |4deps5_build6key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}7restore-keys: |8${{ runner.os }}-mix-
Rebar3
yaml1- uses: buildjet/cache@v32with:3path: |4~/.cache/rebar35_build6key: ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-${{ hashFiles('**/*rebar.lock') }}7restore-keys: |8${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-
Flutter
yaml1- name: Set Flutter cache variables2shell: bash3id: set_flutter_cache_vars4run: |5echo "cache_key=flutter-${{runner.os}}-stable-${{env.FLUTTER_VERSION}}-${{runner.arch}}" >> $GITHUB_OUTPUT6cache_path="${{runner.tool_cache}}/flutter/stable-${{env.FLUTTER_VERSION}}-${{runner.arch}}"7echo "cache_path=$(echo ${cache_path} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT8- name: Cache Flutter9uses: buildjet/cache@v310with:11path: ${{steps.set_flutter_cache_vars.outputs.cache_path}}12key: ${{steps.set_flutter_cache_vars.outputs.cache_key}}-${{hashFiles('**/pubspec.lock')}}13restore-keys: |14${{steps.set_flutter_cache_vars.outputs.cache_key}}15- name: Setup Flutter16uses: subosito/flutter-action@v217with:18channel: stable19flutter-version: ${{env.FLUTTER_VERSION}}
Haskell
Cabal We cache the elements of the Cabal store separately, as the entirety of ~/.cabal
can grow very large for projects with many dependencies.
yaml1- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle2uses: buildjet/cache@v33with:4path: |5~/.cabal/packages6~/.cabal/store7dist-newstyle8key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze') }}9restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
Stack
yaml1- uses: buildjet/cache@v32name: Cache ~/.stack3with:4path: ~/.stack5key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}6restore-keys: |7${{ runner.os }}-stack-global-8- uses: buildjet/cache@v39name: Cache .stack-work10with:11path: .stack-work12key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}13restore-keys: |14${{ runner.os }}-stack-work-
R
renv
yaml1- name: Set RENV_PATHS_ROOT2shell: bash3run: |4echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV5- name: Install and activate renv6run: |7install.packages("renv")8renv::activate()9shell: Rscript {0}10- name: Get R and OS version11id: get-version12run: |13cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "")14cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")15shell: Rscript {0}16- name: Restore Renv package cache17uses: buildjet/cache@v318with:19path: ${{ env.RENV_PATHS_ROOT }}20key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}21restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-
Bazel
bazelisk
does not have be to separately downloaded and installed because it's already included in GitHub's ubuntu-latest
and macos-latest
base images.
yaml1- name: Cache Bazel2uses: buildjet/cache@v33with:4path: |5~/.cache/bazel6key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }}7restore-keys: |8${{ runner.os }}-bazel-
Migrating Docker Cache
Docker layer caching is a feature of Docker BuildKit that allows Docker to reuse the layers from previous builds, leading to much faster build times. However, if you're using Docker's experimental docker layer caching type=gha
, you may encounter instability and speed issues as it uses the same underlying storage as actions/cache
.
To improve your Docker layer caching performance and stability, we recommend using inline
caching in most cases.
Inline cache is stored in the registry, embedded into the main image, and is pulled alongside the main image. Because of the way the inline cache is organized, the inline cache only supports min mode, so if you want max mode, then you'll need to use the registry cache.
Here is an example workflow using the type=inline
to cache the Docker layers:
yaml1name: Build and push Docker image2on: push3jobs:4docker:5runs-on: buildjet-2vcpu-ubuntu-22046steps:7- name: Checkout8uses: actions/checkout@v3910- name: Set up Docker Buildx11uses: docker/setup-buildx-action@v21213- name: Login to Docker Hub14uses: docker/login-action@v215with:16username: ${{ secrets.DOCKERHUB_USERNAME }}17password: ${{ secrets.DOCKERHUB_TOKEN }}1819- name: Build and push20uses: docker/build-push-action@v421with:22context: .23push: true24tags: user/app:latest+cache-from: type=registry,ref=user/app:latest+cache-to: type=inline
Note that the first time you run this workflow, the cache will be empty, meaning that it will take a bit longer to build, as Docker will have to build all the layers from scratch. However, the next time you run the workflow, Docker will be able to reuse the layers from the previous build, leading to much faster build times.
Deleting BuildJet Cache Entries
When your free storage quota of 20GB/repo/week is consumed, BuildJet automatically removes the oldest cache entry to make room for new ones. However, manual deletion can help better manage your cache, especially when handling outdated or irrelevant data.
Manually Deleting Cache Entries
The BuildJet Cache is accessible to all GitHub Actions users, regardless of whether you're using BuildJet. This includes those on self-hosted or official runners. To extend cache management capabilities, we've introduced the buildjet/cache-delete
action. This action enables users to delete their cache entries without requiring a BuildJet sign-up. Moreover, it ensures authenticated and authorized deletions, safeguarding other users' cache entries from accidental deletion.
To manually delete an entry from the BuildJet cache, you simply need to add a .github/workflows/delete-buildjet-cache.yml
file to your repository with the following content:
yaml1name: Manually Delete BuildJet Cache2on:3workflow_dispatch:4inputs:5cache_key:6description: 'BuildJet Cache Key to Delete'7required: true8type: string9jobs:10manually-delete-buildjet-cache:11runs-on: buildjet-2vcpu-ubuntu-220412steps:13- name: Checkout14uses: actions/checkout@v315- uses: buildjet/cache-delete@v116with:17cache_key: ${{ inputs.cache_key }}
This workflow creates a manually-run action that can be executed from the Actions tab in your repository. Once this workflow has been added to your repository, navigate to the Actions tab, select the Delete BuildJet Cache workflow on the sidebar, and click the Run workflow button.
You will then be prompted to input the cache key you wish to delete. After inputting this cache key, the workflow will start, deleting the corresponding cache entry.
The cache key can be located in the logs of the workflow using the BuildJet cache. It should look like:
text1Run buildjet/cache@v32Received 11505181 of 24752374 (46.5%), 11.0 MBs/sec3Received 24752374 of 24752374 (100.0%), 14.0 MBs/sec4Cache Size: ~24 MB (24752374 B)5/usr/bin/tar -xf /home/runner/work/_temp/f6d0f5ad-56bc-487f-a047-6b5f483e40b8/cache.tzst -P -C /home/runner/work/cache-delete/cache-delete --use-compress-program unzstd6Cache restored successfully7Cache restored from key: Linux-npm-73339479b843f24de506811a29b7519e82adab1f40d83fecff88668fa0dc47ff
Simply copy the cache key from the logs and paste it into the input field when running the Delete BuildJet Cache
workflow.