This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output rustc, cargo and rustup versions as Action outputs (#47)
- Loading branch information
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-hash', version.hash); | ||
} | ||
|
||
/** | ||
* 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 { | ||
long: string, | ||
hash: string, | ||
} | ||
|
||
function parse(stdout: string): Version { | ||
stdout = stdout.trim(); | ||
const matches = stdout.match(/\S+\s((\S+)\s\((\S+)\s(\S+)\))/m); | ||
if (matches == null) { | ||
throw new Error(`Unable to parse version from the "${stdout}" string`); | ||
} | ||
|
||
return { | ||
long: matches[1], | ||
hash: matches[3], | ||
} | ||
} | ||
|
||
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; | ||
} |