Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file annotations for src/build #3

Merged
merged 6 commits into from
Oct 20, 2023
Merged
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
17 changes: 11 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Run plugin check
uses: ./
with:
build-dir: 'hello-dolly'
- name: Simulate a build step
run: |
mkdir build/
mv hello.php build/

- name: Run plugin check
uses: ./
with:
build-dir: 'build'
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ jobs:

The following inputs are supported:

* `build-dir` (string): path to the built plugin files if there is a build process involved.
**Note:**: file annotations may be incorrect and not working in this case. This is still an open todo.
* `build-dir` (string): path to the build directory if there is a build process involved.
**Note:**: file annotations will still be made against the source files.
* `checks` (string): only run specific checks, separated by comma.
* `categories` (string): only run checks from specific categories, separated by comma.
* `ignore-warnings` (bool): ignore warnings.
* `ignore-errors` (bool): ignore errors.
* `include-experimental` (bool): include experimental checks.


## To-do

* PR comments
* Changing the path of the file annotations when there is a build step involved
3 changes: 1 addition & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ runs:

- name: Process results
run: |
cat ${{ runner.temp }}/plugin-check-results.txt
RELATIVE_DIR=$(echo $PLUGIN_DIR | sed "s@$GITHUB_WORKSPACE@@g")
node dist/index.js ${{ runner.temp }}/plugin-check-results.txt $RELATIVE_DIR
node dist/index.js ${{ runner.temp }}/plugin-check-results.txt
shell: bash
env:
INPUT_REPO_TOKEN: ${{ inputs.repo-token }}
13 changes: 8 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25886,12 +25886,12 @@ const core_1 = __nccwpck_require__(2186);
const node_fs_1 = __nccwpck_require__(7561);
const args = process.argv.slice(2);
const file = args[0];
const pluginDir = args[1] || '';
if (!(0, node_fs_1.existsSync)(file)) {
(0, core_1.setFailed)('Results file does not exist');
process.exit(0);
(0, core_1.setFailed)('Results file does not exist.');
}
const fileContents = (0, node_fs_1.readFileSync)(file, { encoding: 'utf8' }).split('\n');
const fileContents = (0, node_fs_1.existsSync)(file)
? (0, node_fs_1.readFileSync)(file, { encoding: 'utf8' }).split('\n')
: [];
for (let i = 0; i < fileContents.length - 1; i++) {
const line = fileContents[i];
if (!line.startsWith('FILE: ')) {
Expand All @@ -25900,10 +25900,13 @@ for (let i = 0; i < fileContents.length - 1; i++) {
const fileName = line.split('FILE: ')[1];
const results = JSON.parse(fileContents[++i]) || [];
for (const result of results) {
if (result.type === 'ERROR') {
process.exitCode = 1;
}
const func = result.type === 'ERROR' ? core_1.error : core_1.warning;
func(result.message, {
title: result.code,
file: `${pluginDir}/${fileName}`,
file: fileName,
startLine: result.line,
startColumn: result.column,
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions hello-dolly/readme.txt

This file was deleted.

File renamed without changes.
13 changes: 8 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { existsSync, readFileSync } from 'node:fs';
const args = process.argv.slice(2);

const file = args[0];
const pluginDir = args[1] || '';

if (!existsSync(file)) {
setFailed('Results file does not exist');
process.exit(0);
setFailed('Results file does not exist.');
}

const fileContents = readFileSync(file, { encoding: 'utf8' }).split('\n');
const fileContents = existsSync(file)
? readFileSync(file, { encoding: 'utf8' }).split('\n')
: [];

type Result = {
line: number;
Expand All @@ -31,10 +31,13 @@ for (let i = 0; i < fileContents.length - 1; i++) {
const results: Result[] = JSON.parse(fileContents[++i]) || [];

for (const result of results) {
if (result.type === 'ERROR') {
process.exitCode = 1;
}
const func = result.type === 'ERROR' ? error : warning;
func(result.message, {
title: result.code,
file: `${pluginDir}/${fileName}`,
file: fileName,
startLine: result.line,
startColumn: result.column,
});
Expand Down
Loading