17 Commits

Author SHA1 Message Date
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
14 changed files with 6258 additions and 6872 deletions

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

View File

@@ -1,9 +1,9 @@
name: Continuous integration
on: [push]
on: [push, pull_request]
jobs:
check_pr:
test:
runs-on: ubuntu-latest
steps:
- name: Create npm configuration
@@ -18,7 +18,6 @@ jobs:
install_stable:
runs-on: ubuntu-latest
needs: check_pr
steps:
- uses: actions/checkout@v1
- uses: ./
@@ -27,7 +26,6 @@ jobs:
install_nightly:
runs-on: ubuntu-latest
needs: check_pr
steps:
- uses: actions/checkout@v1
- uses: ./
@@ -39,7 +37,6 @@ jobs:
install_stable_in_docker:
runs-on: ubuntu-latest
container: ubuntu:latest # Docker image, not the GitHub Actions VM
needs: check_pr
steps:
# `rustup` will need `curl` or `wget` later
- run: apt-get update && apt-get install -y curl
@@ -47,3 +44,10 @@ jobs:
- 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

View File

@@ -4,7 +4,14 @@ 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.3] - 2019-10-19
## [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

View File

@@ -19,7 +19,7 @@ jobs:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
@@ -41,13 +41,30 @@ See [additional recipes here](https://github.com/actions-rs/meta).
| 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 | |
| `toolchain` | | [Toolchain](https://github.com/rust-lang/rustup.rs#toolchain-specification) name to use, ex. `stable`, `nightly`, `nightly-2019-04-20`, or `1.32.0` | string | |
| `target` | | Additionally install specified target for this toolchain, ex. `x86_64-apple-darwin` | string | |
| `default` | | Set installed toolchain as a default toolchain | bool | false |
| `override` | | Set installed toolchain as an override for the current directory | bool | false |
| `profile` | | Execute `rustup set profile {value}` before installing the toolchain, ex. `minimal` | string | |
| `components` | | Comma-separated list of the additional components to install, ex. `clippy, rustfmt` | string | |
Note: since `v1.0.4` version, `toolchain` input is not marked as required
in order to support toolchain files. See the details [below](#the-toolchain-file).
## Outputs
Installed `rustc`, `cargo` and `rustup` versions can be fetched from the Action outputs:
| Name | Description | Example |
| ------------ | --------------------- | ------------------------------- |
| `rustc` | Rustc version | `1.40.0 (73528e339 2019-12-16)` |
| `rustc-hash` | Rustc version hash | `73528e339` |
| `cargo` | Cargo version | `1.40.0 (bc8e4c8be 2019-11-22)` |
| `rustup` | rustup version | `1.21.1 (7832b2ebe 2019-12-20)` |
Note: `rustc-hash` output value can be used with [actions/cache](https://github.com/actions/cache) Action
to store cache for different Rust versions, as it is unique across different Rust versions and builds (including `nightly`).
## Profiles
This Action supports rustup [profiles](https://blog.rust-lang.org/2019/10/15/Rustup-1.20.0.html#profiles),
@@ -81,7 +98,7 @@ and in combination with the [profiles](#profiles) input it allows to install onl
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
components: rustfmt, clippy
```
@@ -101,6 +118,15 @@ to install the minimal set of `nightly` toolchain components with the `rustfmt`
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
As `rustup` is not installed by default for [macOS environments](https://help.github.com/en/articles/virtual-environments-for-github-actions)

View File

@@ -1,22 +1,65 @@
import * as args from '../src/args'
const testEnvVars = {
INPUT_TOOLCHAIN: 'nightly-2019-04-20',
INPUT_DEFAULT: 'false',
INPUT_OVERRIDE: 'true'
}
import {toolchain_args} from "../src/args";
import {morph} from "mock-env"
import {sync as tempWriteSync} from "temp-write"
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 () => {
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(result.default).toBe(false);
expect(result.override).toBe(true);
expect(args.name).toBe('nightly-2019-04-20');
expect(args.default).toBe(false);
expect(args.override).toBe(true);
});
it('uses input variable if rust-toolchain file does not exist', function () {
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")
});
});

View File

@@ -10,6 +10,9 @@ inputs:
Rust toolchain name.
See https://github.com/rust-lang/rustup.rs#toolchain-specification
If this is not given, the action will try and install the version specified in the `rust-toolchain` file.
required: false
target:
description: Target triple to install for this toolchain
required: false

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

12825
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.3",
"version": "1.0.4",
"private": false,
"description": "Install the Rust toolchain",
"main": "lib/main.js",
@@ -11,6 +11,7 @@
"scripts": {
"build": "ncc build src/main.ts --minify",
"watch": "ncc build src/main.ts --watch",
"pretest": "git config core.hooksPath .githooks",
"test": "jest"
},
"repository": {
@@ -29,18 +30,21 @@
"url": "https://github.com/actions-rs/toolchain/issues"
},
"dependencies": {
"@actions/core": "^1.1.1",
"@actions/exec": "^1.0.0",
"@actions/io": "^1.0.0",
"@actions-rs/core": "^0.0.7"
"@actions-rs/core": "^0.0.8",
"@actions/core": "^1.2.2",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2",
"npm-check-updates": "^4.0.1"
},
"devDependencies": {
"@types/jest": "^24.0.19",
"@types/node": "^12.11.1",
"@zeit/ncc": "^0.20.5",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"ts-jest": "^24.1.0",
"typescript": "^3.6.4"
"temp-write": "^4.0.0",
"@types/jest": "^24.9.1",
"@types/node": "^13.5.0",
"@zeit/ncc": "^0.21.0",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"mock-env": "^0.2.0",
"ts-jest": "^25.0.0",
"typescript": "^3.7.5"
}
}

View File

@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import {input} from '@actions-rs/core';
import {info, debug} from "@actions/core";
import {existsSync, readFileSync} from 'fs';
export interface ToolchainOptions {
name: string,
@@ -10,13 +11,14 @@ export interface ToolchainOptions {
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 {
name: input.getInput('toolchain', {required: true}),
name: determineToolchain(overrideFile),
target: input.getInput('target') || undefined,
default: input.getInputBool('default'),
override: input.getInputBool('override'),
@@ -24,3 +26,26 @@ export function toolchain_args(): ToolchainOptions {
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;
}

View File

@@ -1,12 +1,17 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import path from "path";
import * as args from './args';
import * as versions from './versions';
import {RustUp, ToolchainOptions} from '@actions-rs/core';
async function run() {
const opts = args.toolchain_args();
// we use path.join to make sure this works on Windows, Linux and MacOS
let toolchainOverrideFile = path.join(process.cwd(), "rust-toolchain");
const opts = args.toolchain_args(toolchainOverrideFile);
const rustup = await RustUp.getOrInstall();
await rustup.call(['show']);
@@ -48,6 +53,8 @@ async function run() {
if (opts.target) {
await rustup.addTarget(opts.target, opts.name);
}
await versions.gatherInstalledVersions();
}
async function main() {

77
src/versions.ts Normal file
View 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
View File

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