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

Commit a02b8c4

Browse files
committed
Better logs and readme
1 parent 53e8d2f commit a02b8c4

File tree

5 files changed

+128
-10
lines changed

5 files changed

+128
-10
lines changed

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
1-
This repo is an ongoing attempt to do some thing.
1+
# `cargo-install` Action
22

3-
Do not use it.
3+
[![Sponsoring](https://img.shields.io/badge/Support%20it-Say%20%22Thank%20you!%22-blue)](https://actions-rs.github.io/#sponsoring)
4+
![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)
5+
[![Gitter](https://badges.gitter.im/actions-rs/community.svg)](https://gitter.im/actions-rs/community)
6+
![Continuous integration](https://github.com/actions-rs/install/workflows/Continuous%20integration/badge.svg)
7+
![Dependabot enabled](https://api.dependabot.com/badges/status?host=github&repo=actions-rs/toolchain)
8+
9+
This GitHub Action provides faster version of the `cargo install` command.
10+
11+
⚠ ️**NOTE: Work on this Action is still in progress, no guarantees on stability, correctness or security are provided right now.**
12+
13+
**Table of Contents**
14+
15+
* [How does this works?](#how-does-it-work)
16+
* [Example workflow](#example-workflow)
17+
* [Inputs](#inputs)
18+
* [Security considerations](#security-considerations)
19+
* [License](#license)
20+
* [Contribute and support](#contribute-and-support)
21+
22+
## How does it work?
23+
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.
30+
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.
33+
34+
## Example workflow
35+
36+
```yaml
37+
on: [push]
38+
39+
name: build
40+
41+
jobs:
42+
check:
43+
name: Rust project
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- uses: actions-rs/install@master
48+
with:
49+
crate: cargo-audit
50+
version: latest
51+
- run: cargo audit
52+
```
53+
54+
## Inputs
55+
56+
| Name | Required | Description | Type | Default |
57+
| ------------ | :------: | -------------------------| ------ | --------|
58+
| `crate` | ✓ | Binary crate name | string | |
59+
| `version` | | Crate version to install | string | latest |
60+
61+
## Security considerations
62+
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.
65+
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.
68+
69+
## License
70+
71+
This Action is distributed under the terms of the MIT license, see [LICENSE](https://github.com/actions-rs/toolchain/blob/master/LICENSE) for details.
72+
73+
## Contribute and support
74+
75+
Any contributions are welcomed!
76+
77+
If you want to report a bug or have a feature request,
78+
check the [Contributing guide](https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md).
79+
80+
You can also support author by funding the ongoing project work,
81+
see [Sponsoring](https://actions-rs.github.io/#sponsoring).

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.

package-lock.json

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rust-cargo-install",
33
"version": "0.0.0",
4-
"description": "Install a Rust binary as fast as possible",
4+
"description": "Install a Rust binary crate as fast as possible",
55
"main": "lib/main.js",
66
"scripts": {
77
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify",
@@ -31,7 +31,8 @@
3131
"@actions-rs/core": "0.0.9",
3232
"@actions/core": "^1.2.3",
3333
"@actions/http-client": "^1.0.6",
34-
"@actions/tool-cache": "^1.3.3"
34+
"@actions/tool-cache": "^1.3.3",
35+
"which": "^2.0.2"
3536
},
3637
"devDependencies": {
3738
"@types/jest": "^25.1.4",

src/download.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ function getExt(): string {
3232
}
3333

3434
async function resolveVersion(crate: string): Promise<string> {
35-
// TODO: Better user-agent
3635
const url = `https://crates.io/api/v1/crates/${crate}`;
37-
const client = new http.HttpClient("actions-rs/install");
36+
const client = new http.HttpClient("@actions-rs (https://github.com/actions-rs/)");
3837

3938
const resp: any = await client.getJson(url);
4039
if (resp.result == null) {
@@ -45,6 +44,19 @@ async function resolveVersion(crate: string): Promise<string> {
4544
}
4645

4746
function buildUrl(crate: string, version: string): string {
47+
/**
48+
* !!! READ THIS IMPORTANT NOTICE !!!
49+
*
50+
* In case you want to use that binary cache bucket
51+
* for your purposes, please, don't do that.
52+
*
53+
* It is strictly private and intended to be used
54+
* by `@actions-rs` only.
55+
* There are no stable folders, naming structure,
56+
* bucket name or even the AWS region used.
57+
* You are not doing yourself better
58+
* by trying to trick everyone, just stop right now.
59+
*/
4860
const s3Region = "us-east-2";
4961
const s3Bucket = "actions-rs.install.binary-cache";
5062
const runner = getRunner();
@@ -56,6 +68,7 @@ function buildUrl(crate: string, version: string): string {
5668
function targetPath(crate: string): string {
5769
const ext = getExt();
5870
const filename = `${crate}${ext}`;
71+
5972
return path.join(os.homedir(), ".cargo", "bin", filename);
6073
}
6174

@@ -64,16 +77,22 @@ export async function downloadFromCache(
6477
version: string
6578
): Promise<void> {
6679
if (version == "latest") {
80+
core.debug(`Latest version requested for ${crate}, querying crates.io`);
6781
version = await resolveVersion(crate);
82+
core.info(`Newest ${crate} version available at crates.io: ${version}`);
6883
}
6984
const url = buildUrl(crate, version);
7085
const path = targetPath(crate);
7186

87+
core.debug(`Constructed S3 URL for ${crate}: ${url}`);
88+
core.info(`Downloading ${crate} == ${version} into ${path}`);
89+
7290
try {
7391
await fs.access(path);
7492

7593
core.warning(`Crate ${crate} already exist at ${path}`);
7694
} catch (error) {
95+
core.debug(`Downloading ${url} into ${path}`);
7796
await tc.downloadTool(url, path);
7897
await fs.chmod(path, 0o755);
7998
}

0 commit comments

Comments
 (0)