Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 37a15a2

Browse files
committed
Fully support modern toolchain file
1 parent 88dc235 commit 37a15a2

21 files changed

+223
-137
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"parser": "@typescript-eslint/parser",
3-
"parserOptions": {
4-
"project": "./tsconfig.eslint.json"
5-
},
6-
"plugins": ["@typescript-eslint"],
7-
"extends": [
8-
"eslint:recommended",
9-
"plugin:@typescript-eslint/eslint-recommended",
10-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11-
"plugin:@typescript-eslint/recommended",
12-
"plugin:prettier/recommended",
13-
"prettier",
14-
"prettier/@typescript-eslint"
15-
],
16-
"rules": {
17-
"@typescript-eslint/ban-ts-ignore": "off"
18-
}
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"project": "./tsconfig.eslint.json"
5+
},
6+
"plugins": ["@typescript-eslint"],
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11+
"plugin:@typescript-eslint/recommended",
12+
"plugin:prettier/recommended",
13+
"prettier",
14+
"prettier/@typescript-eslint"
15+
],
16+
"rules": {
17+
"@typescript-eslint/ban-ts-ignore": "off"
18+
}
1919
}

.github/workflows/ci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ jobs:
1313

1414
- uses: actions/checkout@v1
1515
- run: npm ci
16-
# Temporary disabling in order to release urgent fix
17-
# - run: npm run lint
16+
- run: npm run lint
1817
- run: npm run build
1918
- run: npm run test
2019

@@ -56,7 +55,7 @@ jobs:
5655

5756
install_stable_in_docker:
5857
runs-on: ubuntu-latest
59-
container: ubuntu:latest # Docker image, not the GitHub Actions VM
58+
container: ubuntu:latest # Docker image, not the GitHub Actions VM
6059
steps:
6160
# `rustup` will need `curl` or `wget` later
6261
- run: apt-get update && apt-get install -y curl

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ typings/
9292

9393
# IntelliJ IDEs
9494
.idea
95+
96+
.npmrc

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts:
2+
node_modules
3+
dist

.prettierrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

CHANGELOG.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -8,42 +9,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
89

910
### Added
1011

11-
- Pass `allow-downgrade` flag to `rustup` if `nightly` toolchain with components requested
12+
- Pass `allow-downgrade` flag to `rustup` if `nightly` toolchain with components requested
1213

1314
## [1.0.5] - 2020-01-26
1415

1516
### Fixed
1617

17-
- `rustup` version parser does not fail Action execution on `macOS-latest` VM images anymore
18+
- `rustup` version parser does not fail Action execution on `macOS-latest` VM images anymore
1819

1920
## [1.0.4] - 2020-01-26
2021

2122
### Added
2223

23-
- 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.
24-
- Action outputs with `rustc`, `cargo` and `rustup` versions installed
24+
- 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.
25+
- Action outputs with `rustc`, `cargo` and `rustup` versions installed
2526

2627
## [1.0.3] - 2019-10-19
2728

2829
### Added
2930

30-
- Support for `rustup set profile` command
31-
- Support for `--component` flag for the `rustup toolchain install` command
31+
- Support for `rustup set profile` command
32+
- Support for `--component` flag for the `rustup toolchain install` command
3233

3334
## [1.0.2] - 2019-10-14
3435

3536
### Changed
3637

37-
- Missing `rustup` executable will not raise an annotating warning before the installation anymore (#13)
38+
- Missing `rustup` executable will not raise an annotating warning before the installation anymore (#13)
3839

3940
## [1.0.1] - 2019-10-05
4041

4142
### Changed
4243

43-
- `target` input is not used as a `--default-target` argument for `rustup` anymore (#8)
44+
- `target` input is not used as a `--default-target` argument for `rustup` anymore (#8)
4445

4546
## [1.0.0] - 2019-09-15
4647

4748
### Added
4849

49-
- First public version
50+
- First public version

README.md

+44-44
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ these small papercuts for you.
1414

1515
**Table of Contents**
1616

17-
* [Example workflow](#example-workflow)
18-
* [Inputs](#inputs)
19-
* [Outputs](#outputs)
20-
* [Profiles](#profiles)
21-
* [Components](#components)
22-
* [The toolchain file](#the-toolchain-file)
23-
* [License](#license)
24-
* [Contribute and support](#contribute-and-support)
17+
- [Example workflow](#example-workflow)
18+
- [Inputs](#inputs)
19+
- [Outputs](#outputs)
20+
- [Profiles](#profiles)
21+
- [Components](#components)
22+
- [The toolchain file](#the-toolchain-file)
23+
- [License](#license)
24+
- [Contribute and support](#contribute-and-support)
2525

2626
## Example workflow
2727

@@ -31,33 +31,33 @@ on: [push]
3131
name: build
3232

3333
jobs:
34-
check:
35-
name: Rust project
36-
runs-on: ubuntu-latest
37-
steps:
38-
- uses: actions/checkout@v2
39-
- name: Install latest nightly
40-
uses: actions-rs/toolchain@v1
41-
with:
42-
toolchain: nightly
43-
override: true
44-
components: rustfmt, clippy
45-
46-
# `cargo check` command here will use installed `nightly`
47-
# as it is set as an "override" for current directory
48-
49-
- name: Run cargo check
50-
uses: actions-rs/cargo@v1
51-
with:
52-
command: check
34+
check:
35+
name: Rust project
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
- name: Install latest nightly
40+
uses: actions-rs/toolchain@v1
41+
with:
42+
toolchain: nightly
43+
override: true
44+
components: rustfmt, clippy
45+
46+
# `cargo check` command here will use installed `nightly`
47+
# as it is set as an "override" for current directory
48+
49+
- name: Run cargo check
50+
uses: actions-rs/cargo@v1
51+
with:
52+
command: check
5353
```
5454
5555
See [additional recipes here](https://github.com/actions-rs/meta).
5656
5757
## Inputs
5858
5959
| Name | Required | Description | Type | Default |
60-
| ------------ | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------| ------ | --------|
60+
| ------------ | :------: | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------- |
6161
| `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 |
6262
| `target` | | Additionally install specified target for this toolchain, ex. `x86_64-apple-darwin` | string | |
6363
| `default` | | Set installed toolchain as a default toolchain | bool | false |
@@ -72,12 +72,12 @@ in order to support toolchain files. See the details [below](#the-toolchain-file
7272

7373
Installed `rustc`, `cargo` and `rustup` versions can be fetched from the Action outputs:
7474

75-
| Name | Description | Example |
76-
| ------------ | --------------------- | ------------------------------- |
77-
| `rustc` | Rustc version | `1.40.0 (73528e339 2019-12-16)` |
78-
| `rustc_hash` | Rustc version hash | `73528e339` |
79-
| `cargo` | Cargo version | `1.40.0 (bc8e4c8be 2019-11-22)` |
80-
| `rustup` | rustup version | `1.21.1 (7832b2ebe 2019-12-20)` |
75+
| Name | Description | Example |
76+
| ------------ | ------------------ | ------------------------------- |
77+
| `rustc` | Rustc version | `1.40.0 (73528e339 2019-12-16)` |
78+
| `rustc_hash` | Rustc version hash | `73528e339` |
79+
| `cargo` | Cargo version | `1.40.0 (bc8e4c8be 2019-11-22)` |
80+
| `rustup` | rustup version | `1.21.1 (7832b2ebe 2019-12-20)` |
8181

8282
Note: `rustc_hash` output value can be used with [actions/cache](https://github.com/actions/cache) Action
8383
to store cache for different Rust versions, as it is unique across different Rust versions and builds (including `nightly`).
@@ -92,8 +92,8 @@ minimally required set of components, for example:
9292
- name: Install minimal nightly
9393
uses: actions-rs/toolchain@v1
9494
with:
95-
profile: minimal
96-
toolchain: nightly
95+
profile: minimal
96+
toolchain: nightly
9797
```
9898

9999
This Action will automatically run `rustup self update` if `profile` input is set
@@ -114,9 +114,9 @@ and in combination with the [profiles](#profiles) input it allows to install onl
114114
- name: Install minimal stable with clippy and rustfmt
115115
uses: actions-rs/toolchain@v1
116116
with:
117-
profile: minimal
118-
toolchain: stable
119-
components: rustfmt, clippy
117+
profile: minimal
118+
toolchain: stable
119+
components: rustfmt, clippy
120120
```
121121

122122
As an extra perk, `rustup >= 1.20.0` is able to find the most recent `nightly` toolchain
@@ -127,18 +127,18 @@ to install the minimal set of `nightly` toolchain components with the `rustfmt`
127127
- name: Install minimal nightly with clippy and rustfmt
128128
uses: actions-rs/toolchain@v1
129129
with:
130-
profile: minimal
131-
toolchain: nightly
132-
components: rustfmt, clippy
130+
profile: minimal
131+
toolchain: nightly
132+
components: rustfmt, clippy
133133
```
134134

135135
In case if `nightly` toolchain is requested and one of the components is missing in
136136
latest `nightly` release, this Action will attempt the downgrade till it find
137137
the most recent `nightly` with all components needed.\
138138
Note that this behavior will work only if the following two conditions apply:
139139

140-
1. `toolchain` input is `nightly` exactly.
141-
2. At least one component is provided in `components` input.
140+
1. `toolchain` input is `nightly` exactly.
141+
2. At least one component is provided in `components` input.
142142

143143
Same to the `profile` input, if installed `rustup` does not supports "components",
144144
it will be automatically upgraded by this Action.

__tests__/args.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ describe("actions-rs/toolchain", () => {
6262
expect(args.name).toBe("1.39.0");
6363
});
6464

65+
it("uses new style rust-toolchain file if input does not exist", function () {
66+
const rustToolchainFile = tempWriteSync(
67+
'[toolchain]\nchannel = "1.51.0"\ncomponents = [ "rustfmt", "clippy" ]\nprofile = "minimal"\ntargets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]'
68+
);
69+
70+
const args = morph(() => {
71+
return getToolchainArgs(rustToolchainFile);
72+
}, {});
73+
74+
expect(args.name).toBe("1.51.0");
75+
expect(args.components).toStrictEqual(["rustfmt", "clippy"]);
76+
expect(args.profile).toBe("minimal");
77+
expect(args.target).toBe("wasm32-unknown-unknown");
78+
});
79+
80+
it("uses new style rust-toolchain file with toml ending if input and rust-toolchain file does not exist", function () {
81+
const rustToolchainFile = tempWriteSync(
82+
'[toolchain]\nchannel = "1.51.0"\ncomponents = [ "rustfmt", "clippy" ]\nprofile = "minimal"\ntargets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]',
83+
"./rust-toolchain.toml"
84+
);
85+
86+
const args = morph(() => {
87+
return getToolchainArgs(rustToolchainFile.replace(/\.toml^/, ""));
88+
}, {});
89+
90+
expect(args.name).toBe("1.51.0");
91+
expect(args.components).toStrictEqual(["rustfmt", "clippy"]);
92+
expect(args.profile).toBe("minimal");
93+
expect(args.target).toBe("wasm32-unknown-unknown");
94+
});
95+
6596
it("trims content of the override file", function () {
6697
const rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
6798

action.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: 'rust-toolchain'
2-
description: 'Install the Rust toolchain'
3-
author: 'actions-rs team'
1+
name: "rust-toolchain"
2+
description: "Install the Rust toolchain"
3+
author: "actions-rs team"
44
branding:
55
icon: play-circle
66
color: black
@@ -40,5 +40,5 @@ outputs:
4040
description: Installed rustup version
4141

4242
runs:
43-
using: 'node12'
44-
main: 'dist/index.js'
43+
using: "node12"
44+
main: "dist/index.js"

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"clearMocks": true,
3-
"moduleFileExtensions": ["js", "ts"],
4-
"testEnvironment": "node",
5-
"testMatch": ["**/*.test.ts"],
6-
"testRunner": "jest-circus/runner",
7-
"transform": {
8-
"^.+\\.ts$": "ts-jest"
9-
},
10-
"verbose": true
2+
"clearMocks": true,
3+
"moduleFileExtensions": ["js", "ts"],
4+
"testEnvironment": "node",
5+
"testMatch": ["**/*.test.ts"],
6+
"testRunner": "jest-circus/runner",
7+
"transform": {
8+
"^.+\\.ts$": "ts-jest"
9+
},
10+
"verbose": true
1111
}

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
"scripts": {
1212
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify",
13-
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'",
14-
"lint": "tsc --noEmit && eslint 'src/**/*.ts' '__tests__/**/*.ts'",
13+
"format": "prettier --write .",
14+
"lint": "tsc --noEmit && eslint .",
1515
"watch": "rm -rf ./dist/* && ncc build src/main.ts --watch",
1616
"test": "jest -c jest.config.json",
1717
"pretest": "git config core.hooksPath .githooks"
@@ -35,7 +35,8 @@
3535
"@actions-rs/core": "^0.1.6",
3636
"@actions/core": "^1.2.6",
3737
"@actions/exec": "^1.0.4",
38-
"@actions/io": "^1.0.2"
38+
"@actions/io": "^1.0.2",
39+
"@iarna/toml": "^2.2.5"
3940
},
4041
"devDependencies": {
4142
"@types/jest": "^26.0.15",

0 commit comments

Comments
 (0)