mirror of
https://github.com/actions-rs/cargo.git
synced 2024-12-21 23:25:51 +02:00
Add formatting and linting tools
This commit is contained in:
parent
ecffd7835a
commit
efdda56b63
14 changed files with 2826 additions and 472 deletions
19
.eslintrc.json
Normal file
19
.eslintrc.json
Normal file
|
@ -0,0 +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"
|
||||
}
|
||||
}
|
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
|
@ -1,3 +0,0 @@
|
|||
liberapay: svartalf
|
||||
patreon: svartalf
|
||||
custom: ["https://svartalf.info/donate/", "https://www.buymeacoffee.com/svartalf"]
|
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
|
@ -3,7 +3,7 @@ name: Continuous integration
|
|||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
check_pr:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Create npm configuration
|
||||
|
@ -11,13 +11,8 @@ jobs:
|
|||
env:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: "npm ci"
|
||||
run: npm ci
|
||||
|
||||
- name: "npm run build"
|
||||
run: npm run build
|
||||
|
||||
- name: "npm run test"
|
||||
run: npm run test
|
||||
- uses: actions/checkout@v2
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
- run: npm run build
|
||||
- run: npm run test
|
||||
|
|
45
README.md
45
README.md
|
@ -1,11 +1,23 @@
|
|||
# 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)
|
||||
[![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)
|
||||
command on a Rust language project.
|
||||
|
||||
**Table of Contents**
|
||||
|
||||
* [Example workflow](#example-workflow)
|
||||
* [Inputs](#inputs)
|
||||
* [Virtual environments](#virtual-environments)
|
||||
* [Cross-compilation](#cross-compilation)
|
||||
* [License](#license)
|
||||
* [Contribute and support](#contribute-and-support)
|
||||
|
||||
## Example workflow
|
||||
|
||||
```yaml
|
||||
|
@ -18,7 +30,7 @@ jobs:
|
|||
name: Rust project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
|
@ -36,22 +48,23 @@ See [additional recipes here](https://github.com/actions-rs/meta).
|
|||
| `args` | | Arguments for the cargo command | string | |
|
||||
| `use-cross` | | Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` | bool | false |
|
||||
|
||||
## Virtual environments
|
||||
## Toolchain
|
||||
|
||||
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);
|
||||
for example, as for 2019-09-15, `macOS` env is missing it.
|
||||
By default this Action will call whatever `cargo` binary is available
|
||||
in the current [virtual environment](https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions).
|
||||
|
||||
You can use [`actions-rs/toolchain`](https://github.com/actions-rs/toolchain)
|
||||
to install the Rust toolchain with `cargo` included.
|
||||
to install specific Rust toolchain with `cargo` included.
|
||||
|
||||
## Cross
|
||||
## Cross-compilation
|
||||
|
||||
In order to make cross-compilation an easy process,
|
||||
In order to make cross-compile an easy process,
|
||||
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
|
||||
then instead of `cargo` automatically.
|
||||
|
||||
All consequent calls of this Action in the same job will use the same `cross` installed.
|
||||
All consequent calls of this Action in the same job
|
||||
with `use-cross: true` input enabled will use the same `cross` installed.
|
||||
|
||||
```yaml
|
||||
on: [push]
|
||||
|
@ -63,7 +76,7 @@ jobs:
|
|||
name: Linux ARMv7
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
@ -75,3 +88,17 @@ jobs:
|
|||
command: build
|
||||
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).
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
import * as input from '../src/input'
|
||||
import * as input from "../src/input";
|
||||
|
||||
const testEnvVars = {
|
||||
INPUT_COMMAND: 'build',
|
||||
INPUT_COMMAND: "build",
|
||||
// There are few unnecessary spaces here to check that args parser works properly
|
||||
INPUT_ARGS: ' --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ',
|
||||
'INPUT_USE-CROSS': 'true',
|
||||
INPUT_TOOLCHAIN: '+nightly'
|
||||
}
|
||||
INPUT_ARGS:
|
||||
" --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ",
|
||||
"INPUT_USE-CROSS": "true",
|
||||
INPUT_TOOLCHAIN: "+nightly",
|
||||
};
|
||||
|
||||
describe('actions-rs/cargo/input', () => {
|
||||
describe("actions-rs/cargo/input", () => {
|
||||
beforeEach(() => {
|
||||
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', async () => {
|
||||
it("Parses action input into cargo input", () => {
|
||||
const result = input.get();
|
||||
|
||||
expect(result.command).toBe('build');
|
||||
expect(result.command).toBe("build");
|
||||
expect(result.args).toStrictEqual([
|
||||
'--release',
|
||||
'--target',
|
||||
'x86_64-unknown-linux-gnu',
|
||||
'--no-default-features',
|
||||
'--features',
|
||||
'unstable'
|
||||
"--release",
|
||||
"--target",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"--no-default-features",
|
||||
"--features",
|
||||
"unstable",
|
||||
]);
|
||||
expect(result.useCross).toBe(true);
|
||||
expect(result.toolchain).toBe('nightly');
|
||||
expect(result.toolchain).toBe("nightly");
|
||||
});
|
||||
});
|
||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,11 +0,0 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
11
jest.config.json
Normal file
11
jest.config.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"clearMocks": true,
|
||||
"moduleFileExtensions": ["js", "ts"],
|
||||
"testEnvironment": "node",
|
||||
"testMatch": ["**/*.test.ts"],
|
||||
"testRunner": "jest-circus/runner",
|
||||
"transform": {
|
||||
"^.+\\.ts$": "ts-jest"
|
||||
},
|
||||
"verbose": true
|
||||
}
|
2977
package-lock.json
generated
2977
package-lock.json
generated
File diff suppressed because it is too large
Load diff
25
package.json
25
package.json
|
@ -10,9 +10,11 @@
|
|||
},
|
||||
"scripts": {
|
||||
"bundle": "cp -r .matchers ./dist/",
|
||||
"build": "ncc build src/main.ts --minify && npm run bundle",
|
||||
"watch": "npm run bundle && ncc build src/main.ts --watch --minify",
|
||||
"test": "jest"
|
||||
"build": "rm -rf ./dist/* && ncc build src/main.ts --minify && npm run bundle",
|
||||
"format": "prettier --write 'src/**/*.ts' '__tests__/**/*.ts'",
|
||||
"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": {
|
||||
"type": "git",
|
||||
|
@ -29,16 +31,23 @@
|
|||
"url": "https://github.com/actions-rs/cargo/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions-rs/core": "0.0.8",
|
||||
"@actions/core": "^1.1.1",
|
||||
"@actions-rs/core": "0.0.9",
|
||||
"@actions/core": "^1.2.3",
|
||||
"string-argv": "^0.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^25.1.3",
|
||||
"@types/node": "^13.7.7",
|
||||
"@zeit/ncc": "^0.21.1",
|
||||
"@types/jest": "^25.1.4",
|
||||
"@types/node": "^13.9.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.25.0",
|
||||
"@typescript-eslint/parser": "^2.25.0",
|
||||
"@zeit/ncc": "^0.22.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"jest": "^25.1.0",
|
||||
"jest-circus": "^25.1.0",
|
||||
"npm-check-updates": "^4.0.5",
|
||||
"prettier": "^2.0.2",
|
||||
"ts-jest": "^25.2.1",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
|
|
26
src/input.ts
26
src/input.ts
|
@ -2,31 +2,31 @@
|
|||
* 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
|
||||
export interface Input {
|
||||
command: string,
|
||||
toolchain?: string,
|
||||
args: string[],
|
||||
useCross: boolean,
|
||||
command: string;
|
||||
toolchain?: string;
|
||||
args: string[];
|
||||
useCross: boolean;
|
||||
}
|
||||
|
||||
export function get(): Input {
|
||||
const command = input.getInput('command', {required: true});
|
||||
const args = stringArgv(input.getInput('args'));
|
||||
let toolchain = input.getInput('toolchain');
|
||||
if (toolchain.startsWith('+')) {
|
||||
const command = input.getInput("command", { required: true });
|
||||
const args = stringArgv(input.getInput("args"));
|
||||
let toolchain = input.getInput("toolchain");
|
||||
if (toolchain.startsWith("+")) {
|
||||
toolchain = toolchain.slice(1);
|
||||
}
|
||||
const useCross = input.getInputBool('use-cross');
|
||||
const useCross = input.getInputBool("use-cross");
|
||||
|
||||
return {
|
||||
command: command,
|
||||
args: args,
|
||||
useCross: useCross,
|
||||
toolchain: toolchain || undefined
|
||||
}
|
||||
toolchain: toolchain || undefined,
|
||||
};
|
||||
}
|
||||
|
|
12
src/main.ts
12
src/main.ts
|
@ -1,9 +1,9 @@
|
|||
const path = require('path');
|
||||
import path from "path";
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as input from './input';
|
||||
import {Cargo, Cross} from '@actions-rs/core';
|
||||
import * as input from "./input";
|
||||
import { Cargo, Cross } from "@actions-rs/core";
|
||||
|
||||
export async function run(actionInput: input.Input): Promise<void> {
|
||||
let program;
|
||||
|
@ -24,8 +24,8 @@ export async function run(actionInput: input.Input): Promise<void> {
|
|||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const matchersPath = path.join(__dirname, '.matchers');
|
||||
console.log(`::add-matcher::${path.join(matchersPath, 'rust.json')}`);
|
||||
const matchersPath = path.join(__dirname, ".matchers");
|
||||
console.log(`::add-matcher::${path.join(matchersPath, "rust.json")}`);
|
||||
|
||||
const actionInput = input.get();
|
||||
|
||||
|
|
7
tsconfig.eslint.json
Normal file
7
tsconfig.eslint.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"__tests__/**/*.ts"
|
||||
]
|
||||
}
|
|
@ -1,63 +1,31 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"allowJs": false, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"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. */
|
||||
"allowJs": false,
|
||||
"checkJs": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"newLine": "LF",
|
||||
"noEmitOnError": true,
|
||||
"noErrorTruncation": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"outDir": "dist",
|
||||
"pretty": true,
|
||||
"removeComments": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"suppressImplicitAnyIndexErrors": false,
|
||||
"target": "es2018",
|
||||
"declaration": false,
|
||||
"sourceMap": false
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue