Output rustc, cargo and rustup versions as Action outputs

This commit is contained in:
svartalf 2020-01-24 15:10:57 +03:00
parent ad7f1a0189
commit 661772c5dc
4 changed files with 91 additions and 1 deletions

View File

@ -48,6 +48,16 @@ See [additional recipes here](https://github.com/actions-rs/meta).
| `profile` | | Execute `rustup set profile {value}` before installing the toolchain, ex. `minimal` | string | |
| `components` | | Comma-separated list of the additional components to install, ex. `clippy, rustfmt` | string | |
## Outputs
Installed `rustc`, `cargo` and `rustup` versions can be fetched from the Action outputs:
| Name | Example |
| -------- | ------------------------------- |
| `rustc` | `1.40.0 (73528e339 2019-12-16)` |
| `cargo` | `1.40.0 (bc8e4c8be 2019-11-22)` |
| `rustup` | `1.21.1 (7832b2ebe 2019-12-20)` |
## Profiles
This Action supports rustup [profiles](https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html#profiles),

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ import * as io from '@actions/io';
import path from "path";
import * as args from './args';
import * as versions from './versions';
import {RustUp, ToolchainOptions} from '@actions-rs/core';
async function run() {
@ -52,6 +53,8 @@ async function run() {
if (opts.target) {
await rustup.addTarget(opts.target, opts.name);
}
await versions.gatherInstalledVersions();
}
async function main() {

77
src/versions.ts Normal file
View File

@ -0,0 +1,77 @@
import * as exec from '@actions/exec';
import * as core from '@actions/core';
export async function gatherInstalledVersions(): Promise<void> {
try {
core.startGroup('Gathering installed versions');
await rustc();
await cargo();
await rustup();
} finally {
core.endGroup();
}
}
/**
* Fetch currently used `rustc` version
*/
async function rustc(): Promise<void> {
const stdout = await getStdout('rustc', ['-V']);
const version = parse(stdout);
core.setOutput('rustc', version.long);
// core.setOutput('rustc_short', version.short);
}
/**
* Fetch currently used `cargo` version
*/
async function cargo(): Promise<void> {
const stdout = await getStdout('cargo', ['-V']);
const version = parse(stdout);
core.setOutput('cargo', version.long);
// core.setOutput('cargo_short', version.short);
}
async function rustup(): Promise<void> {
const stdout = await getStdout('rustup', ['-V']);
const version = parse(stdout);
core.setOutput('rustup', version.long);
// core.setOutput('rustup_short', version.short);
}
interface Version {
short: string,
long: string,
}
function parse(stdout: string): Version {
stdout = stdout.trim();
const matches = stdout.match(/\S+\s((\S+)\s\(.+\))/m);
if (matches == null) {
throw new Error(`Unable to parse version from the "${stdout}" string`);
}
return {
short: matches[2],
long: matches[1],
}
}
async function getStdout(exe: string, args: string[], options?: {}): Promise<string> {
let stdout = '';
const resOptions = Object.assign({}, options, {
listeners: {
stdout: (buffer: Buffer) => {
stdout += buffer.toString();
},
},
});
await exec.exec(exe, args, resOptions);
return stdout;
}