Add components support as an input

This commit is contained in:
Héctor Ramón Jiménez 2019-09-04 12:58:20 +02:00
parent aadd26abab
commit f4d4827168
5 changed files with 37 additions and 17 deletions

View File

@ -2,8 +2,7 @@ name: Integration
on:
push: {}
schedule:
cron: '0 0 * * *'
- cron: '0 0 * * *'
jobs:
test:
runs-on: ${{ matrix.os }}
@ -11,11 +10,21 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable, nightly]
include:
- os: macOS-latest
rust: 'stable'
components: 'rustfmt, clippy'
steps:
- uses: hecrj/setup-rust-action@master
with:
rust-version: ${{ matrix.rust }}
components: ${{ matrix.components || '' }}
- name: Check Cargo availability
run: cargo --version
- name: Check Rustup default toolchain
run: rustup default | grep '${{ matrix.rust }}'
- name: Check rustfmt and clippy are available on MacOS
if: matrix.os == 'macOS-latest' && matrix.rust == 'stable'
run: |
cargo fmt --version
cargo clippy --version

View File

@ -5,6 +5,9 @@ inputs:
rust-version:
description: 'The toolchain name, such as stable, nightly, or 1.8.0'
default: 'stable'
components:
description: 'The toolchain components to install, comma-separated'
default: ''
runs:
using: 'node12'
main: 'lib/main.js'

View File

@ -22,10 +22,17 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('rust-version');
const components = core.getInput('components')
.split(',')
.map((component) => component.trim())
.filter((component) => component.length > 0);
if (version) {
yield rustup.install(version);
yield rustup.install();
yield exec.exec('rustup', ['default', version]);
yield exec.exec('rustup', ['update', version]);
for (let component of components) {
yield exec.exec('rustup', ['component', 'add', component]);
}
}
}
catch (error) {

View File

@ -22,29 +22,22 @@ const path = __importStar(require("path"));
const os = __importStar(require("os"));
const fs_1 = require("fs");
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
function install(version) {
function install() {
return __awaiter(this, void 0, void 0, function* () {
// `rustup` is already installed on Linux and Windows platforms
if (os.platform() == 'darwin') {
let toolPath = yield acquireRust(version);
core.debug('Rust toolchain is cached under ' + toolPath);
let toolPath = yield installOnUnix();
core.debug('rustup is located under: ' + toolPath);
core.addPath(path.join(toolPath, 'bin'));
}
});
}
exports.install = install;
function acquireRust(version) {
function installOnUnix() {
return __awaiter(this, void 0, void 0, function* () {
let script;
try {
script = yield toolCache.downloadTool("https://sh.rustup.rs");
}
catch (error) {
core.debug(error);
throw `Failed to download rustup: ${error}`;
}
let script = yield toolCache.downloadTool("https://sh.rustup.rs");
fs_1.chmodSync(script, '777');
yield exec.exec(`"${script}"`, ['-y', '--default-toolchain', 'none']);
let cargo = path.join(process.env['HOME'] || '', '.cargo');
return yield toolCache.cacheDir(cargo, 'rust', version);
return path.join(process.env['HOME'] || '', '.cargo');
});
}

View File

@ -6,11 +6,19 @@ import * as os from 'os';
async function run() {
try {
const version = core.getInput('rust-version');
const components = core.getInput('components')
.split(',')
.map((component) => component.trim())
.filter((component) => component.length > 0);
if(version) {
await rustup.install();
await exec.exec('rustup', ['default', version]);
await exec.exec('rustup', ['update', version]);
for(let component of components) {
await exec.exec('rustup', ['component', 'add', component]);
}
}
} catch (error) {
core.setFailed(error.message);