Compare commits

..

No commits in common. "master" and "v1.0.0" have entirely different histories.

17 changed files with 2051 additions and 10929 deletions

View File

@ -1,19 +0,0 @@
{
"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"
}
}

View File

@ -1,18 +0,0 @@
name: Continuous integration
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Create npm configuration
run: echo "//npm.pkg.github.com/:_authToken=${token}" >> ~/.npmrc
env:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm run test

View File

@ -1,21 +0,0 @@
{
"problemMatcher": [
{
"owner": "rust",
"pattern": [
{
"regexp": "^(warning|warn|error)(\\[(.*)\\])?: (.*)$",
"severity": 1,
"message": 4,
"code": 3
},
{
"regexp": "^([\\s->=]*(.*):(\\d*):(\\d*)|.*)$",
"file": 2,
"line": 3,
"column": 4
}
]
}
]
}

1
.npmrc
View File

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

View File

@ -1,27 +0,0 @@
# 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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.3] - 2019-11-24
### Fixed
- Rustup installer for Windows VMs is downloaded via HTTPS
## [1.0.2] - 2019-11-09
### Added
- Problem matcher which will highlight warnings and errors in the cargo output
### Changed
- Use `@action-rs/core` package for cargo/cross execution
## [1.0.1] - 2019-09-15
### Added
- First public version

View File

@ -1,24 +1,11 @@
# Rust `cargo` Action # Rust `cargo` 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) ![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) [![Gitter](https://badges.gitter.im/actions-rs/community.svg)](https://gitter.im/actions-rs/community)
![Continuous integration](https://github.com/actions-rs/cargo/workflows/Continuous%20integration/badge.svg)
![Dependabot enabled](https://api.dependabot.com/badges/status?host=github&repo=actions-rs/toolchain)
This GitHub Action runs specified [`cargo`](https://github.com/rust-lang/cargo) This GitHub Action runs specified [`cargo`](https://github.com/rust-lang/cargo)
command on a Rust language project. command on a Rust language project.
**Table of Contents**
* [Example workflow](#example-workflow)
* [Use cases](#use-cases)
* [Inputs](#inputs)
* [Toolchain](#toolchain)
* [Cross-compilation](#cross-compilation)
* [License](#license)
* [Contribute and support](#contribute-and-support)
## Example workflow ## Example workflow
```yaml ```yaml
@ -31,68 +18,37 @@ jobs:
name: Rust project name: Rust project
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: --release --all-features arguments: --release --all-features
``` ```
See [additional recipes here](https://github.com/actions-rs/meta).
## Use cases
Note that this Action is not required usually
and you can just use [`run`](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun)
step instead as in example below:
```yaml
jobs:
build_and_test:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: cargo build --release --all-features
```
Why would you want to use this Action instead:
1. Transparent `cross` installation and execution with `use-cross: true` input enabled
2. Warnings and errors issued by `cargo` will be displayed in GitHub UI
## Inputs ## Inputs
| Name | Required | Description | Type | Default | * `command` (*required*) - Cargo command to run (ex. `check` or `build`)
| ------------| :------: | -------------------------------------------------------------------------| ------ | --------| * `toolchain` - Rust toolchain to use (without the `+` sign, ex. `nightly`);\
| `command` | ✓ | Cargo command to run, ex. `check` or `build` | string | | Override or system toolchain will be used if omitted.
| `toolchain` | | Rust toolchain name to use | string | | * `args` - Arguments for the cargo command
| `args` | | Arguments for the cargo command | string | | * `use-cross` - Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` (default: `false`)
| `use-cross` | | Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` | bool | false |
## Toolchain ## Virtual environments
By default this Action will call whatever `cargo` binary is available Note that `cargo` is not available by default for all [virtual environments](https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions);
in the current [virtual environment](https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions). for example, as for 2019-09-15, `macOS` env is missing it.
You can use [`actions-rs/toolchain`](https://github.com/actions-rs/toolchain) You can use [`actions-rs/toolchain`](https://github.com/actions-rs/toolchain)
to install specific Rust toolchain with `cargo` included. to install the Rust toolchain with `cargo` included.
## Cross-compilation ## Cross
In order to make cross-compile an easy process, In order to make cross-compilation an easy process,
this Action can install [cross](https://github.com/rust-embedded/cross) this Action can install [cross](https://github.com/rust-embedded/cross)
tool on demand if `use-cross` input is enabled; `cross` executable will be invoked tool on demand if `use-cross` input is enabled; `cross` executable will be invoked
then instead of `cargo` automatically. then instead of `cargo` automatically.
All consequent calls of this Action in the same job All consequent calls of this Action in the same job will use the same `cross` installed.
with `use-cross: true` input enabled will use the same `cross` installed.
```yaml ```yaml
on: [push] on: [push]
@ -104,7 +60,7 @@ jobs:
name: Linux ARMv7 name: Linux ARMv7
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@master
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: stable toolchain: stable
@ -116,17 +72,3 @@ jobs:
command: build command: build
args: --target armv7-unknown-linux-gnueabihf args: --target armv7-unknown-linux-gnueabihf
``` ```
## 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,33 +1,32 @@
import * as input from "../src/input"; import * as input from '../src/input'
const testEnvVars = { const testEnvVars = {
INPUT_COMMAND: "build", INPUT_COMMAND: 'build',
// There are few unnecessary spaces here to check that args parser works properly // There are few unnecessary spaces here to check that args parser works properly
INPUT_ARGS: INPUT_ARGS: ' --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ',
" --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ", 'INPUT_USE-CROSS': 'true',
"INPUT_USE-CROSS": "true", INPUT_TOOLCHAIN: '+nightly'
INPUT_TOOLCHAIN: "+nightly", }
};
describe("actions-rs/cargo/input", () => { describe('actions-rs/check', () => {
beforeEach(() => { beforeEach(() => {
for (const key in testEnvVars) for (const key in testEnvVars)
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]; process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
}); })
it("Parses action input into cargo input", () => { it('Parses action input into cargo input', async () => {
const result = input.get(); const result = input.parse();
expect(result.command).toBe("build"); expect(result.command).toBe('build');
expect(result.args).toStrictEqual([ expect(result.args).toStrictEqual([
"--release", '--release',
"--target", '--target',
"x86_64-unknown-linux-gnu", 'x86_64-unknown-linux-gnu',
"--no-default-features", '--no-default-features',
"--features", '--features',
"unstable", 'unstable'
]); ]);
expect(result.useCross).toBe(true); expect(result.useCross).toBe(true);
expect(result.toolchain).toBe("nightly"); expect(result.toolchain).toBe('nightly');
}); });
}); });

View File

@ -1,21 +0,0 @@
{
"problemMatcher": [
{
"owner": "rust",
"pattern": [
{
"regexp": "^(warning|warn|error)(\\[(.*)\\])?: (.*)$",
"severity": 1,
"message": 4,
"code": 3
},
{
"regexp": "^([\\s->=]*(.*):(\\d*):(\\d*)|.*)$",
"file": 2,
"line": 3,
"column": 4
}
]
}
]
}

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

11
jest.config.js Normal file
View File

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

View File

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

12516
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "rust-cargo", "name": "rust-cargo",
"version": "1.0.3", "version": "1.0.0",
"private": false, "private": false,
"description": "Run cargo command", "description": "Run cargo command",
"main": "lib/main.js", "main": "lib/main.js",
@ -9,12 +9,9 @@
"test": "__tests__" "test": "__tests__"
}, },
"scripts": { "scripts": {
"bundle": "cp -r .matchers ./dist/", "build": "ncc build src/main.ts --minify",
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify && npm run bundle", "watch": "ncc build src/main.ts --watch --minify",
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'", "test": "jest"
"lint": "tsc --noEmit && eslint 'src/**/*.ts' '__tests__/**/*.ts'",
"watch": "rm -rf ./dist/* && ncc build src/main.ts --watch",
"test": "jest -c jest.config.json"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -31,24 +28,18 @@
"url": "https://github.com/actions-rs/cargo/issues" "url": "https://github.com/actions-rs/cargo/issues"
}, },
"dependencies": { "dependencies": {
"@actions-rs/core": "0.1.3", "@actions/core": "^1.0.1",
"@actions/core": "^1.2.4", "@actions/exec": "^1.0.1",
"@actions/io": "^1.0.1",
"string-argv": "^0.3.1" "string-argv": "^0.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^24.0.13",
"@types/node": "^15.6.1", "@types/node": "^12.7.5",
"@typescript-eslint/eslint-plugin": "^4.0.0", "@zeit/ncc": "^0.20.5",
"@typescript-eslint/parser": "^3.10.1", "jest": "^24.9.0",
"@zeit/ncc": "^0.22.3", "jest-circus": "^24.9.0",
"eslint": "^7.29.0", "ts-jest": "^24.0.2",
"eslint-config-prettier": "^7.2.0", "typescript": "^3.5.1"
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"jest-circus": "^27.0.6",
"npm-check-updates": "^11.1.9",
"prettier": "^2.2.1",
"ts-jest": "^26.5.6",
"typescript": "^4.3.5"
} }
} }

View File

@ -2,31 +2,58 @@
* Parse action input into a some proper thing. * Parse action input into a some proper thing.
*/ */
import { input } from "@actions-rs/core"; import * as core from '@actions/core';
import * as exec from '@actions/exec';
import stringArgv from 'string-argv';
// 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): string {
const inputFullName = name.replace(/-/g, '_');
let value = core.getInput(inputFullName);
if (value.length > 0) {
return value
}
return core.getInput(name)
}
function getInputBool(name: string): boolean {
const value = getInput(name);
if (value && (value == 'true' || value == '1')) {
return true;
} else {
return false;
}
}
import stringArgv from "string-argv";
// Parsed action input // Parsed action input
export interface Input { export interface Input {
command: string; command: string,
toolchain?: string; toolchain?: string,
args: string[]; args: string[],
useCross: boolean; useCross: boolean,
} }
export function get(): Input { export function parse(): Input {
const command = input.getInput("command", { required: true }); const command = getInput('command');
const args = stringArgv(input.getInput("args")); const args = stringArgv(getInput('args'));
let toolchain = input.getInput("toolchain"); let toolchain = getInput('toolchain');
if (toolchain.startsWith("+")) { if (toolchain.startsWith('+')) {
toolchain = toolchain.slice(1); toolchain = toolchain.slice(1);
} }
const useCross = input.getInputBool("use-cross"); const useCross = getInputBool('use-cross');
return { return {
command: command, command: command,
args: args, args: args,
useCross: useCross, useCross: useCross,
toolchain: toolchain || undefined, toolchain: toolchain || undefined
}; }
} }

View File

@ -1,16 +1,86 @@
import path from "path"; const os = require('os');
const process = require('process');
import * as core from "@actions/core"; import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as input from "./input"; import * as input from './input';
import { Cargo, Cross } from "@actions-rs/core";
const CROSS_REV: string = '69b8da7da287055127812c9e4b071756c2b98545';
// TODO: `core.info` function is not published yet as for `1.0.1` version,
// bundling it.
function core_info(message: string): void {
process.stdout.write(message + os.EOL);
}
async function getCargo(): Promise<string> {
try {
return await io.which('cargo', true);
} catch (error) {
core_info('cargo is not installed by default for some virtual environments, \
see https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions');
core_info('To install it, use this action: https://github.com/actions-rs/toolchain');
throw error;
}
}
async function getCross(cargoPath: string): Promise<string> {
try {
return await io.which('cross', true);
} catch (error) {
core.debug('Unable to find cross, installing it now');
throw error;
}
// Somewhat new Rust is required to compile `cross`
// (TODO: Not sure what version exactly, should clarify)
// but if some action will set an override toolchain before this action called
// (ex. `@actions-rs/toolchain` with `toolchain: 1.31.0`)
// `cross` compilation will fail.
//
// In order to skip this problem and install `cross` globally
// using the pre-installed system Rust,
// we are going to jump to the tmpdir (skipping directory override that way)
// install `cross` from there and then jump back.
const cwd = process.cwd();
process.chdir(os.tmpdir());
try {
core.startGroup('Install cross');
core.warning('Git version of cross will be installed, \
see https://github.com/actions-rs/cargo/issues/1');
await exec.exec(cargoPath, [
'install',
'--rev',
CROSS_REV,
'--git',
'https://github.com/rust-embedded/cross.git'
]);
} catch (error) {
throw error;
} finally {
// It is important to chdir back!
process.chdir(cwd);
core.endGroup();
}
// Expecting it to be in PATH already
return 'cross';
}
async function run(): Promise<void> {
const actionInput = input.parse();
const cargo = await getCargo();
export async function run(actionInput: input.Input): Promise<void> {
let program; let program;
if (actionInput.useCross) { if (actionInput.useCross) {
program = await Cross.getOrInstall(); program = await getCross(cargo);
} else { } else {
program = await Cargo.get(); program = cargo;
} }
let args: string[] = []; let args: string[] = [];
@ -20,20 +90,15 @@ export async function run(actionInput: input.Input): Promise<void> {
args.push(actionInput.command); args.push(actionInput.command);
args = args.concat(actionInput.args); args = args.concat(actionInput.args);
await program.call(args); await exec.exec(program, args);
} }
async function main(): Promise<void> { async function main(): Promise<void> {
const matchersPath = path.join(__dirname, ".matchers");
console.log(`::add-matcher::${path.join(matchersPath, "rust.json")}`);
const actionInput = input.get();
try { try {
await run(actionInput); await run();
} catch (error) { } catch (error) {
core.setFailed((<Error>error).message); core.setFailed(error.message);
} }
} }
void main(); main();

View File

@ -1,7 +0,0 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"__tests__/**/*.ts"
]
}

View File

@ -1,31 +1,63 @@
{ {
"compilerOptions": { "compilerOptions": {
"allowJs": false, /* Basic Options */
"checkJs": false, // "incremental": true, /* Enable incremental compilation */
"esModuleInterop": true, "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"forceConsistentCasingInFileNames": true, "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "commonjs", // "allowJs": true, /* Allow javascript files to be compiled. */
"moduleResolution": "node", // "checkJs": true, /* Report errors in .js files. */
"newLine": "LF", // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"noEmitOnError": true, // "declaration": true, /* Generates corresponding '.d.ts' file. */
"noErrorTruncation": true, // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"noFallthroughCasesInSwitch": true, // "sourceMap": true, /* Generates corresponding '.map' file. */
"noImplicitAny": true, // "outFile": "./", /* Concatenate and emit output to single file. */
"noImplicitReturns": true, "outDir": "./lib", /* Redirect output structure to the directory. */
"noImplicitThis": true, "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"noUnusedLocals": true, // "composite": true, /* Enable project compilation */
"noUnusedParameters": true, // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"outDir": "dist", // "removeComments": true, /* Do not emit comments to output. */
"pretty": true, // "noEmit": true, /* Do not emit outputs. */
"removeComments": true, // "importHelpers": true, /* Import emit helpers from 'tslib'. */
"resolveJsonModule": true, // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"strict": true, // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"suppressImplicitAnyIndexErrors": false,
"target": "es2018", /* Strict Type-Checking Options */
"declaration": false, "strict": true, /* Enable all strict type-checking options. */
"sourceMap": false "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. */
}, },
"include": [ "exclude": ["node_modules", "**/*.test.ts"]
"src/**/*.ts"
]
} }