Compare commits

...

39 Commits

Author SHA1 Message Date
Ivan Tham 88dc235639 Mention the default for toolchain and profile 2020-11-29 18:15:29 +01:00
Pytal b3ea035039 Fix typo 2020-11-28 10:37:02 +01:00
svartalf 16499b5e05 Bump dependencies 2020-11-17 15:27:55 +01:00
dependabot-preview[bot] 4d9a2b11c1 [Security] Bump @actions/core from 1.2.3 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.3 to 1.2.6. **This update includes a security fix.**
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-17 14:27:58 +01:00
MindSwipe 83a0369c8d Fix dead link to Rust toolchain specification 2020-10-05 18:58:42 +02:00
Will Stott 3639e8fd46 README: Fix link to toolchain file.
No longer in the rustup readme!
2020-09-24 20:28:49 +02:00
Arthur Arnold 69f9ca11d9 Update README.md
Fix link to rustup toolchain specification
2020-09-16 06:55:07 +02:00
David Tolnay b223206e28 Fix ts file identification in pre-commit hook 2020-05-02 23:48:49 +03:00
svartalf 7f00d1018c
Small typo 2020-04-07 09:19:47 +03:00
svartalf 4d3830945c Freeze changelog for v1.0.6 release 2020-03-24 16:29:33 +03:00
svartalf b2417cde72 Release v1.0.6 2020-03-24 16:27:19 +03:00
svartalf 8e14415dec Changing buymeacoffee link 2020-03-19 16:58:35 +03:00
svartalf 396d1ee271 Extra funding links 2020-03-19 16:09:22 +03:00
svartalf 23cd1093e2 Release v1.0.5 2020-01-26 19:20:01 +03:00
svartalf 402d025565 Release v1.0.4 2020-01-26 18:38:00 +03:00
svartalf 5d50a12f35
Output rustc, cargo and rustup versions as Action outputs (#47) 2020-01-26 18:18:21 +03:00
svartalf ad7f1a0189 Bumping dependencies versions in a bulk 2020-01-24 13:53:13 +03:00
Thomas Eizinger d8323be6bd Dont prioritze rust-toolchain file over input variable (#45) 2020-01-17 15:21:07 +03:00
Thomas Eizinger 6a1db6369e Allow to override toolchain from rust-toolchain file (#35) 2020-01-13 16:31:26 +03:00
dependabot-preview[bot] e2aeba25b2 Bump @types/node from 12.12.12 to 12.12.14
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.12 to 12.12.14.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-02 07:27:40 +00:00
dependabot-preview[bot] e3ee71a17e Bump @types/node from 12.12.8 to 12.12.12
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.8 to 12.12.12.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-25 07:40:22 +00:00
dependabot-preview[bot] 1ce6b1d112 Bump @actions-rs/core from 0.0.7 to 0.0.8
Bumps [@actions-rs/core](https://github.com/actions-rs/core) from 0.0.7 to 0.0.8.
- [Release notes](https://github.com/actions-rs/core/releases)
- [Commits](https://github.com/actions-rs/core/compare/v0.0.7...v0.0.8)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-25 07:36:19 +00:00
dependabot-preview[bot] f2024a92ea Bump ts-jest from 24.1.0 to 24.2.0
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 24.1.0 to 24.2.0.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v24.1.0...v24.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-25 07:35:10 +00:00
Philipp Oppermann 6f9b172a64 Fix component example in Readme
The comment talks about a stable Rust version, but the configuration was set to nightly.
2019-11-18 14:53:28 +03:00
dependabot-preview[bot] d03d2d0fa3 Bump @types/jest from 24.0.22 to 24.0.23
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.22 to 24.0.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-18 07:40:08 +00:00
dependabot-preview[bot] 9db57f6e68 Bump @types/node from 12.12.7 to 12.12.8
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.7 to 12.12.8.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-18 07:36:17 +00:00
dependabot-preview[bot] 5d172335f8 Bump @types/node from 12.11.7 to 12.12.7
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.11.7 to 12.12.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-11 10:18:54 +00:00
dependabot-preview[bot] a7a240846b Bump @types/jest from 24.0.20 to 24.0.22
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.20 to 24.0.22.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-11 10:13:37 +00:00
dependabot-preview[bot] 3254cb49ae Bump typescript from 3.6.4 to 3.7.2
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.6.4 to 3.7.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.6.4...v3.7.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-11 10:11:56 +00:00
dependabot-preview[bot] 5ed95ab73b Bump @types/node from 12.11.1 to 12.11.7
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.11.1 to 12.11.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-28 07:58:17 +00:00
dependabot-preview[bot] 6696391ce4 Bump @types/jest from 24.0.19 to 24.0.20
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.19 to 24.0.20.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-28 07:52:48 +00:00
svartalf f0a61e6769 Profiles and components support 2019-10-19 13:28:57 +03:00
dependabot-preview[bot] 74865b8fc9 Bump @types/jest from 24.0.18 to 24.0.19
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.18 to 24.0.19.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-17 06:12:18 +00:00
dependabot-preview[bot] 269db1d873 Bump @types/node from 12.7.12 to 12.11.1
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.7.12 to 12.11.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-17 06:09:07 +00:00
svartalf 941154aed5 Release 1.0.2 2019-10-14 18:31:15 +03:00
dependabot-preview[bot] a919188b61
Merge pull request #11 from actions-rs/dependabot/npm_and_yarn/types/node-12.7.12 2019-10-14 15:16:26 +00:00
dependabot-preview[bot] beaa269702 Bump typescript from 3.6.3 to 3.6.4
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.6.3 to 3.6.4.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.6.3...v3.6.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-14 18:15:08 +03:00
Lionel Faber ad3964bd05 Use info log level when installing rustup 2019-10-14 15:19:08 +03:00
dependabot-preview[bot] 46a11bddfe
Bump @types/node from 12.7.11 to 12.7.12
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.7.11 to 12.7.12.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-09 10:18:58 +00:00
21 changed files with 5760 additions and 2952 deletions

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

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
custom: https://svartalf.info/donate/

View File

@ -1,18 +1,73 @@
name: Continuous integration
on: [pull_request, push]
on: [push, pull_request]
jobs:
check_pr:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create npm configuration
run: echo "//npm.pkg.github.com/:_authToken=${token}" >> ~/.npmrc
env:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "npm ci"
run: npm ci
- uses: actions/checkout@v1
- run: npm ci
# Temporary disabling in order to release urgent fix
# - run: npm run lint
- run: npm run build
- run: npm run test
- name: "npm run build"
run: npm run build
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
- name: "npm run test"
run: npm run test
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: ./

3
.gitignore vendored
View File

@ -89,3 +89,6 @@ typings/
# DynamoDB Local files
.dynamodb/
# IntelliJ IDEs
.idea

1
.npmrc Normal file
View File

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

View File

@ -4,6 +4,38 @@ 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

146
README.md
View File

@ -1,11 +1,27 @@
# `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).
This GitHub Action installs [Rust toolchain](https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification)
with [rustup](https://github.com/rust-lang/rustup) help.
Optionally it can set installed toolchain as a default and as an override for current directory.
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
@ -19,15 +35,16 @@ jobs:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install nightly
- 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 set as an "override" for current directory
# as it is set as an "override" for current directory
- name: Run cargo check
uses: actions-rs/cargo@v1
@ -39,21 +56,114 @@ 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` | 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 |
| 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 | stable |
| `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 | default |
| `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
If you are going to install `clippy`, `rustfmt` or any other [rustup component](https://rust-lang.github.io/rustup-components-history/),
it might not be available in latest `nightly` build;
check out the [`actions-rs/components-nightly`](https://github.com/actions-rs/components-nightly) Action,
which makes this process much easier.
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:
## Notes
```yaml
- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
```
As `rustup` is not installed by default for [macOS environments](https://help.github.com/en/articles/virtual-environments-for-github-actions)
at the moment (2019-09-13), this Action will try its best to install it before any other operations.
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://rust-lang.github.io/rustup/overrides.html#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).

View File

@ -1,22 +1,74 @@
import * as args from '../src/args'
import { getToolchainArgs } from "../src/args";
import { morph } from "mock-env";
import { sync as tempWriteSync } from "temp-write";
const testEnvVars = {
INPUT_TOOLCHAIN: 'nightly-2019-04-20',
INPUT_DEFAULT: 'false',
INPUT_OVERRIDE: 'true'
}
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",
}
);
describe('actions-rs/toolchain', () => {
beforeEach(() => {
for (const key in testEnvVars)
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
})
expect(args.name).toBe("nightly-2019-04-20");
expect(args.default).toBe(false);
expect(args.override).toBe(true);
});
it('Parses action input into toolchain options', async () => {
const result = args.toolchain_args();
it("uses input variable if rust-toolchain file does not exist", function () {
const args = morph(
() => {
return getToolchainArgs("./rust-toolchain");
},
{
INPUT_TOOLCHAIN: "nightly",
}
);
expect(result.name).toBe('nightly-2019-04-20');
expect(result.default).toBe(false);
expect(result.override).toBe(true);
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");
});
});

View File

@ -9,7 +9,10 @@ inputs:
description: |
Rust toolchain name.
See https://github.com/rust-lang/rustup.rs#toolchain-specification
See https://rust-lang.github.io/rustup/concepts/toolchains.html#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
@ -19,6 +22,22 @@ inputs:
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'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

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

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
}

7802
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "rust-toolchain",
"version": "1.0.1",
"version": "1.0.7",
"private": false,
"description": "Install the Rust toolchain",
"main": "lib/main.js",
@ -9,9 +9,12 @@
"test": "__tests__"
},
"scripts": {
"build": "ncc build src/main.ts --minify",
"watch": "ncc build src/main.ts --watch",
"test": "jest"
"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",
@ -29,18 +32,27 @@
"url": "https://github.com/actions-rs/toolchain/issues"
},
"dependencies": {
"@actions/core": "^1.1.1",
"@actions/exec": "^1.0.0",
"@actions/io": "^1.0.0",
"download": "^7.1.0"
"@actions-rs/core": "^0.1.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@types/jest": "^24.0.13",
"@types/node": "^12.7.11",
"@zeit/ncc": "^0.20.5",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"ts-jest": "^24.1.0",
"typescript": "^3.5.1"
"@types/jest": "^26.0.15",
"@types/node": "^14.14.7",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"@zeit/ncc": "^0.22.3",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"mock-env": "^0.2.0",
"npm-check-updates": "^10.2.1",
"prettier": "^2.1.2",
"temp-write": "^4.0.0",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5"
}
}

View File

@ -1,43 +1,52 @@
import * as core from '@actions/core';
// Workaround for a GH bug: https://github.com/actions/toolkit/issues/127
//
// For input `all-features: true` it will generate the `INPUT_ALL-FEATURES: true`
// env variable, which looks too weird.
// Here we are trying to get proper name `INPUT_NO_DEFAULT_FEATURES` first,
// and if it does not exist, trying the `INPUT_NO-DEFAULT-FEATURES`
function getInput(name: string, options?: core.InputOptions): string {
const inputFullName = name.replace(/-/g, '_');
let value = core.getInput(inputFullName, options);
if (value.length > 0) {
return value
}
return core.getInput(name)
}
function inputBoolean(name: string): boolean {
const value = getInput(name);
if (value == 'true' || value == '1') {
return true;
} else {
return false;
}
}
import { input } from "@actions-rs/core";
import { debug } from "@actions/core";
import { existsSync, readFileSync } from "fs";
export interface ToolchainOptions {
name: string,
target?: string,
default: boolean,
override: boolean
name: string;
target: string | undefined;
default: boolean;
override: boolean;
profile: string | undefined;
components: string[] | undefined;
}
export function toolchain_args(): ToolchainOptions {
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: getInput('toolchain', {required: true}),
target: getInput('target') || undefined,
default: inputBoolean('default'),
override: inputBoolean('override')
name: determineToolchain(overrideFile),
target: input.getInput("target") || undefined,
default: input.getInputBool("default"),
override: input.getInputBool("override"),
profile: input.getInput("profile") || undefined,
components: components,
};
}

View File

@ -1,95 +1,92 @@
const os = require('os');
const fs = require('fs');
const path = require('path');
const https = require('https');
import * as core from "@actions/core";
import path from "path";
const download = require('download');
import * as args from "./args";
import * as versions from "./versions";
import { RustUp, ToolchainOptions } from "@actions-rs/core";
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
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");
import * as args from './args';
const opts = args.getToolchainArgs(toolchainOverridePath);
const rustup = await RustUp.getOrInstall();
await rustup.call(["show"]);
function downloadRustInit(url: string, name: string): Promise<string> {
const absPath = path.join(os.tmpdir(), name);
return new Promise((resolve, reject) => {
let req = download(url);
let output = fs.createWriteStream(absPath, {
mode: 0o755
});
req.pipe(output);
req.on('end', () => {
output.close(resolve);
});
req.on('error', reject);
output.on('error', reject);
})
.then(() => {
return absPath;
});
}
async function get_rustup(toolchain: string): Promise<string> {
try {
const foundPath = await io.which('rustup', true);
core.debug(`Found rustup at ${foundPath}`);
return foundPath;
} catch (error) {
core.warning('Unable to find rustup, installing it now');
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();
}
}
let args = [
'-y',
'--default-toolchain',
toolchain,
];
// Note: `target` input can't be used here for `--default-host` argument, see #8
switch (process.platform) {
case 'darwin':
case 'linux': // Should be installed already, but just in case
const rustupSh = await downloadRustInit('https://sh.rustup.rs', 'rustup-init.sh');
await exec.exec(rustupSh, args);
break;
case 'win32':
const rustupExe = await downloadRustInit('http://win.rustup.rs', 'rustup-init.exe');
await exec.exec(rustupExe, args);
break;
default:
throw new Error(`Unknown platform ${process.platform}, can't install rustup`);
if (opts.profile) {
// @ts-ignore: TS2345
await rustup.setProfile(opts.profile);
}
core.addPath(path.join(process.env['HOME'], '.cargo', 'bin'));
return 'rustup';
}
async function run() {
const opts = args.toolchain_args();
const rustup = await get_rustup(opts.name);
await exec.exec(rustup, ['toolchain', 'install', opts.name]);
if (opts.default) {
await exec.exec(rustup, ['default', opts.name]);
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;
}
if (opts.override) {
await exec.exec(rustup, ['override', 'set', opts.name]);
// 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 exec.exec(rustup, ['target', 'add', '--toolchain', opts.name, opts.target]);
await rustup.addTarget(opts.target, opts.name);
}
await versions.gatherInstalledVersions();
}
async function main() {
async function main(): Promise<void> {
try {
await run();
} catch (error) {

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"
]
}

View File

@ -1,63 +1,32 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["node_modules", "**/*.test.ts"]
"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;
}