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

Commit

Permalink
Fully support modern toolchain file
Browse files Browse the repository at this point in the history
  • Loading branch information
boaz-codota committed Apr 5, 2021
1 parent 88dc235 commit 37a15a2
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
34 changes: 17 additions & 17 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,19 +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"
}
"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"
}
}
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:

- uses: actions/checkout@v1
- run: npm ci
# Temporary disabling in order to release urgent fix
# - run: npm run lint
- run: npm run lint
- run: npm run build
- run: npm run test

Expand Down Expand Up @@ -56,7 +55,7 @@ jobs:

install_stable_in_docker:
runs-on: ubuntu-latest
container: ubuntu:latest # Docker image, not the GitHub Actions VM
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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ typings/

# IntelliJ IDEs
.idea

.npmrc
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
node_modules
dist
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
19 changes: 10 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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/),
Expand All @@ -8,42 +9,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Pass `allow-downgrade` flag to `rustup` if `nightly` toolchain with components requested
- 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
- `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
- 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
- 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)
- 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)
- `target` input is not used as a `--default-target` argument for `rustup` anymore (#8)

## [1.0.0] - 2019-09-15

### Added

- First public version
- First public version
88 changes: 44 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ 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](#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

Expand All @@ -31,33 +31,33 @@ 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
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 | 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 |
Expand All @@ -72,12 +72,12 @@ in order to support toolchain files. See the details [below](#the-toolchain-file

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)` |
| 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`).
Expand All @@ -92,8 +92,8 @@ minimally required set of components, for example:
- name: Install minimal nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
profile: minimal
toolchain: nightly
```

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

As an extra perk, `rustup >= 1.20.0` is able to find the most recent `nightly` toolchain
Expand All @@ -127,18 +127,18 @@ to install the minimal set of `nightly` toolchain components with the `rustfmt`
- name: Install minimal nightly with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
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.
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.
Expand Down
31 changes: 31 additions & 0 deletions __tests__/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ describe("actions-rs/toolchain", () => {
expect(args.name).toBe("1.39.0");
});

it("uses new style rust-toolchain file if input does not exist", function () {
const rustToolchainFile = tempWriteSync(
'[toolchain]\nchannel = "1.51.0"\ncomponents = [ "rustfmt", "clippy" ]\nprofile = "minimal"\ntargets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]'
);

const args = morph(() => {
return getToolchainArgs(rustToolchainFile);
}, {});

expect(args.name).toBe("1.51.0");
expect(args.components).toStrictEqual(["rustfmt", "clippy"]);
expect(args.profile).toBe("minimal");
expect(args.target).toBe("wasm32-unknown-unknown");
});

it("uses new style rust-toolchain file with toml ending if input and rust-toolchain file does not exist", function () {
const rustToolchainFile = tempWriteSync(
'[toolchain]\nchannel = "1.51.0"\ncomponents = [ "rustfmt", "clippy" ]\nprofile = "minimal"\ntargets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]',
"./rust-toolchain.toml"
);

const args = morph(() => {
return getToolchainArgs(rustToolchainFile.replace(/\.toml^/, ""));
}, {});

expect(args.name).toBe("1.51.0");
expect(args.components).toStrictEqual(["rustfmt", "clippy"]);
expect(args.profile).toBe("minimal");
expect(args.target).toBe("wasm32-unknown-unknown");
});

it("trims content of the override file", function () {
const rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");

Expand Down
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'rust-toolchain'
description: 'Install the Rust toolchain'
author: 'actions-rs team'
name: "rust-toolchain"
description: "Install the Rust toolchain"
author: "actions-rs team"
branding:
icon: play-circle
color: black
Expand Down Expand Up @@ -40,5 +40,5 @@ outputs:
description: Installed rustup version

runs:
using: 'node12'
main: 'dist/index.js'
using: "node12"
main: "dist/index.js"
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"clearMocks": true,
"moduleFileExtensions": ["js", "ts"],
"testEnvironment": "node",
"testMatch": ["**/*.test.ts"],
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true
"clearMocks": true,
"moduleFileExtensions": ["js", "ts"],
"testEnvironment": "node",
"testMatch": ["**/*.test.ts"],
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"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'",
"format": "prettier --write .",
"lint": "tsc --noEmit && eslint .",
"watch": "rm -rf ./dist/* && ncc build src/main.ts --watch",
"test": "jest -c jest.config.json",
"pretest": "git config core.hooksPath .githooks"
Expand All @@ -35,7 +35,8 @@
"@actions-rs/core": "^0.1.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2"
"@actions/io": "^1.0.2",
"@iarna/toml": "^2.2.5"
},
"devDependencies": {
"@types/jest": "^26.0.15",
Expand Down
Loading

0 comments on commit 37a15a2

Please sign in to comment.