Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Add working-directory param #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ jobs:

## Inputs

| Name | Required | Description | Type | Default |
| ------------| :------: | ---------------------------------------------------------------------------------------------------------------------------------------| ------ | --------|
| `token` | ✓ | GitHub secret token, usually a `${{ secrets.GITHUB_TOKEN }}` | string | |
| `toolchain` | | Rust toolchain to use; override or system default toolchain will be used if omitted | string | |
| `args` | | Arguments for the `cargo clippy` command | string | |
| `use-cross` | | Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` | bool | false |
| `name` | | Name of the created GitHub check. If running this action multiple times, each run must have a unique name. | string | clippy |
| Name | Required | Description | Type | Default |
| ------------------- | :------: | ---------------------------------------------------------------------------------------------------------- | ------ | ------- |
| `token` | ✓ | GitHub secret token, usually a `${{ secrets.GITHUB_TOKEN }}` | string | |
| `toolchain` | | Rust toolchain to use; override or system default toolchain will be used if omitted | string | |
| `args` | | Arguments for the `cargo clippy` command | string | |
| `use-cross` | | Use [`cross`](https://github.com/rust-embedded/cross) instead of `cargo` | bool | false |
| `name` | | Name of the created GitHub check. If running this action multiple times, each run must have a unique name. | string | clippy |
| `working-directory` | | Specify where rust directory is | string | . |

For extra details about the `toolchain`, `args` and `use-cross` inputs,
see [`cargo` Action](https://github.com/actions-rs/cargo#inputs) documentation.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
args:
description: Arguments for the cargo command
required: false
working-directory:
description: Specify where rust directory is. By default runs in root directory
required: false
use-cross:
description: Use cross instead of cargo
default: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rust-clippy-check",
"version": "1.0.7",
"version": "1.0.8",
"private": false,
"description": "Run clippy and annotate the diff with errors and warnings",
"main": "dist/index.js",
Expand Down
17 changes: 13 additions & 4 deletions src/check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import {join as pathJoin} from 'path';

const pkg = require('../package.json');
import {plural} from './render';
Expand Down Expand Up @@ -53,8 +54,10 @@ interface Stats {
export class CheckRunner {
private annotations: Array<ChecksCreateParamsOutputAnnotations>;
private stats: Stats;
private workingDirectory?: string;

constructor() {
constructor(workingDirectory: string | undefined) {
this.workingDirectory = workingDirectory;
this.annotations = [];
this.stats = {
ice: 0,
Expand Down Expand Up @@ -104,7 +107,7 @@ export class CheckRunner {
break;
}

this.annotations.push(CheckRunner.makeAnnotation(contents));
this.annotations.push(this.makeAnnotation(contents));
}

public async executeCheck(options: CheckOptions): Promise<void> {
Expand Down Expand Up @@ -340,7 +343,7 @@ See https://github.com/actions-rs/clippy-check/issues/2 for details.`);
/// Convert parsed JSON line into the GH annotation object
///
/// https://developer.github.com/v3/checks/runs/#annotations-object
static makeAnnotation(contents: CargoMessage): ChecksCreateParamsOutputAnnotations {
private makeAnnotation(contents: CargoMessage): ChecksCreateParamsOutputAnnotations {
const primarySpan: undefined | DiagnosticSpan = contents.message.spans.find((span) => span.is_primary == true);
// TODO: Handle it properly
if (null == primarySpan) {
Expand All @@ -362,8 +365,14 @@ See https://github.com/actions-rs/clippy-check/issues/2 for details.`);
break;
}

let path = primarySpan.file_name;

if(this.workingDirectory) {
path = pathJoin(this.workingDirectory, path);
}

let annotation: ChecksCreateParamsOutputAnnotations = {
path: primarySpan.file_name,
path,
start_line: primarySpan.line_start,
end_line: primarySpan.line_end,
annotation_level: annotation_level,
Expand Down
5 changes: 4 additions & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Input {
args: string[],
useCross: boolean,
name: string,
workingDirectory?: string,
}

export function get(): Input {
Expand All @@ -23,12 +24,14 @@ export function get(): Input {
}
const useCross = input.getInputBool('use-cross');
const name = input.getInput('name');
const workingDirectory = input.getInput('working-directory');

return {
token: input.getInput('token', {required: true}),
args: args,
useCross: useCross,
toolchain: toolchain || undefined,
name
name,
workingDirectory: workingDirectory || undefined
}
}
14 changes: 12 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as github from '@actions/github';
import {join as pathJoin} from 'path';

import {Cargo, Cross} from '@actions-rs/core';
import * as input from './input';
Expand Down Expand Up @@ -44,15 +45,23 @@ export async function run(actionInput: input.Input): Promise<void> {
if (actionInput.toolchain) {
args.push(`+${actionInput.toolchain}`);
}

args.push('clippy');

// `--message-format=json` should just right after the `cargo clippy`
// because usually people are adding the `-- -D warnings` at the end
// of arguments and it will mess up the output.
args.push('--message-format=json');

args = args.concat(actionInput.args);

let runner = new CheckRunner();
let cwd = undefined;

if (actionInput.workingDirectory) {
cwd = pathJoin(process.cwd(), actionInput.workingDirectory);
}

let runner = new CheckRunner(actionInput.workingDirectory);
let clippyExitCode: number = 0;
try {
core.startGroup('Executing cargo clippy (JSON output)');
Expand All @@ -63,7 +72,8 @@ export async function run(actionInput: input.Input): Promise<void> {
stdline: (line: string) => {
runner.tryPush(line);
}
}
},
cwd
});
} finally {
core.endGroup();
Expand Down