@@ -20,7 +20,9 @@ inputs:
2020 description : |
2121 Path to lint report file to process as GitHub annotations.
2222 Supports ESLint JSON and Checkstyle XML formats.
23- If not specified, no report processing is done.
23+ If not specified, auto-detection will be attempted for common paths:
24+ - eslint-report.json, eslint.json
25+ - checkstyle-result.xml, checkstyle.xml
2426 required : false
2527 default : " "
2628 report-format :
6769 FAIL_ON_ERROR : ${{ inputs.fail-on-error }}
6870 with :
6971 script : |
70- const { exec } = require('child_process');
71- const { promisify } = require('util');
72- const execAsync = promisify(exec);
73- const path = require('path');
72+ const path = require('node:path');
73+ const exec = require('@actions/exec');
7474
7575 const workingDirectory = process.env.WORKING_DIRECTORY || '.';
7676 const runScriptCommand = process.env.RUN_SCRIPT_COMMAND;
@@ -79,42 +79,87 @@ runs:
7979 core.info('👕 Running lint...');
8080
8181 try {
82- const { stdout, stderr } = await execAsync(`${runScriptCommand} lint`, {
83- cwd: path.resolve(process.env.GITHUB_WORKSPACE, workingDirectory)
82+ const result = await exec.getExecOutput(runScriptCommand, ['lint'], {
83+ cwd: path.resolve(process.env.GITHUB_WORKSPACE, workingDirectory),
84+ ignoreReturnCode: true
8485 });
8586
86- if (stdout) core.info(stdout);
87- if (stderr) core.warning(stderr);
87+ if (result. stdout) core.info(result. stdout);
88+ if (result. stderr) core.warning(result. stderr);
8889
89- core.setOutput('lint-exit-code', 0);
90- } catch (error) {
91- core.setOutput('lint-exit-code', error.code || 1);
92-
93- if (error.stdout) core.info(error.stdout);
94- if (error.stderr) core.error(error.stderr);
90+ core.setOutput('lint-exit-code', result.exitCode);
9591
96- if (failOnError) {
97- core.setFailed(`Linting failed with exit code ${error.code || 1 }`);
98- } else {
99- core.warning(`Linting failed with exit code ${error.code || 1 }`);
92+ if (result.exitCode !== 0 && failOnError) {
93+ core.setFailed(`Linting failed with exit code ${result.exitCode }`);
94+ } else if (result.exitCode !== 0) {
95+ core.warning(`Linting failed with exit code ${result.exitCode }`);
10096 }
97+ } catch (error) {
98+ core.setOutput('lint-exit-code', 1);
99+ core.setFailed(`Linting error: ${error.message}`);
101100 }
102101 # jscpd:ignore-end
102+ # Auto-detect report file if not specified
103+ - id : detect-report-file
104+ if : always() && inputs.report-file == ''
105+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
106+ env :
107+ WORKING_DIRECTORY : ${{ inputs.working-directory }}
108+ with :
109+ script : |
110+ const fs = require('node:fs');
111+ const path = require('node:path');
112+
113+ const workingDirectory = process.env.WORKING_DIRECTORY || '.';
114+ const workDir = path.resolve(process.env.GITHUB_WORKSPACE, workingDirectory);
115+
116+ // Common lint report file paths
117+ const commonPaths = [
118+ 'eslint-report.json',
119+ 'eslint.json',
120+ '.eslint-report.json',
121+ 'checkstyle-result.xml',
122+ 'checkstyle.xml',
123+ 'lint-results.xml',
124+ 'reports/eslint-report.json',
125+ 'reports/checkstyle.xml'
126+ ];
127+
128+ for (const filePath of commonPaths) {
129+ const fullPath = path.join(workDir, filePath);
130+ if (fs.existsSync(fullPath)) {
131+ core.info(`Auto-detected lint report file: ${filePath}`);
132+ core.setOutput('report-file', filePath);
133+
134+ // Auto-detect format from extension
135+ if (filePath.endsWith('.json')) {
136+ core.setOutput('report-format', 'eslint');
137+ } else if (filePath.endsWith('.xml')) {
138+ core.setOutput('report-format', 'checkstyle');
139+ }
140+ return;
141+ }
142+ }
143+
144+ core.info('No lint report file auto-detected');
145+ core.setOutput('report-file', '');
146+ core.setOutput('report-format', '');
147+
103148 # Process ESLint report
104149 - name : 📊 Annotate ESLint results
105- if : always() && inputs.report-file != '' && (inputs.report-format == 'eslint' || inputs.report-format == '')
150+ if : always() && ( inputs.report-file != '' || steps.detect-report-file.outputs.report-file != '') && (inputs.report-format == 'eslint' || steps.detect-report-file.outputs.report-format == 'eslint' || ( inputs.report-format == '' && steps.detect-report-file.outputs.report-format == '') )
106151 uses : ataylorme/eslint-annotate-action@d57a1193d4c59cbfbf2f1529e82e2f8e0da1498d # v3.0.0
107152 with :
108- report-json : ${{ inputs.working-directory }}/${{ inputs.report-file }}
153+ report-json : ${{ inputs.working-directory }}/${{ inputs.report-file != '' && inputs.report-file || steps.detect-report-file.outputs.report-file }}
109154 fail-on-error : false
110155 fail-on-warning : false
111156
112157 # Process Checkstyle report
113158 - name : 📊 Annotate Checkstyle results
114- if : always() && inputs.report-file != '' && inputs.report-format == 'checkstyle'
159+ if : always() && ( inputs.report-file != '' || steps.detect-report-file.outputs.report-file != '') && ( inputs.report-format == 'checkstyle' || steps.detect-report-file.outputs.report-format == 'checkstyle')
115160 uses : lcollins/checkstyle-github-action@8e0abb97e71a72c2cf9d6f0619e38002cb6e36c9 # v2.0.0
116161 with :
117- path : ${{ inputs.working-directory }}/${{ inputs.report-file }}
162+ path : ${{ inputs.working-directory }}/${{ inputs.report-file != '' && inputs.report-file || steps.detect-report-file.outputs.report-file }}
118163
119164 - shell : bash
120165 if : always() && steps.run-lint.outputs.lint-exit-code != '0' && inputs.fail-on-error == 'true'
0 commit comments