Merge pull request #2 from hecrj/feature/components

Add `components` support as an input
This commit is contained in:
Héctor Ramón 2019-09-04 13:23:32 +02:00 committed by GitHub
commit b6dfb72c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 17 deletions

View File

@ -2,8 +2,7 @@ name: Integration
on: on:
push: {} push: {}
schedule: schedule:
cron: '0 0 * * *' - cron: '0 0 * * *'
jobs: jobs:
test: test:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@ -11,11 +10,21 @@ jobs:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
rust: [stable, nightly] rust: [stable, nightly]
include:
- os: macOS-latest
rust: 'stable'
components: 'rustfmt, clippy'
steps: steps:
- uses: hecrj/setup-rust-action@master - uses: hecrj/setup-rust-action@master
with: with:
rust-version: ${{ matrix.rust }} rust-version: ${{ matrix.rust }}
components: ${{ matrix.components || '' }}
- name: Check Cargo availability - name: Check Cargo availability
run: cargo --version run: cargo --version
- name: Check Rustup default toolchain - name: Check Rustup default toolchain
run: rustup default | grep '${{ matrix.rust }}' 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: rust-version:
description: 'The toolchain name, such as stable, nightly, or 1.8.0' description: 'The toolchain name, such as stable, nightly, or 1.8.0'
default: 'stable' default: 'stable'
components:
description: 'The toolchain components to install, comma-separated'
default: ''
runs: runs:
using: 'node12' using: 'node12'
main: 'lib/main.js' main: 'lib/main.js'

View File

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

View File

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

View File

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