Compare commits

..

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

14 changed files with 2065 additions and 10681 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"
}
}

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
custom: https://svartalf.info/donate/

View File

@ -3,7 +3,7 @@ name: Continuous integration
on: [pull_request, push] on: [pull_request, push]
jobs: jobs:
test: check_pr:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Create npm configuration - name: Create npm configuration
@ -11,8 +11,13 @@ jobs:
env: env:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2 - uses: actions/checkout@v1
- run: npm ci
- run: npm run lint - name: "npm ci"
- run: npm run build run: npm ci
- run: npm run test
- name: "npm run build"
run: npm run build
- name: "npm run test"
run: npm run test

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,10 +18,7 @@ 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
@ -43,30 +27,6 @@ jobs:
See [additional recipes here](https://github.com/actions-rs/meta). 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 | | Name | Required | Description | Type | Default |
@ -76,23 +36,22 @@ Why would you want to use this Action instead:
| `args` | | Arguments for the cargo command | string | | | `args` | | Arguments for the cargo command | string | |
| `use-cross` | | Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` | bool | 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 some [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 +63,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 +75,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/cargo/input', () => {
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.get();
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');
}); });
}); });

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
}

12427
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,9 @@
}, },
"scripts": { "scripts": {
"bundle": "cp -r .matchers ./dist/", "bundle": "cp -r .matchers ./dist/",
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify && npm run bundle", "build": "ncc build src/main.ts --minify && npm run bundle",
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'", "watch": "npm run bundle && ncc build src/main.ts --watch --minify",
"lint": "tsc --noEmit && eslint 'src/**/*.ts' '__tests__/**/*.ts'", "test": "jest"
"watch": "rm -rf ./dist/* && ncc build src/main.ts --watch",
"test": "jest -c jest.config.json"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -31,24 +29,17 @@
"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-rs/core": "0.0.8",
"@actions/core": "^1.2.4", "@actions/core": "^1.1.1",
"string-argv": "^0.3.1" "string-argv": "^0.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^24.0.23",
"@types/node": "^15.6.1", "@types/node": "^12.12.12",
"@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.2.0",
"eslint-config-prettier": "^7.2.0", "typescript": "^3.7.2"
"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,31 @@
* Parse action input into a some proper thing. * Parse action input into a some proper thing.
*/ */
import { input } from "@actions-rs/core"; import {input} from '@actions-rs/core';
import stringArgv from "string-argv"; 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 get(): Input {
const command = input.getInput("command", { required: true }); const command = input.getInput('command', {required: true});
const args = stringArgv(input.getInput("args")); const args = stringArgv(input.getInput('args'));
let toolchain = input.getInput("toolchain"); let toolchain = input.getInput('toolchain');
if (toolchain.startsWith("+")) { if (toolchain.startsWith('+')) {
toolchain = toolchain.slice(1); toolchain = toolchain.slice(1);
} }
const useCross = input.getInputBool("use-cross"); const useCross = input.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,9 +1,9 @@
import path from "path"; const path = require('path');
import * as core from "@actions/core"; import * as core from '@actions/core';
import * as input from "./input"; import * as input from './input';
import { Cargo, Cross } from "@actions-rs/core"; import {Cargo, Cross} from '@actions-rs/core';
export async function run(actionInput: input.Input): Promise<void> { export async function run(actionInput: input.Input): Promise<void> {
let program; let program;
@ -24,16 +24,16 @@ export async function run(actionInput: input.Input): Promise<void> {
} }
async function main(): Promise<void> { async function main(): Promise<void> {
const matchersPath = path.join(__dirname, ".matchers"); const matchersPath = path.join(__dirname, '.matchers');
console.log(`::add-matcher::${path.join(matchersPath, "rust.json")}`); console.log(`::add-matcher::${path.join(matchersPath, 'rust.json')}`);
const actionInput = input.get(); const actionInput = input.get();
try { try {
await run(actionInput); await run(actionInput);
} 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": false, /* 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"
]
} }