Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
402d025565 | ||
|
|
5d50a12f35 | ||
|
|
ad7f1a0189 | ||
|
|
d8323be6bd | ||
|
|
6a1db6369e | ||
|
|
e2aeba25b2 | ||
|
|
e3ee71a17e | ||
|
|
1ce6b1d112 | ||
|
|
f2024a92ea | ||
|
|
6f9b172a64 | ||
|
|
d03d2d0fa3 | ||
|
|
9db57f6e68 | ||
|
|
5d172335f8 | ||
|
|
a7a240846b | ||
|
|
3254cb49ae | ||
|
|
5ed95ab73b | ||
|
|
6696391ce4 | ||
|
|
f0a61e6769 | ||
|
|
74865b8fc9 | ||
|
|
269db1d873 |
15
.githooks/pre-commit
Executable file
15
.githooks/pre-commit
Executable 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
|
||||||
53
.github/workflows/ci.yml
vendored
53
.github/workflows/ci.yml
vendored
@@ -1,18 +1,53 @@
|
|||||||
name: Continuous integration
|
name: Continuous integration
|
||||||
|
|
||||||
on: [pull_request, push]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_pr:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
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"
|
- uses: actions/checkout@v1
|
||||||
run: npm ci
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run test
|
||||||
|
|
||||||
- name: "npm run build"
|
install_stable:
|
||||||
run: npm run build
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
- name: "npm run test"
|
install_nightly:
|
||||||
run: npm run test
|
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
3
.gitignore
vendored
@@ -89,3 +89,6 @@ typings/
|
|||||||
|
|
||||||
# DynamoDB Local files
|
# DynamoDB Local files
|
||||||
.dynamodb/
|
.dynamodb/
|
||||||
|
|
||||||
|
# IntelliJ IDEs
|
||||||
|
.idea
|
||||||
|
|||||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -4,6 +4,20 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [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
|
## [1.0.2] - 2019-10-14
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
98
README.md
98
README.md
@@ -19,8 +19,8 @@ jobs:
|
|||||||
name: Rust project
|
name: Rust project
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v2
|
||||||
- name: Install nightly
|
- name: Install latest nightly
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
@@ -39,19 +39,93 @@ See [additional recipes here](https://github.com/actions-rs/meta).
|
|||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
| Name | Required | Description | Type | Default |
|
| 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 | |
|
| `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 | |
|
| `target` | | Additionally install specified target for this toolchain, ex. `x86_64-apple-darwin` | string | |
|
||||||
| `default` | | Set installed toolchain as a default toolchain | bool | false |
|
| `default` | | Set installed toolchain as a default toolchain | bool | false |
|
||||||
| `override` | | Set installed toolchain as an override for the current directory | 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
|
## Components
|
||||||
|
|
||||||
If you are going to install `clippy`, `rustfmt` or any other [rustup component](https://rust-lang.github.io/rustup-components-history/),
|
This Action supports rustup [components](https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html#installing-the-latest-compatible-nightly) too,
|
||||||
it might not be available in latest `nightly` build;
|
and in combination with the [profiles](#profiles) input it allows to install only the needed components:
|
||||||
check out the [`actions-rs/components-nightly`](https://github.com/actions-rs/components-nightly) Action,
|
|
||||||
which makes this process much easier.
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
Same to the `profile` input, if the 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.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,65 @@
|
|||||||
import * as args from '../src/args'
|
import {toolchain_args} from "../src/args";
|
||||||
|
import {morph} from "mock-env"
|
||||||
const testEnvVars = {
|
import {sync as tempWriteSync} from "temp-write"
|
||||||
INPUT_TOOLCHAIN: 'nightly-2019-04-20',
|
|
||||||
INPUT_DEFAULT: 'false',
|
|
||||||
INPUT_OVERRIDE: 'true'
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('actions-rs/toolchain', () => {
|
describe('actions-rs/toolchain', () => {
|
||||||
beforeEach(() => {
|
|
||||||
for (const key in testEnvVars)
|
|
||||||
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Parses action input into toolchain options', async () => {
|
it('Parses action input into toolchain options', async () => {
|
||||||
const result = args.toolchain_args();
|
let args = morph(() => {
|
||||||
|
return toolchain_args("./rust-toolchain");
|
||||||
|
}, {
|
||||||
|
'INPUT_TOOLCHAIN': 'nightly-2019-04-20',
|
||||||
|
'INPUT_DEFAULT': 'false',
|
||||||
|
'INPUT_OVERRIDE': 'true'
|
||||||
|
});
|
||||||
|
|
||||||
expect(result.name).toBe('nightly-2019-04-20');
|
expect(args.name).toBe('nightly-2019-04-20');
|
||||||
expect(result.default).toBe(false);
|
expect(args.default).toBe(false);
|
||||||
expect(result.override).toBe(true);
|
expect(args.override).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses input variable if rust-toolchain file does not exist', function () {
|
||||||
|
let args = morph(() => {
|
||||||
|
return toolchain_args("./rust-toolchain");
|
||||||
|
}, {
|
||||||
|
'INPUT_TOOLCHAIN': 'nightly',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(args.name).toBe("nightly")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toolchain input is required if rust-toolchain does not exist', function () {
|
||||||
|
expect(() => toolchain_args("./rust-toolchain")).toThrowError()
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prioritizes rust-toolchain file over input variable', function () {
|
||||||
|
let rustToolchainFile = tempWriteSync("1.39.0");
|
||||||
|
|
||||||
|
let args = morph(() => {
|
||||||
|
return toolchain_args(rustToolchainFile);
|
||||||
|
}, {
|
||||||
|
'INPUT_TOOLCHAIN': 'nightly',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(args.name).toBe("nightly")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses rust-toolchain file if input does not exist', function () {
|
||||||
|
let rustToolchainFile = tempWriteSync("1.39.0");
|
||||||
|
|
||||||
|
let args = morph(() => {
|
||||||
|
return toolchain_args(rustToolchainFile);
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
expect(args.name).toBe("1.39.0")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('trims content of the override file', function () {
|
||||||
|
let rustToolchainFile = tempWriteSync("\n 1.39.0\n\n\n\n");
|
||||||
|
|
||||||
|
let args = morph(() => {
|
||||||
|
return toolchain_args(rustToolchainFile);
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
expect(args.name).toBe("1.39.0")
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ inputs:
|
|||||||
Rust toolchain name.
|
Rust toolchain name.
|
||||||
|
|
||||||
See https://github.com/rust-lang/rustup.rs#toolchain-specification
|
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:
|
target:
|
||||||
description: Target triple to install for this toolchain
|
description: Target triple to install for this toolchain
|
||||||
required: false
|
required: false
|
||||||
@@ -19,6 +22,12 @@ inputs:
|
|||||||
override:
|
override:
|
||||||
description: Set installed toolchain as an override for a directory
|
description: Set installed toolchain as an override for a directory
|
||||||
default: false
|
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
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
|||||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
8226
package-lock.json
generated
8226
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rust-toolchain",
|
"name": "rust-toolchain",
|
||||||
"version": "1.0.2",
|
"version": "1.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Install the Rust toolchain",
|
"description": "Install the Rust toolchain",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/main.ts --minify",
|
"build": "ncc build src/main.ts --minify",
|
||||||
"watch": "ncc build src/main.ts --watch",
|
"watch": "ncc build src/main.ts --watch",
|
||||||
|
"pretest": "git config core.hooksPath .githooks",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -29,18 +30,21 @@
|
|||||||
"url": "https://github.com/actions-rs/toolchain/issues"
|
"url": "https://github.com/actions-rs/toolchain/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.1.1",
|
"@actions-rs/core": "^0.0.8",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/core": "^1.2.2",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/exec": "^1.0.3",
|
||||||
"download": "^7.1.0"
|
"@actions/io": "^1.0.2",
|
||||||
|
"npm-check-updates": "^4.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.13",
|
"temp-write": "^4.0.0",
|
||||||
"@types/node": "^12.7.12",
|
"@types/jest": "^24.9.1",
|
||||||
"@zeit/ncc": "^0.20.5",
|
"@types/node": "^13.5.0",
|
||||||
"jest": "^24.9.0",
|
"@zeit/ncc": "^0.21.0",
|
||||||
"jest-circus": "^24.9.0",
|
"jest": "^25.1.0",
|
||||||
"ts-jest": "^24.1.0",
|
"jest-circus": "^25.1.0",
|
||||||
"typescript": "^3.6.4"
|
"mock-env": "^0.2.0",
|
||||||
|
"ts-jest": "^25.0.0",
|
||||||
|
"typescript": "^3.7.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
76
src/args.ts
76
src/args.ts
@@ -1,43 +1,51 @@
|
|||||||
import * as core from '@actions/core';
|
import {input} from '@actions-rs/core';
|
||||||
|
import {info, debug} from "@actions/core";
|
||||||
// Workaround for a GH bug: https://github.com/actions/toolkit/issues/127
|
import {existsSync, readFileSync} from 'fs';
|
||||||
//
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface ToolchainOptions {
|
export interface ToolchainOptions {
|
||||||
name: string,
|
name: string,
|
||||||
target?: string,
|
target: string | undefined,
|
||||||
default: boolean,
|
default: boolean,
|
||||||
override: boolean
|
override: boolean,
|
||||||
|
profile: string | undefined,
|
||||||
|
components: string[] | undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toolchain_args(): ToolchainOptions {
|
export function toolchain_args(overrideFile: string): ToolchainOptions {
|
||||||
|
let components: string[] | undefined = input.getInputList('components');
|
||||||
|
if (components && components.length === 0) {
|
||||||
|
components = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: getInput('toolchain', {required: true}),
|
name: determineToolchain(overrideFile),
|
||||||
target: getInput('target') || undefined,
|
target: input.getInput('target') || undefined,
|
||||||
default: inputBoolean('default'),
|
default: input.getInputBool('default'),
|
||||||
override: inputBoolean('override')
|
override: input.getInputBool('override'),
|
||||||
|
profile: input.getInput('profile') || undefined,
|
||||||
|
components: components,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
116
src/main.ts
116
src/main.ts
@@ -1,92 +1,60 @@
|
|||||||
const os = require('os');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
const download = require('download');
|
|
||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
import * as args from './args';
|
import * as args from './args';
|
||||||
|
import * as versions from './versions';
|
||||||
function downloadRustInit(url: string, name: string): Promise<string> {
|
import {RustUp, ToolchainOptions} from '@actions-rs/core';
|
||||||
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.info('Unable to find rustup, installing it now');
|
|
||||||
}
|
|
||||||
|
|
||||||
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`);
|
|
||||||
}
|
|
||||||
|
|
||||||
core.addPath(path.join(process.env['HOME'], '.cargo', 'bin'));
|
|
||||||
|
|
||||||
return 'rustup';
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const opts = args.toolchain_args();
|
// we use path.join to make sure this works on Windows, Linux and MacOS
|
||||||
const rustup = await get_rustup(opts.name);
|
let toolchainOverrideFile = path.join(process.cwd(), "rust-toolchain");
|
||||||
|
|
||||||
await exec.exec(rustup, ['toolchain', 'install', opts.name]);
|
const opts = args.toolchain_args(toolchainOverrideFile);
|
||||||
|
const rustup = await RustUp.getOrInstall();
|
||||||
|
await rustup.call(['show']);
|
||||||
|
|
||||||
if (opts.default) {
|
let shouldSelfUpdate = false;
|
||||||
await exec.exec(rustup, ['default', opts.name]);
|
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.override) {
|
if (opts.profile) {
|
||||||
await exec.exec(rustup, ['override', 'set', opts.name]);
|
//@ts-ignore
|
||||||
|
await rustup.setProfile(opts.profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let 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;
|
||||||
|
}
|
||||||
|
await rustup.installToolchain(opts.name, installOptions);
|
||||||
|
|
||||||
if (opts.target) {
|
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() {
|
||||||
|
|||||||
77
src/versions.ts
Normal file
77
src/versions.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import * as exec from '@actions/exec';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
export async function gatherInstalledVersions(): Promise<void> {
|
||||||
|
try {
|
||||||
|
core.startGroup('Gathering installed versions');
|
||||||
|
|
||||||
|
await rustc();
|
||||||
|
await cargo();
|
||||||
|
await rustup();
|
||||||
|
} finally {
|
||||||
|
core.endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch currently used `rustc` version
|
||||||
|
*/
|
||||||
|
async function rustc(): Promise<void> {
|
||||||
|
const stdout = await getStdout('rustc', ['-V']);
|
||||||
|
const version = parse(stdout);
|
||||||
|
|
||||||
|
core.setOutput('rustc', version.long);
|
||||||
|
core.setOutput('rustc-hash', version.hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch currently used `cargo` version
|
||||||
|
*/
|
||||||
|
async function cargo(): Promise<void> {
|
||||||
|
const stdout = await getStdout('cargo', ['-V']);
|
||||||
|
const version = parse(stdout);
|
||||||
|
|
||||||
|
core.setOutput('cargo', version.long);
|
||||||
|
// core.setOutput('cargo_short', version.short);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function rustup(): Promise<void> {
|
||||||
|
const stdout = await getStdout('rustup', ['-V']);
|
||||||
|
const version = parse(stdout);
|
||||||
|
|
||||||
|
core.setOutput('rustup', version.long);
|
||||||
|
// core.setOutput('rustup_short', version.short);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Version {
|
||||||
|
long: string,
|
||||||
|
hash: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse(stdout: string): Version {
|
||||||
|
stdout = stdout.trim();
|
||||||
|
const matches = stdout.match(/\S+\s((\S+)\s\((\S+)\s(\S+)\))/m);
|
||||||
|
if (matches == null) {
|
||||||
|
throw new Error(`Unable to parse version from the "${stdout}" string`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
long: matches[1],
|
||||||
|
hash: matches[3],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getStdout(exe: string, args: string[], options?: {}): Promise<string> {
|
||||||
|
let stdout = '';
|
||||||
|
const resOptions = Object.assign({}, options, {
|
||||||
|
listeners: {
|
||||||
|
stdout: (buffer: Buffer) => {
|
||||||
|
stdout += buffer.toString();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await exec.exec(exe, args, resOptions);
|
||||||
|
|
||||||
|
return stdout;
|
||||||
|
}
|
||||||
7
types/mock-env/index.d.ts
vendored
Normal file
7
types/mock-env/index.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
declare module "mock-env" {
|
||||||
|
function morph<T>(
|
||||||
|
callback: () => T,
|
||||||
|
vars: object,
|
||||||
|
toRemove?: string[]
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user