0
0
Fork 0
mirror of https://github.com/dtolnay/rust-toolchain.git synced 2025-06-02 07:33:35 +03:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
David Tolnay 2020-05-02 11:31:04 -07:00
commit 637c7a32b7
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
21 changed files with 10929 additions and 0 deletions

11
.editorconfig Normal file
View file

@ -0,0 +1,11 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
max_line_length = 80
indent_size = 4
[*.yml]
indent_size = 2

19
.eslintrc.json Normal file
View file

@ -0,0 +1,19 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/ban-ts-ignore": "off"
}
}

15
.githooks/pre-commit Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
# This commit hook checks whether we ran `npm run build` when committed TypeScript files.
# For GitHub actions to work, we need to check the compiled JavaScript into VCS.
#
# This script can yield false positives in cases where you only make stylistic changes to the TypeScript code that don't result in changes to the compiled JavaScript code.
# It is your responsibility as a developer to then commit the changes with `git commit --no-verify` and simply skip this commit hook.
TS_FILES=$(git diff --staged --name-only | grep -c '.ts')
DIST_MODIFIED=$(git diff --staged --name-only | grep -c dist/index.js)
if [ $TS_FILES -gt 0 ] && [ $DIST_MODIFIED -eq 0 ] ; then
echo "You modified TypeScript files but apparently did not run 'npm run build'".
exit 1;
fi

72
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,72 @@
name: Continuous integration
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Create npm configuration
run: echo "//npm.pkg.github.com/:_authToken=${token}" >> ~/.npmrc
env:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v1
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm run test
install_stable:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
steps:
- uses: actions/checkout@v1
- id: toolchain
uses: ./
with:
toolchain: stable
- name: Test toolchain outputs
env:
RUSTC: ${{ steps.toolchain.outputs.rustc }}
RUSTC_HASH: ${{ steps.toolchain.outputs.rustc_hash }}
CARGO: ${{ steps.toolchain.outputs.cargo }}
RUSTUP: ${{ steps.toolchain.outputs.rustup }}
run: |
echo $RUSTC
echo $RUSTC_HASH
echo $CARGO
echo $RUSTUP
install_nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
install_stable_in_docker:
runs-on: ubuntu-latest
container: ubuntu:latest # Docker image, not the GitHub Actions VM
steps:
# `rustup` will need `curl` or `wget` later
- run: apt-get update && apt-get install -y curl
- uses: actions/checkout@v1
- uses: ./
with:
toolchain: stable
install_stable_through_rust_toolchain_file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: echo "stable" > ./rust-toolchain
- uses: ./

94
.gitignore vendored Normal file
View file

@ -0,0 +1,94 @@
__tests__/runner/*
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# IntelliJ IDEs
.idea

1
.npmrc Normal file
View file

@ -0,0 +1 @@
@actions-rs:registry=https://npm.pkg.github.com

49
CHANGELOG.md Normal file
View file

@ -0,0 +1,49 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.6] - 2020-03-24
### Added
- Pass `allow-downgrade` flag to `rustup` if `nightly` toolchain with components requested
## [1.0.5] - 2020-01-26
### Fixed
- `rustup` version parser does not fail Action execution on `macOS-latest` VM images anymore
## [1.0.4] - 2020-01-26
### Added
- Support for the `rust-toolchain` file: If the toolchain input is not given, we will try and install the version specified in the `rust-toolchain` file.
- Action outputs with `rustc`, `cargo` and `rustup` versions installed
## [1.0.3] - 2019-10-19
### Added
- Support for `rustup set profile` command
- Support for `--component` flag for the `rustup toolchain install` command
## [1.0.2] - 2019-10-14
### Changed
- Missing `rustup` executable will not raise an annotating warning before the installation anymore (#13)
## [1.0.1] - 2019-10-05
### Changed
- `target` input is not used as a `--default-target` argument for `rustup` anymore (#8)
## [1.0.0] - 2019-09-15
### Added
- First public version

22
LICENSE Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2019 actions-rs team and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

169
README.md Normal file
View file

@ -0,0 +1,169 @@
# `rust-toolchain` Action
[![Sponsoring](https://img.shields.io/badge/Support%20it-Say%20%22Thank%20you!%22-blue)](https://actions-rs.github.io/#sponsoring)
![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)
[![Gitter](https://badges.gitter.im/actions-rs/community.svg)](https://gitter.im/actions-rs/community)
![Continuous integration](https://github.com/actions-rs/toolchain/workflows/Continuous%20integration/badge.svg)
![Dependabot enabled](https://api.dependabot.com/badges/status?host=github&repo=actions-rs/toolchain)
This GitHub Action installs [Rust toolchain](https://github.com/rust-lang/rustup.rs#toolchain-specification)
with [rustup](https://github.com/rust-lang/rustup) help.
It supports additional targets, components and profiles and handles all
these small papercuts for you.
**Table of Contents**
* [Example workflow](#example-workflow)
* [Inputs](#inputs)
* [Outputs](#outputs)
* [Profiles](#profiles)
* [Components](#components)
* [The toolchain file](#the-toolchain-file)
* [License](#license)
* [Contribute and support](#contribute-and-support)
## Example workflow
```yaml
on: [push]
name: build
jobs:
check:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy
# `cargo check` command here will use installed `nightly`
# as it is set as an "override" for current directory
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
```
See [additional recipes here](https://github.com/actions-rs/meta).
## Inputs
| Name | Required | Description | Type | Default |
| ------------ | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------| ------ | --------|
| `toolchain` | | [Toolchain](https://github.com/rust-lang/rustup.rs#toolchain-specification) name to use, ex. `stable`, `nightly`, `nightly-2019-04-20`, or `1.32.0` | string | |
| `target` | | Additionally install specified target for this toolchain, ex. `x86_64-apple-darwin` | string | |
| `default` | | Set installed toolchain as a default toolchain | bool | false |
| `override` | | Set installed toolchain as an override for the current directory | bool | false |
| `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 | |
Note: since `v1.0.4` version, `toolchain` input is not marked as required
in order to support toolchain files. See the details [below](#the-toolchain-file).
## Outputs
Installed `rustc`, `cargo` and `rustup` versions can be fetched from the Action outputs:
| Name | Description | Example |
| ------------ | --------------------- | ------------------------------- |
| `rustc` | Rustc version | `1.40.0 (73528e339 2019-12-16)` |
| `rustc_hash` | Rustc version hash | `73528e339` |
| `cargo` | Cargo version | `1.40.0 (bc8e4c8be 2019-11-22)` |
| `rustup` | rustup version | `1.21.1 (7832b2ebe 2019-12-20)` |
Note: `rustc-hash` output value can be used with [actions/cache](https://github.com/actions/cache) Action
to store cache for different Rust versions, as it is unique across different Rust versions and builds (including `nightly`).
## Profiles
This Action supports rustup [profiles](https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html#profiles),
which are can be used to speed up the workflow execution by installing the
minimally required set of components, for example:
```yaml
- name: Install minimal nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
```
This Action will automatically run `rustup self update` if `profile` input is set
and the installed `rustup` version does not supports them.
In order to provide backwards compatibility for `v1` version,
there is no value for `profile` input set by default,
which means that the `default` profile is used by `rustup`
(and that includes `rust-docs`, `clippy` and `rustfmt`).\
You may want to consider using `profile: minimal` to speed up toolchain installation.
## Components
This Action supports rustup [components](https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html#installing-the-latest-compatible-nightly) too,
and in combination with the [profiles](#profiles) input it allows to install only the needed components:
```yaml
- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
```
As an extra perk, `rustup >= 1.20.0` is able to find the most recent `nightly` toolchain
with the requested components available; next example is utilizing this feature
to install the minimal set of `nightly` toolchain components with the `rustfmt` and `clippy` extras:
```yaml
- name: Install minimal nightly with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
```
In case if `nightly` toolchain is requested and one of the components is missing in
latest `nightly` release, this Action will attempt the downgrade till it find
the most recent `nightly` with all components needed.\
Note that this behavior will work only if the following two conditions apply:
1. `toolchain` input is `nightly` exactly.
2. At least one component is provided in `components` input.
Same to the `profile` input, if installed `rustup` does not supports "components",
it will be automatically upgraded by this Action.
## The toolchain file
This Action supports [toolchain files](https://github.com/rust-lang/rustup#the-toolchain-file),
so it is not necessary to use `toolchain` input anymore.
Input has higher priority, so if you are want to use toolchain file,
you need to remove the input from the workflow file.
If neither `toolchain` input or `rust-toolchain` file are provided,
Action execution will fail.
## License
This Action is distributed under the terms of the MIT license, see [LICENSE](https://github.com/actions-rs/toolchain/blob/master/LICENSE) for details.
## Contribute and support
Any contributions are welcomed!
If you want to report a bug or have a feature request,
check the [Contributing guide](https://github.com/actions-rs/.github/blob/master/CONTRIBUTING.md).
You can also support author by funding the ongoing project work,
see [Sponsoring](https://actions-rs.github.io/#sponsoring).

74
__tests__/args.test.ts Normal file
View file

@ -0,0 +1,74 @@
import { getToolchainArgs } from "../src/args";
import { morph } from "mock-env";
import { sync as tempWriteSync } from "temp-write";
describe("actions-rs/toolchain", () => {
it("Parses action input into toolchain options", () => {
const args = morph(
() => {
return getToolchainArgs("./rust-toolchain");
},
{
INPUT_TOOLCHAIN: "nightly-2019-04-20",
INPUT_DEFAULT: "false",
INPUT_OVERRIDE: "true",
}
);
expect(args.name).toBe("nightly-2019-04-20");
expect(args.default).toBe(false);
expect(args.override).toBe(true);
});
it("uses input variable if rust-toolchain file does not exist", function () {
const args = morph(
() => {
return getToolchainArgs("./rust-toolchain");
},
{
INPUT_TOOLCHAIN: "nightly",
}
);
expect(args.name).toBe("nightly");
});
it("toolchain input is required if rust-toolchain does not exist", function () {
expect(() => getToolchainArgs("./rust-toolchain")).toThrowError();
});
it("prioritizes rust-toolchain file over input variable", function () {
const rustToolchainFile = tempWriteSync("1.39.0");
const args = morph(
() => {
return getToolchainArgs(rustToolchainFile);
},
{
INPUT_TOOLCHAIN: "nightly",
}
);
expect(args.name).toBe("nightly");
});
it("uses rust-toolchain file if input does not exist", function () {
const rustToolchainFile = tempWriteSync("1.39.0");
const args = morph(() => {
return getToolchainArgs(rustToolchainFile);
}, {});
expect(args.name).toBe("1.39.0");
});
it("trims content of the override file", function () {
const rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
const args = morph(() => {
return getToolchainArgs(rustToolchainFile);
}, {});
expect(args.name).toBe("1.39.0");
});
});

44
action.yml Normal file
View file

@ -0,0 +1,44 @@
name: 'rust-toolchain'
description: 'Install the Rust toolchain'
author: 'actions-rs team'
branding:
icon: play-circle
color: black
inputs:
toolchain:
description: |
Rust toolchain name.
See https://github.com/rust-lang/rustup.rs#toolchain-specification
If this is not given, the action will try and install the version specified in the `rust-toolchain` file.
required: false
target:
description: Target triple to install for this toolchain
required: false
default:
description: Set installed toolchain as default
default: false
override:
description: Set installed toolchain as an override for a directory
default: false
profile:
description: Name of the group of components to be installed for a new toolchain
required: false
components:
description: Comma-separated list of components to be additionally installed for a new toolchain
required: false
outputs:
rustc:
description: Installed Rustc version
rustc_hash:
description: Installed Rustc version hash, can be used for caching purposes
cargo:
description: Installed Cargo version
rustup:
description: Installed rustup version
runs:
using: 'node12'
main: 'dist/index.js'

1
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

11
jest.config.json Normal file
View file

@ -0,0 +1,11 @@
{
"clearMocks": true,
"moduleFileExtensions": ["js", "ts"],
"testEnvironment": "node",
"testMatch": ["**/*.test.ts"],
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true
}

9980
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

58
package.json Normal file
View file

@ -0,0 +1,58 @@
{
"name": "rust-toolchain",
"version": "1.0.6",
"private": false,
"description": "Install the Rust toolchain",
"main": "lib/main.js",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"scripts": {
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify",
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'",
"lint": "tsc --noEmit && eslint 'src/**/*.ts' '__tests__/**/*.ts'",
"watch": "rm -rf ./dist/* && ncc build src/main.ts --watch",
"test": "jest -c jest.config.json",
"pretest": "git config core.hooksPath .githooks"
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions-rs/toolchain.git"
},
"keywords": [
"actions",
"rust",
"rustup",
"toolchain"
],
"author": "actions-rs",
"license": "MIT",
"bugs": {
"url": "https://github.com/actions-rs/toolchain/issues"
},
"dependencies": {
"@actions-rs/core": "^0.0.9",
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@types/jest": "^25.1.4",
"@types/node": "^13.9.3",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"@zeit/ncc": "^0.22.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"mock-env": "^0.2.0",
"npm-check-updates": "^4.0.5",
"prettier": "^2.0.2",
"temp-write": "^4.0.0",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
}
}

52
src/args.ts Normal file
View file

@ -0,0 +1,52 @@
import { input } from "@actions-rs/core";
import { debug } from "@actions/core";
import { existsSync, readFileSync } from "fs";
export interface ToolchainOptions {
name: string;
target: string | undefined;
default: boolean;
override: boolean;
profile: string | undefined;
components: string[] | undefined;
}
function determineToolchain(overrideFile: string): string {
const toolchainInput = input.getInput("toolchain", { required: false });
if (toolchainInput) {
debug(`using toolchain from input: ${toolchainInput}`);
return toolchainInput;
}
if (!existsSync(overrideFile)) {
throw new Error(
"toolchain input was not given and repository does not have a rust-toolchain file"
);
}
const rustToolchainFile = readFileSync(overrideFile, {
encoding: "utf-8",
flag: "r",
}).trim();
debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
return rustToolchainFile;
}
export function getToolchainArgs(overrideFile: string): ToolchainOptions {
let components: string[] | undefined = input.getInputList("components");
if (components && components.length === 0) {
components = undefined;
}
return {
name: determineToolchain(overrideFile),
target: input.getInput("target") || undefined,
default: input.getInputBool("default"),
override: input.getInputBool("override"),
profile: input.getInput("profile") || undefined,
components: components,
};
}

97
src/main.ts Normal file
View file

@ -0,0 +1,97 @@
import * as core from "@actions/core";
import path from "path";
import * as args from "./args";
import * as versions from "./versions";
import { RustUp, ToolchainOptions } from "@actions-rs/core";
async function run(): Promise<void> {
// we use path.join to make sure this works on Windows, Linux and MacOS
const toolchainOverridePath = path.join(process.cwd(), "rust-toolchain");
const opts = args.getToolchainArgs(toolchainOverridePath);
const rustup = await RustUp.getOrInstall();
await rustup.call(["show"]);
let shouldSelfUpdate = false;
if (opts.profile && !(await rustup.supportProfiles())) {
shouldSelfUpdate = true;
}
if (opts.components && !(await rustup.supportComponents())) {
shouldSelfUpdate = true;
}
if (shouldSelfUpdate) {
core.startGroup("Updating rustup");
try {
await rustup.selfUpdate();
} finally {
core.endGroup();
}
}
if (opts.profile) {
// @ts-ignore: TS2345
await rustup.setProfile(opts.profile);
}
const installOptions: ToolchainOptions = {
default: opts.default,
override: opts.override,
};
if (opts.components) {
installOptions.components = opts.components;
}
// We already did it just now, there is no reason to do that again,
// so it would skip few network calls.
if (shouldSelfUpdate) {
installOptions.noSelfUpdate = true;
}
// Extra funny case.
// Due to `rustup` issue (https://github.com/rust-lang/rustup/issues/2146)
// right now installing `nightly` toolchain with extra components might fail
// if that specific `nightly` version does not have this component
// available.
//
// See https://github.com/actions-rs/toolchain/issues/53 also.
//
// By default `rustup` does not downgrade, as it does when you are
// updating already installed `nightly`, so we need to pass the
// corresponding flag manually.
//
// We are doing it only if both following conditions apply:
//
// 1. Requested toolchain is `"nightly"` (exact string match).
// 2. At least one component is requested.
//
// All other cases are not triggering automatic downgrade,
// for example, installing specific nightly version
// as in `"nightly-2020-03-20"` or `"stable"`.
//
// Motivation is that users probably want the latest one nightly
// with rustfmt and clippy (miri, etc) and they don't really care
// about what exact nightly it is.
// In case if it's not the nightly at all or it is a some specific
// nightly version, they know what they are doing.
if (opts.name == "nightly" && opts.components) {
installOptions.allowDowngrade = true;
}
await rustup.installToolchain(opts.name, installOptions);
if (opts.target) {
await rustup.addTarget(opts.target, opts.name);
}
await versions.gatherInstalledVersions();
}
async function main(): Promise<void> {
try {
await run();
} catch (error) {
core.setFailed(error.message);
}
}
main();

114
src/versions.ts Normal file
View file

@ -0,0 +1,114 @@
import * as exec from "@actions/exec";
import * as core from "@actions/core";
interface Version {
long: string;
hash: string;
}
/**
* Try to parse the version parts and return them.
*
* It is important to note that some components are not providing
* all the expected information, ex. `rustup` on `macOS-latest` VM image
* does not has the hash in the version string,
* so this function might throw an error.
*
* As a fallback, `parseShort` function can be used.
*/
function parseFull(stdout: string): Version {
const regex = /\S+\s((\S+)\s\((\S+)\s(\S+)\))/m;
stdout = stdout.trim();
const matches = regex.exec(stdout);
if (matches == null) {
throw new Error(`Unable to parse version from the "${stdout}" string`);
}
return {
long: matches[1],
hash: matches[3],
};
}
function parseShort(stdout: string): string {
const regex = /\S+\s(.+)/m;
stdout = stdout.trim();
const matches = regex.exec(stdout);
if (matches == null) {
core.warning(`Unable to determine version from the "${stdout}" string`);
return "";
} else {
return matches[1];
}
}
async function getStdout(
exe: string,
args: string[],
options?: {}
): Promise<string> {
let stdout = "";
const resOptions = Object.assign({}, options, {
listeners: {
stdout: (buffer: Buffer): void => {
stdout += buffer.toString();
},
},
});
await exec.exec(exe, args, resOptions);
return stdout;
}
/**
* Fetch currently used `rustc` version
*/
async function rustc(): Promise<void> {
const stdout = await getStdout("rustc", ["-V"]);
try {
const version = parseFull(stdout);
core.setOutput("rustc", version.long);
core.setOutput("rustc_hash", version.hash);
} catch (e) {
core.warning(e);
core.setOutput("rustc", parseShort(stdout));
}
}
/**
* Fetch currently used `cargo` version
*/
async function cargo(): Promise<void> {
const stdout = await getStdout("cargo", ["-V"]);
try {
const version = parseFull(stdout);
core.setOutput("cargo", version.long);
} catch (e) {
core.setOutput("cargo", parseShort(stdout));
}
}
async function rustup(): Promise<void> {
const stdout = await getStdout("rustup", ["-V"]);
try {
const version = parseFull(stdout);
core.setOutput("rustup", version.long);
} catch (e) {
core.setOutput("rustup", parseShort(stdout));
}
}
export async function gatherInstalledVersions(): Promise<void> {
try {
core.startGroup("Gathering installed versions");
await rustc();
await cargo();
await rustup();
} finally {
core.endGroup();
}
}

7
tsconfig.eslint.json Normal file
View file

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"__tests__/**/*.ts"
]
}

32
tsconfig.json Normal file
View file

@ -0,0 +1,32 @@
{
"compilerOptions": {
"allowJs": false,
"checkJs": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"newLine": "LF",
"noEmitOnError": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"pretty": true,
"removeComments": true,
"resolveJsonModule": true,
"strict": true,
"suppressImplicitAnyIndexErrors": false,
"target": "es2018",
"declaration": false,
"sourceMap": false,
"typeRoots": ["./types", "./node_modules/@types"]
},
"include": [
"src/**/*.ts"
]
}

7
types/mock-env/index.d.ts vendored Normal file
View file

@ -0,0 +1,7 @@
declare module "mock-env" {
function morph<T>(
callback: () => T,
vars: object,
toRemove?: string[]
): any;
}