Compare commits

...

4 commits

Author SHA1 Message Date
Miles Johnson
52e0bc3392 deps: Update to latest. 2025-02-20 10:02:54 -08:00
Adi Yakovian
2d9112aa0c
deps: Update cache version (#26) 2025-02-20 09:59:51 -08:00
Miles Johnson
1670d14080
fix: Fix binstall 404. (#21) 2024-08-03 22:14:37 -07:00
Miles Johnson
dcab3dcf9f
new: Support custom target dirs. (#19) 2024-05-03 12:01:30 -07:00
9 changed files with 2249 additions and 1702 deletions

View file

@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- run: npm install -g pnpm - run: npm install -g pnpm
- run: pnpm install - run: pnpm install
- run: pnpm run check - run: pnpm run check
@ -23,7 +23,7 @@ jobs:
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- run: npm install -g pnpm - run: npm install -g pnpm
- run: pnpm install - run: pnpm install
- run: pnpm run build - run: pnpm run build
@ -39,7 +39,7 @@ jobs:
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- run: npm install -g pnpm - run: npm install -g pnpm
- run: pnpm install - run: pnpm install
- run: pnpm run build - run: pnpm run build

View file

@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.release.tag_name }} ref: ${{ github.event.release.tag_name }}
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
- run: npm install -g pnpm - run: npm install -g pnpm
- run: pnpm install - run: pnpm install
- run: pnpm run build - run: pnpm run build

View file

@ -1,3 +1,19 @@
# 1.2.2
- Updated dependencies.
# 1.2.1
- Pinned the `cargo-binstall` version to v1.8 to work around the 404 errors in CI.
- Added support for the `CARGO_BINSTALL_VERSION` environment variable.
# 1.2.0
- Added a `target-dirs` input, allowing the target folders to be specified. Can now cache multiple
target folders.
- Updated to skip caching a directory if it does not exist, instead of failing.
- Updated dependencies.
# 1.1.0 # 1.1.0
- Added a `cache-base` input. When provided, will only save cache on this branch/ref, but will - Added a `cache-base` input. When provided, will only save cache on this branch/ref, but will

View file

@ -30,6 +30,8 @@ optional.
- `inherit-toolchain` - Inherit all toolchain settings from the `rust-toolchain.toml` file. Defaults - `inherit-toolchain` - Inherit all toolchain settings from the `rust-toolchain.toml` file. Defaults
to `false`. to `false`.
- `targets` - Comma-separated list of additional targets to install. - `targets` - Comma-separated list of additional targets to install.
- `target-dirs` - Comma-separated list of target folder paths, relative from the repository root.
Defaults to `target`.
- `profile` - Profile to install. Defaults to `minimal`. - `profile` - Profile to install. Defaults to `minimal`.
## Configuring the Rust toolchain ## Configuring the Rust toolchain

View file

@ -8,7 +8,7 @@ inputs:
description: 'Comma-separated list of global binaries to install into Cargo.' description: 'Comma-separated list of global binaries to install into Cargo.'
cache: cache:
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.' description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
default: true default: 'true'
cache-base: cache-base:
description: description:
'Base branch/ref to save a warmup cache on. Other branches/refs will restore from this base.' 'Base branch/ref to save a warmup cache on. Other branches/refs will restore from this base.'
@ -21,9 +21,12 @@ inputs:
description: 'Comma-separated list of additional components to install.' description: 'Comma-separated list of additional components to install.'
inherit-toolchain: inherit-toolchain:
description: 'Inherit all toolchain settings from the rust-toolchain.toml file.' description: 'Inherit all toolchain settings from the rust-toolchain.toml file.'
default: false default: 'false'
targets: targets:
description: 'Comma-separated list of additional targets to install.' description: 'Comma-separated list of additional targets to install.'
target-dirs:
description: 'Comma-separated list of target folder paths, relative from the repository root.'
default: 'target'
profile: profile:
description: 'Profile to install. Defaults to "minimal".' description: 'Profile to install. Defaults to "minimal".'
outputs: outputs:

View file

@ -1,6 +1,6 @@
{ {
"name": "@moonrepo/setup-rust", "name": "@moonrepo/setup-rust",
"version": "1.0.3", "version": "1.2.2",
"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": {
@ -16,24 +16,24 @@
"author": "Miles Johnson", "author": "Miles Johnson",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.2.2", "@actions/cache": "^4.0.0",
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0", "@actions/glob": "^0.5.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" "detect-libc": "^2.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.9.1", "@types/node": "^20.13.4",
"@vercel/ncc": "^0.38.1", "@vercel/ncc": "^0.38.1",
"eslint": "^8.53.0", "eslint": "^8.53.0",
"eslint-config-moon": "^2.0.11", "eslint-config-moon": "^2.0.11",
"prettier": "^3.1.0", "prettier": "^3.2.5",
"prettier-config-moon": "^1.1.2", "prettier-config-moon": "^1.1.2",
"tsconfig-moon": "^1.3.0", "tsconfig-moon": "^1.3.0",
"typescript": "^5.2.2" "typescript": "^5.4.5"
}, },
"engines": { "engines": {
"node": ">=20.0.0" "node": ">=20.0.0"

3853
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -18,12 +18,22 @@ export function getCacheTarget(): string {
return core.getInput('cache-target') || 'debug'; return core.getInput('cache-target') || 'debug';
} }
export function getTargetPaths(): string[] {
const profile = getCacheTarget();
const dirs = core.getInput('target-dirs', { required: true }).split(',');
return dirs
.map((dir) => dir.trim())
.filter(Boolean)
.map((dir) => path.join(WORKSPACE_ROOT, dir, profile));
}
export function getCachePaths(): string[] { export function getCachePaths(): string[] {
return [ return [
// ~/.cargo/registry // ~/.cargo/registry
path.join(CARGO_HOME, 'registry'), path.join(CARGO_HOME, 'registry'),
// /workspace/target/debug // /workspace/target/debug
path.join(WORKSPACE_ROOT, 'target', getCacheTarget()), ...getTargetPaths(),
]; ];
} }

View file

@ -17,6 +17,7 @@ import {
} from './cache'; } from './cache';
import { rmrf } from './fs'; import { rmrf } from './fs';
// eslint-disable-next-line complexity
export async function downloadAndInstallBinstall(binDir: string) { export async function downloadAndInstallBinstall(binDir: string) {
core.info('cargo-binstall does not exist, attempting to install'); core.info('cargo-binstall does not exist, attempting to install');
@ -62,7 +63,11 @@ export async function downloadAndInstallBinstall(binDir: string) {
throw new Error(`Unsupported platform: ${process.platform}`); throw new Error(`Unsupported platform: ${process.platform}`);
} }
const url = `https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-${file}`; // https://github.com/cargo-bins/cargo-binstall/issues/1864
const version = process.env.CARGO_BINSTALL_VERSION ?? 'v1.8.0';
const url = version === 'latest'
? `https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-${file}`
: `https://github.com/cargo-bins/cargo-binstall/releases/download/${version}/cargo-binstall-${file}`;
const dlPath = await tc.downloadTool(url); const dlPath = await tc.downloadTool(url);
if (url.endsWith('.zip')) { if (url.endsWith('.zip')) {
@ -165,12 +170,33 @@ export async function saveCache() {
return; return;
} }
const cachePaths = getCachePaths().filter((cachePath) => {
if (!fs.existsSync(cachePath)) {
core.info(`Cache path ${cachePath} does not exist, skipping`);
return false;
}
return true;
});
if (cachePaths.length === 0) {
core.info('No paths to cache, skipping save entirely');
return;
}
await cleanCargoRegistry(); await cleanCargoRegistry();
await cleanTargetProfile(); await cleanTargetProfile();
core.info(`Saving cache with key ${primaryKey}`); core.info(`Saving cache with key ${primaryKey}`);
await cache.saveCache(getCachePaths(), primaryKey); core.debug(`Cache key: ${primaryKey}`);
core.debug('Cache paths:');
for (const cachePath of cachePaths) {
core.debug(`- ${cachePath}`);
}
await cache.saveCache(cachePaths, primaryKey);
} }
export async function restoreCache() { export async function restoreCache() {
@ -181,6 +207,15 @@ export async function restoreCache() {
core.info('Attempting to restore cache'); core.info('Attempting to restore cache');
const primaryKey = await getPrimaryCacheKey(); const primaryKey = await getPrimaryCacheKey();
const cachePaths = getCachePaths();
core.debug(`Cache key: ${primaryKey}`);
core.debug('Cache paths:');
for (const cachePath of cachePaths) {
core.debug(`- ${cachePath}`);
}
const cacheKey = await cache.restoreCache(getCachePaths(), primaryKey, getCachePrefixes()); const cacheKey = await cache.restoreCache(getCachePaths(), primaryKey, getCachePrefixes());
if (cacheKey) { if (cacheKey) {