Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 1fcd20d

Browse files
committed
Skip tool cache if corresponding input is disabled
1 parent bde3069 commit 1fcd20d

File tree

6 files changed

+112
-24
lines changed

6 files changed

+112
-24
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- run: npm run test
1919

2020
install_from_tool_cache:
21+
needs: test
2122
runs-on: ${{ matrix.os }}
2223
strategy:
2324
matrix:
@@ -26,6 +27,18 @@ jobs:
2627
- ubuntu-16.04
2728
- macOS-latest
2829
- windows-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Install sccache
33+
uses: ./
34+
with:
35+
crate: sccache
36+
use-tool-cache: true
37+
- run: sccache --help
38+
39+
disabled_tool_cache:
40+
needs: test
41+
runs-on: ubuntu-latest
2942
steps:
3043
- uses: actions/checkout@v2
3144
- name: Install sccache
@@ -35,11 +48,13 @@ jobs:
3548
- run: sccache --help
3649

3750
install_missing_from_tool_cache:
51+
needs: test
3852
runs-on: ubuntu-latest
3953
steps:
4054
- uses: actions/checkout@v2
4155
- name: Install bat
4256
uses: ./
4357
with:
4458
crate: bat
59+
use-tool-cache: true
4560
- run: bat package.json

README.md

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,32 @@
88

99
This GitHub Action provides faster version of the `cargo install` command.
1010

11-
⚠ ️**NOTE: Work on this Action is still in progress, no guarantees on stability, correctness or security are provided right now.**
11+
⚠ ️**NOTE: This is an experimental Action.**
1212

1313
**Table of Contents**
1414

1515
* [How does this works?](#how-does-it-work)
1616
* [Example workflow](#example-workflow)
1717
* [Inputs](#inputs)
18-
* [Security considerations](#security-considerations)
18+
* [Tool cache](#tool-cache)
19+
* [Security considerations](#security-considerations)
20+
* [GitHub cache](#github-cache)
1921
* [License](#license)
2022
* [Contribute and support](#contribute-and-support)
2123

2224
## How does it work?
2325

24-
1. Most popular binary crates used in Rust CI are selected for the speed-up installation
25-
2. They are compiled directly at GitHub virtual environments
26-
3. Then they are uploaded into the external storage
27-
4. When you use this Action to install one of these crates,
28-
it will be downloaded from this cache storage
29-
5. If crate was not found in the cache storage, usual `cargo install` will be invoked instead.
26+
Before calling your usual `cargo install` command, this Action
27+
attempts to download pre-build binary crate file from the binary crates cache.\
28+
See [Security considerations](#security-considerations) to read more
29+
about potential caveats and usage policy.
30+
31+
If requested crate does not exist in the crates cache storage,
32+
this Action will fall back to the usual `cargo install`.
33+
34+
As soon as [actions-rs/meta#21](https://github.com/actions-rs/meta/issues/21) will be implemented,
35+
this Action will also cache compiled binary in the GitHub cache.
3036

31-
As soon as https://github.com/actions-rs/meta/issues/21 will be implemented,
32-
this Action will also cache resulting binary in the GitHub cache after compilation.
3337

3438
## Example workflow
3539

@@ -53,18 +57,41 @@ jobs:
5357
5458
## Inputs
5559
56-
| Name | Required | Description | Type | Default |
57-
| ------------ | :------: | -------------------------| ------ | --------|
58-
| `crate` | ✓ | Binary crate name | string | |
59-
| `version` | | Crate version to install | string | latest |
60+
| Name | Required | Description | Type | Default |
61+
| ---------------- | :------: | ------------------------------------------------ | ------ | --------|
62+
| `crate` | ✓ | Binary crate name | string | |
63+
| `version` | | Crate version to install | string | latest |
64+
| `use-tool-cache` | | Use pre-compiled crates to speed-up installation | bool | false |
65+
66+
## Tool cache
67+
68+
As it was mentioned in [How does it work?](#how-does-it-work) section,
69+
this Action can use external cache with the pre-compiled crates in it.
70+
71+
In order to use it, you need to **explicitly** enable `use-tool-cache` input:
72+
73+
```yaml
74+
- uses: actions-rs/install@master
75+
with:
76+
crate: cargo-audit
77+
version: latest
78+
use-tool-cache: true
79+
```
80+
81+
Before enabling this input, you should acknowledge security risks
82+
of executing pre-compiled binaries in your CI workflows.
83+
84+
### Security considerations
6085

61-
## Security considerations
86+
Check the [`tool-cache`](https://github.com/actions-rs/tool-cache/) repo
87+
to under understand how binary crates are built, signed and uploaded to the external cache.
6288

63-
You should acknowledge that in order to speed up the crates installation,
64-
this Action uses pre-built binaries stored in the external storage.
89+
This Action downloads both binary file and its signature.\
90+
Signature validation is proceeded by `openssl` and public key (`public.pem`)
91+
of the same certificate used for signing files at `tool-cache` repo.
6592

66-
Before using this Action consider checking the [Security considerations](https://github.com/actions-rs/tool-cache/blob/master/README.md#security-considerations) chapter
67-
of the tool cache builder to understand how this might affect you.
93+
If signature validation fails, binary file is removed immediately,
94+
warning issued and fall back to the `cargo install` call happens.
6895

6996
## License
7097

action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ inputs:
1212
description: Specify a version to install
1313
required: false
1414
default: 'latest'
15-
16-
# These inputs are not used/implemented yet
1715
use-tool-cache:
1816
description: Use tool cache to speed up installation (not used yet)
1917
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/input.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ import { input } from "@actions-rs/core";
88
export interface Input {
99
crate: string;
1010
version: string;
11+
useToolCache: boolean;
12+
useCache: boolean;
1113
}
1214

1315
export function get(): Input {
1416
const crate = input.getInput("crate", { required: true });
1517
const version = input.getInput("version", { required: true });
18+
const useToolCache = input.getInputBool("use-tool-cache") || false;
19+
const useCache = input.getInputBool("use-cache") || true;
1620

1721
return {
1822
crate: crate,
1923
version: version,
24+
useToolCache: useToolCache,
25+
useCache: useCache,
2026
};
2127
}

src/main.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,52 @@ import { Cargo } from "@actions-rs/core";
44
import * as input from "./input";
55
import * as download from "./download";
66

7-
export async function run(crate: string, version: string): Promise<void> {
7+
interface Options {
8+
useToolCache: boolean;
9+
useCache: boolean;
10+
}
11+
12+
async function downloadFromToolCache(
13+
crate: string,
14+
version: string
15+
): Promise<void> {
816
try {
917
await download.downloadFromCache(crate, version);
1018
} catch (error) {
1119
core.warning(
1220
`Unable to download ${crate} == ${version} from the tool cache: ${error}`
1321
);
22+
throw error;
23+
}
24+
}
25+
26+
export async function run(
27+
crate: string,
28+
version: string,
29+
options: Options
30+
): Promise<void> {
31+
try {
32+
if (options.useToolCache) {
33+
try {
34+
core.info(
35+
"Tool cache is explicitly enabled via the Action input"
36+
);
37+
core.startGroup("Downloading from the tool cache");
38+
39+
return await downloadFromToolCache(crate, version);
40+
} finally {
41+
core.endGroup();
42+
}
43+
} else {
44+
core.info(
45+
"Tool cache is disabled in the Action inputs, skipping it"
46+
);
47+
48+
throw new Error(
49+
"Faster installation options either failed or disabled"
50+
);
51+
}
52+
} catch (error) {
1453
core.info("Falling back to the `cargo install` command");
1554
const cargo = await Cargo.get();
1655
await cargo.installCached(crate, version);
@@ -21,7 +60,10 @@ async function main(): Promise<void> {
2160
try {
2261
const actionInput = input.get();
2362

24-
await run(actionInput.crate, actionInput.version);
63+
await run(actionInput.crate, actionInput.version, {
64+
useToolCache: actionInput.useToolCache,
65+
useCache: actionInput.useCache,
66+
});
2567
} catch (error) {
2668
core.setFailed(error.message);
2769
}

0 commit comments

Comments
 (0)