Skip to content
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
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'unicorn/prefer-top-level-await': 'off',
},
};
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ jobs:
- run: npm install -g pnpm
- run: pnpm install
- run: pnpm run check
action:
name: 'Action'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install -g pnpm
- run: pnpm install
- run: pnpm run build
- uses: ./ # self
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.0

- Will now install `rustup` if it does not exist in the environment.
- Added musl support to `cargo-binstall`.

# 0.6.0

- Breaking: Cargo `bins` must provide the `cargo-` crate prefix manually. This change allows
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# ...
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
- run: cargo test
```

Expand Down Expand Up @@ -51,7 +51,7 @@ The toolchain/channel can also be explicitly configured with the `channel` input
highest precedence.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
channel: '1.65.0'
```
Expand All @@ -63,15 +63,15 @@ with the `profile`, `components`, and `targets` inputs respectively. When not de
defaults to `minimal`.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
profile: complete
```

When using components, the input requires a comma separated list of component names.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
components: clippy
- run: cargo clippy --workspace
Expand All @@ -80,7 +80,7 @@ When using components, the input requires a comma separated list of component na
When using targets, the input requires a comma separated list of target triples.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
targets: 'x86_64-pc-windows-msvc,x86_64-pc-windows-gnu'
```
Expand All @@ -92,13 +92,15 @@ installing Cargo binaries through the `bins` input, which requires a comma-separ
names.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
bins: cargo-nextest, cargo-insta@1.28.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

> Binaries are installed with [`cargo-binstall`](https://crates.io/crates/cargo-binstall) under the
> hood.
> hood. We suggest setting `GITHUB_TOKEN` to avoid rate limiting.

## Caching in CI

Expand All @@ -107,7 +109,7 @@ CI times. To disable caching, set the `cache` input to `false`. Furthermore, the
be changed with the `cache-target` input, which defaults to `debug`.

```yaml
- uses: moonrepo/setup-rust@v0
- uses: moonrepo/setup-rust@v1
with:
cache: false
cache-target: release
Expand Down Expand Up @@ -147,11 +149,6 @@ Outside of being evergreen, this action also supports the following features:
- Assumes `rustup`, `cargo`, and other commands are available globally. This allows you to use them
directly in a `run` command, without having to use `actions-rs/cargo`.

However, this action _does not_:

- Install `rustup` if it does not exist, while `actions-rs` will. This is typically fine if using
GitHub provided runners as all Rust tooling comes pre-installed.

### `dtolnay/rust-toolchain`

Our action is very similar to theirs, which was a great implementation reference, but our action
Expand Down
33 changes: 32 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import path from 'path';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import { CARGO_HOME, installBins, restoreCache } from './src/cargo';
import { installToolchain } from './src/rust';

export async function installRustup() {
try {
await io.which('rustup', true);
return;
} catch {
// Doesn't exist
}

core.info('rustup does not exist, attempting to install');

const script = await tc.downloadTool(
process.platform === 'win32' ? 'https://win.rustup.rs' : 'https://sh.rustup.rs',
path.join(os.tmpdir(), 'rustup-init'),
);

core.info(`Downloaded installation script to ${script}`);

// eslint-disable-next-line no-magic-numbers
await fs.promises.chmod(script, 0o755);

await exec.exec(script, ['--default-toolchain', 'none', '-y']);

core.info('Installed rustup');
}

async function run() {
core.info('Setting cargo environment variables');

Expand All @@ -14,6 +44,7 @@ async function run() {
core.addPath(path.join(CARGO_HOME, 'bin'));

try {
await installRustup();
await installToolchain();
await installBins();

Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonrepo/setup-rust",
"version": "0.6.1",
"version": "1.0.0",
"description": "A GitHub action for setting up Rust and Cargo.",
"main": "dist/index.js",
"scripts": {
Expand All @@ -22,16 +22,20 @@
"@actions/glob": "^0.4.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"@ltd/j-toml": "^1.38.0"
"@ltd/j-toml": "^1.38.0",
"detect-libc": "^2.0.2"
},
"devDependencies": {
"@types/node": "^18.15.11",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.40.0",
"eslint-config-moon": "^2.0.3",
"prettier": "^2.8.8",
"eslint": "^8.46.0",
"eslint-config-moon": "^2.0.6",
"prettier": "^3.0.0",
"prettier-config-moon": "^1.1.2",
"tsconfig-moon": "^1.3.0",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
},
"engines": {
"node": ">=16.0.0"
}
}
Loading