mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-22 10:38:43 +00:00
new: Prepare v1 release. (#9)
This commit is contained in:
parent
711a320c49
commit
889bf1db60
9 changed files with 592 additions and 450 deletions
|
@ -7,4 +7,7 @@ module.exports = {
|
||||||
project: 'tsconfig.json',
|
project: 'tsconfig.json',
|
||||||
tsconfigRootDir: __dirname,
|
tsconfigRootDir: __dirname,
|
||||||
},
|
},
|
||||||
|
rules: {
|
||||||
|
'unicorn/prefer-top-level-await': 'off',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
|
@ -14,3 +14,19 @@ jobs:
|
||||||
- run: npm install -g pnpm
|
- run: npm install -g pnpm
|
||||||
- run: pnpm install
|
- run: pnpm install
|
||||||
- run: pnpm run check
|
- 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 }}
|
||||||
|
|
|
@ -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
|
# 0.6.0
|
||||||
|
|
||||||
- Breaking: Cargo `bins` must provide the `cargo-` crate prefix manually. This change allows
|
- Breaking: Cargo `bins` must provide the `cargo-` crate prefix manually. This change allows
|
||||||
|
|
23
README.md
23
README.md
|
@ -11,7 +11,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# ...
|
# ...
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
- run: cargo test
|
- run: cargo test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ The toolchain/channel can also be explicitly configured with the `channel` input
|
||||||
highest precedence.
|
highest precedence.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
channel: '1.65.0'
|
channel: '1.65.0'
|
||||||
```
|
```
|
||||||
|
@ -63,7 +63,7 @@ with the `profile`, `components`, and `targets` inputs respectively. When not de
|
||||||
defaults to `minimal`.
|
defaults to `minimal`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
profile: complete
|
profile: complete
|
||||||
```
|
```
|
||||||
|
@ -71,7 +71,7 @@ defaults to `minimal`.
|
||||||
When using components, the input requires a comma separated list of component names.
|
When using components, the input requires a comma separated list of component names.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
components: clippy
|
components: clippy
|
||||||
- run: cargo clippy --workspace
|
- run: cargo clippy --workspace
|
||||||
|
@ -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.
|
When using targets, the input requires a comma separated list of target triples.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
targets: 'x86_64-pc-windows-msvc,x86_64-pc-windows-gnu'
|
targets: 'x86_64-pc-windows-msvc,x86_64-pc-windows-gnu'
|
||||||
```
|
```
|
||||||
|
@ -92,13 +92,15 @@ installing Cargo binaries through the `bins` input, which requires a comma-separ
|
||||||
names.
|
names.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
bins: cargo-nextest, cargo-insta@1.28.0
|
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
|
> 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
|
## Caching in CI
|
||||||
|
|
||||||
|
@ -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`.
|
be changed with the `cache-target` input, which defaults to `debug`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v1
|
||||||
with:
|
with:
|
||||||
cache: false
|
cache: false
|
||||||
cache-target: release
|
cache-target: release
|
||||||
|
@ -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
|
- 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`.
|
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`
|
### `dtolnay/rust-toolchain`
|
||||||
|
|
||||||
Our action is very similar to theirs, which was a great implementation reference, but our action
|
Our action is very similar to theirs, which was a great implementation reference, but our action
|
||||||
|
|
33
index.ts
33
index.ts
|
@ -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 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 { CARGO_HOME, installBins, restoreCache } from './src/cargo';
|
||||||
import { installToolchain } from './src/rust';
|
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() {
|
async function run() {
|
||||||
core.info('Setting cargo environment variables');
|
core.info('Setting cargo environment variables');
|
||||||
|
|
||||||
|
@ -14,6 +44,7 @@ async function run() {
|
||||||
core.addPath(path.join(CARGO_HOME, 'bin'));
|
core.addPath(path.join(CARGO_HOME, 'bin'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await installRustup();
|
||||||
await installToolchain();
|
await installToolchain();
|
||||||
await installBins();
|
await installBins();
|
||||||
|
|
||||||
|
|
16
package.json
16
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@moonrepo/setup-rust",
|
"name": "@moonrepo/setup-rust",
|
||||||
"version": "0.6.1",
|
"version": "1.0.0",
|
||||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -22,16 +22,20 @@
|
||||||
"@actions/glob": "^0.4.0",
|
"@actions/glob": "^0.4.0",
|
||||||
"@actions/io": "^1.1.3",
|
"@actions/io": "^1.1.3",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@ltd/j-toml": "^1.38.0"
|
"@ltd/j-toml": "^1.38.0",
|
||||||
|
"detect-libc": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^18.15.11",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.36.1",
|
||||||
"eslint": "^8.40.0",
|
"eslint": "^8.46.0",
|
||||||
"eslint-config-moon": "^2.0.3",
|
"eslint-config-moon": "^2.0.6",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^3.0.0",
|
||||||
"prettier-config-moon": "^1.1.2",
|
"prettier-config-moon": "^1.1.2",
|
||||||
"tsconfig-moon": "^1.3.0",
|
"tsconfig-moon": "^1.3.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.1.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
913
pnpm-lock.yaml
generated
913
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
29
src/cargo.ts
29
src/cargo.ts
|
@ -1,7 +1,7 @@
|
||||||
import crypto from 'crypto';
|
import crypto from 'node:crypto';
|
||||||
import fs from 'fs';
|
import fs from 'node:fs';
|
||||||
import os from 'os';
|
import os from 'node:os';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
@ -26,6 +26,9 @@ export async function downloadAndInstallBinstall(binDir: string) {
|
||||||
case 'x64':
|
case 'x64':
|
||||||
arch = 'x86_64';
|
arch = 'x86_64';
|
||||||
break;
|
break;
|
||||||
|
case 'arm':
|
||||||
|
arch = 'armv7';
|
||||||
|
break;
|
||||||
case 'arm64':
|
case 'arm64':
|
||||||
arch = 'aarch64';
|
arch = 'aarch64';
|
||||||
break;
|
break;
|
||||||
|
@ -34,9 +37,21 @@ export async function downloadAndInstallBinstall(binDir: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'linux':
|
case 'linux': {
|
||||||
file = `${arch}-unknown-linux-gnu.tgz`;
|
const { family } = await import('detect-libc');
|
||||||
|
let lib = 'gnu';
|
||||||
|
|
||||||
|
if ((await family()) === 'musl') {
|
||||||
|
lib = 'musl';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.arch === 'arm') {
|
||||||
|
lib += 'eabihf';
|
||||||
|
}
|
||||||
|
|
||||||
|
file = `${arch}-unknown-linux-${lib}.tgz`;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
file = `${arch}-apple-darwin.zip`;
|
file = `${arch}-apple-darwin.zip`;
|
||||||
break;
|
break;
|
||||||
|
@ -220,7 +235,7 @@ export async function restoreCache() {
|
||||||
core.saveState('cache-hit-key', cacheKey);
|
core.saveState('cache-hit-key', cacheKey);
|
||||||
core.info(`Cache restored using key ${primaryKey}`);
|
core.info(`Cache restored using key ${primaryKey}`);
|
||||||
} else {
|
} else {
|
||||||
core.warning(`Cache does not exist using key ${primaryKey}`);
|
core.info(`Cache does not exist using key ${primaryKey}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('cache-key', cacheKey ?? primaryKey);
|
core.setOutput('cache-key', cacheKey ?? primaryKey);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* eslint-disable import/no-mutable-exports */
|
/* eslint-disable import/no-mutable-exports */
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'node:fs';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import TOML from '@ltd/j-toml';
|
import TOML from '@ltd/j-toml';
|
||||||
|
|
Loading…
Add table
Reference in a new issue