Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BuildJet Option #154

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}