Automatic compilation

This commit is contained in:
github-actions[bot] 2023-04-16 06:19:26 +00:00 committed by GitHub
parent 9c82124546
commit e2da288550
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 7258 additions and 2874 deletions

View file

@ -1,6 +0,0 @@
coverage/
dist/
node_modules/
*.min.js
*.map
*.snap

View file

@ -1,10 +0,0 @@
/* eslint-disable sort-keys */
module.exports = {
root: true,
extends: ['moon', 'moon/node'],
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
};

View file

@ -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

View file

@ -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
View file

@ -1,2 +0,0 @@
node_modules/
dist/

View file

@ -1,3 +0,0 @@
# Unreleased
- Initial release.

View file

@ -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
```

7258
dist/index.js vendored Normal file

File diff suppressed because it is too large Load diff

181
index.ts
View file

@ -1,181 +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)
.map((bin) => (bin.startsWith('cargo-') ? bin : `cargo-${bin}`));
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 exec.exec('cargo', ['binstall', ' --no-confirm', '--log-level', 'info', ...bins]);
}
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();

View file

@ -1,33 +0,0 @@
{
"name": "@moonrepo/setup-rust",
"version": "0.2.1",
"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

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
module.exports = 'prettier-config-moon';

View file

@ -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"
]
}