Skip to content

Commit

Permalink
Add BuildJet Option (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
joroshiba committed Aug 1, 2023
1 parent 9de8f90 commit b00faf5
Show file tree
Hide file tree
Showing 10 changed files with 5,501 additions and 24 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,33 @@ jobs:
cargo test
cargo build --release
working-directory: tests
simple-buildjet:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

name: Test `cargo check/test` on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

env:
CARGO_TERM_COLOR: always

steps:
- uses: actions/checkout@v3

# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
- run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- uses: ./
with:
workspaces: tests
cache-provider: buildjet

- run: |
cargo check
cargo test
working-directory: tests
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ sensible defaults.
# Useful for jobs where the matrix is additive e.g. additional Cargo features.
# default: "true"
save-if: ""

# Specifies what to use as the backend providing cache
# Can be set to either "github" or "buildjet"
# default: "github"
cache-provider: ""
```

Further examples are available in the [.github/workflows](./.github/workflows/) directory.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ inputs:
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
required: false
default: "true"
cache-provider:
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
required: false
default: "github"
outputs:
cache-hit:
description: "A boolean value that indicates an exact match was found."
Expand Down
2,718 changes: 2,707 additions & 11 deletions dist/restore/index.js

Large diffs are not rendered by default.

2,718 changes: 2,707 additions & 11 deletions dist/save/index.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": {
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.1.2",
"@actions/cache": "^3.2.1",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
Expand Down
4 changes: 3 additions & 1 deletion src/restore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";

import { cleanTargetDir } from "./cleanup";
import { CacheConfig } from "./config";
import { getCacheHandler } from "./utils";

process.on("uncaughtException", (e) => {
core.error(e.message);
Expand All @@ -12,6 +12,8 @@ process.on("uncaughtException", (e) => {
});

async function run() {
const cache = getCacheHandler();

if (!cache.isFeatureAvailable()) {
setCacheHitOutput(false);
return;
Expand Down
4 changes: 3 additions & 1 deletion src/save.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import * as exec from "@actions/exec";

import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup";
import { CacheConfig, isCacheUpToDate } from "./config";
import { getCacheHandler } from "./utils";

process.on("uncaughtException", (e) => {
core.error(e.message);
Expand All @@ -13,6 +13,8 @@ process.on("uncaughtException", (e) => {
});

async function run() {
const cache = getCacheHandler();

const save = core.getInput("save-if").toLowerCase() || "true";

if (!(cache.isFeatureAvailable() && save === "true")) {
Expand Down
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as buildjetCache from "@actions/buildjet-cache";
import * as ghCache from "@actions/cache";
import * as core from "@actions/core";
import * as exec from "@actions/exec";

Expand Down Expand Up @@ -28,3 +30,17 @@ export async function getCmdOutput(
}
return stdout;
}

export function getCacheHandler() {
const cacheProvider = core.getInput("cache-provider");
switch (cacheProvider) {
case 'github':
core.info ("Using Github Cache.");
return ghCache;
case 'buildjet':
core.info ("Using Buildjet Cache.");
return buildjetCache;
default:
throw new Error("Only currently support github and buildjet caches");
}
}

0 comments on commit b00faf5

Please sign in to comment.