mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 13:30:03 +00:00
Automatic compilation
This commit is contained in:
parent
befb8010f7
commit
c5574dc09d
13 changed files with 7265 additions and 2886 deletions
|
@ -1,6 +0,0 @@
|
|||
coverage/
|
||||
dist/
|
||||
node_modules/
|
||||
*.min.js
|
||||
*.map
|
||||
*.snap
|
10
.eslintrc.js
10
.eslintrc.js
|
@ -1,10 +0,0 @@
|
|||
/* eslint-disable sort-keys */
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ['moon', 'moon/node'],
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
};
|
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
|
@ -1,16 +0,0 @@
|
|||
name: 'Pipeline'
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
pull_request:
|
||||
jobs:
|
||||
ci:
|
||||
name: 'CI'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- run: npm install -g pnpm
|
||||
- run: pnpm install
|
||||
- run: pnpm run check
|
18
.github/workflows/publish.yml
vendored
18
.github/workflows/publish.yml
vendored
|
@ -1,18 +0,0 @@
|
|||
name: Publish
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.release.tag_name }}
|
||||
- uses: actions/setup-node@v3
|
||||
- run: npm install -g pnpm
|
||||
- run: pnpm install
|
||||
- run: pnpm run build
|
||||
- uses: JasonEtco/build-and-tag-action@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
node_modules/
|
||||
dist/
|
|
@ -1,3 +0,0 @@
|
|||
# Unreleased
|
||||
|
||||
- Initial release.
|
19
README.md
19
README.md
|
@ -1,19 +0,0 @@
|
|||
# Setup Rust
|
||||
|
||||
A GitHub action for setting up Rust and Cargo. Will automatically install the appropriate toolchain
|
||||
with `rustup` by inspecting the `RUSTUP_TOOLCHAIN` environment variable or the `rust-toolchain.toml`
|
||||
configuration file.
|
||||
|
||||
## Installation
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# ...
|
||||
- uses: moonrepo/setup-rust@v0
|
||||
- run: cargo test
|
||||
```
|
7265
dist/index.js
vendored
Normal file
7265
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
193
index.ts
193
index.ts
|
@ -1,193 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import TOML from '@ltd/j-toml';
|
||||
|
||||
interface Toolchain {
|
||||
channel: string;
|
||||
components: string[];
|
||||
targets: string[];
|
||||
profile: string;
|
||||
}
|
||||
|
||||
interface ToolchainConfig {
|
||||
toolchain: Partial<Toolchain>;
|
||||
}
|
||||
|
||||
const DEFAULT_TOOLCHAIN: Toolchain = {
|
||||
channel: 'stable',
|
||||
components: [],
|
||||
profile: 'minimal',
|
||||
targets: [],
|
||||
};
|
||||
|
||||
function getCargoHome(): string {
|
||||
if (process.env.CARGO_HOME) {
|
||||
return process.env.CARGO_HOME;
|
||||
}
|
||||
|
||||
return path.join(os.homedir(), '.cargo');
|
||||
}
|
||||
|
||||
function parseConfig(configPath: string): Partial<Toolchain> {
|
||||
const contents = fs.readFileSync(configPath, 'utf8').trim();
|
||||
|
||||
if (!contents.includes('[toolchain]')) {
|
||||
core.debug('No [toolchain] section found, assuming legacy format');
|
||||
|
||||
return { channel: contents };
|
||||
}
|
||||
|
||||
const config = TOML.parse(contents) as unknown as ToolchainConfig;
|
||||
|
||||
if (config.toolchain.channel) {
|
||||
core.debug('Found channel in [toolchain] section');
|
||||
|
||||
return { channel: config.toolchain.channel };
|
||||
}
|
||||
|
||||
core.debug('No channel found in [toolchain] section');
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://rust-lang.github.io/rustup/overrides.html
|
||||
function detectToolchain(): Toolchain {
|
||||
core.info('Detecting toolchain');
|
||||
|
||||
const toolchain = { ...DEFAULT_TOOLCHAIN };
|
||||
|
||||
if (process.env.RUSTUP_TOOLCHAIN) {
|
||||
core.info('Using toolchain from RUSTUP_TOOLCHAIN environment variable');
|
||||
|
||||
Object.assign(toolchain, {
|
||||
channel: process.env.RUSTUP_TOOLCHAIN,
|
||||
});
|
||||
} else {
|
||||
core.info('Searching for rust-toolchain.toml or rust-toolchain file');
|
||||
|
||||
for (const configName of ['rust-toolchain.toml', 'rust-toolchain']) {
|
||||
const configPath = path.join(process.cwd(), configName);
|
||||
|
||||
if (fs.existsSync(configPath)) {
|
||||
core.debug(`Found ${configName}, parsing TOML`);
|
||||
|
||||
Object.assign(toolchain, parseConfig(configPath));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.info('Inheriting toolchain settings from inputs');
|
||||
|
||||
(Object.keys(DEFAULT_TOOLCHAIN) as (keyof typeof DEFAULT_TOOLCHAIN)[]).forEach((key) => {
|
||||
const input = core.getInput(key);
|
||||
|
||||
if (input) {
|
||||
core.debug(`Found input for ${key}: ${input}`);
|
||||
|
||||
if (key === 'components' || key === 'targets') {
|
||||
input.split(',').forEach((part) => {
|
||||
toolchain[key].push(part.trim());
|
||||
});
|
||||
} else {
|
||||
toolchain[key] = input;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return toolchain;
|
||||
}
|
||||
|
||||
async function installToolchain(toolchain: Toolchain) {
|
||||
core.info('Installing toolchain with rustup');
|
||||
|
||||
const args = ['toolchain', 'install', toolchain.channel, '--profile', toolchain.profile];
|
||||
|
||||
toolchain.targets.forEach((target) => {
|
||||
args.push('--target', target);
|
||||
});
|
||||
|
||||
toolchain.components.forEach((component) => {
|
||||
args.push('--component', component);
|
||||
});
|
||||
|
||||
if (toolchain.channel === 'nightly' && toolchain.components.length > 0) {
|
||||
args.push('--allow-downgrade');
|
||||
}
|
||||
|
||||
args.push('--no-self-update');
|
||||
|
||||
await exec.exec('rustup', args);
|
||||
await exec.exec('rustup', ['default', toolchain.channel]);
|
||||
|
||||
core.info('Logging installed toolchain versions');
|
||||
|
||||
await exec.exec('rustc', [`+${toolchain.channel}`, '--version', '--verbose']);
|
||||
}
|
||||
|
||||
async function installBins() {
|
||||
const bins = core
|
||||
.getInput('bins')
|
||||
.split(',')
|
||||
.map((bin) => bin.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
if (bins.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
core.info('Installing additional binaries');
|
||||
|
||||
const binDir = path.join(getCargoHome(), 'bin');
|
||||
|
||||
core.debug('Checking if cargo-binstall has been installed');
|
||||
|
||||
if (!fs.existsSync(path.join(binDir, 'cargo-binstall'))) {
|
||||
core.debug('Not installed, attempting to install');
|
||||
|
||||
await exec.exec('cargo', ['install', 'cargo-binstall']);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
bins.map((bin) => {
|
||||
const [crate, version] = bin.split('@');
|
||||
const args = ['binstall', crate.startsWith('cargo-') ? crate : `cargo-${crate}`];
|
||||
|
||||
if (version) {
|
||||
args.push('--version', version);
|
||||
}
|
||||
|
||||
core.info(`Installing ${crate}...`);
|
||||
|
||||
return exec.exec('cargo', args);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
core.info('Setting cargo environment variables');
|
||||
|
||||
// Disable incremental compilation
|
||||
core.exportVariable('CARGO_INCREMENTAL', '0');
|
||||
|
||||
// Always enable colored output
|
||||
core.exportVariable('CARGO_TERM_COLOR', 'always');
|
||||
|
||||
try {
|
||||
await installToolchain(detectToolchain());
|
||||
await installBins();
|
||||
} catch (error: unknown) {
|
||||
core.setFailed((error as Error).message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
core.info('Adding ~/.cargo/bin to PATH');
|
||||
|
||||
core.addPath(path.join(getCargoHome(), 'bin'));
|
||||
}
|
||||
|
||||
void run();
|
33
package.json
33
package.json
|
@ -1,33 +0,0 @@
|
|||
{
|
||||
"name": "@moonrepo/setup-rust",
|
||||
"version": "0.2.0",
|
||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build ./index.ts",
|
||||
"check": "npm run lint && npm run typecheck",
|
||||
"lint": "eslint --ext .ts,.js --fix .",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/moonrepo/setup-rust"
|
||||
},
|
||||
"author": "Miles Johnson",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@ltd/j-toml": "^1.38.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.15.10",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.36.0",
|
||||
"eslint-config-moon": "^2.0.2",
|
||||
"prettier": "^2.8.7",
|
||||
"prettier-config-moon": "^1.1.2",
|
||||
"tsconfig-moon": "^1.3.0",
|
||||
"typescript": "^5.0.2"
|
||||
}
|
||||
}
|
2569
pnpm-lock.yaml
generated
2569
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
@ -1 +0,0 @@
|
|||
module.exports = 'prettier-config-moon';
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"extends": "tsconfig-moon/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"module": "Node16",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noEmit": true,
|
||||
"verbatimModuleSyntax": false
|
||||
},
|
||||
"include": [
|
||||
".eslintrc.js",
|
||||
"*.js",
|
||||
"*.ts",
|
||||
"tests/*.ts"
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue