@@ -19,10 +19,18 @@ inputs:
1919 report-file :
2020 description : |
2121 Path to lint report file to process as GitHub annotations.
22- Supports common formats like checkstyle XML, eslint JSON, etc .
22+ Supports ESLint JSON and Checkstyle XML formats .
2323 If not specified, no report processing is done.
2424 required : false
2525 default : " "
26+ report-format :
27+ description : |
28+ Format of the lint report file. Supported values:
29+ - "eslint": ESLint JSON format
30+ - "checkstyle": Checkstyle XML format
31+ - "": Auto-detect from file extension
32+ required : false
33+ default : " "
2634 fail-on-error :
2735 description : " Whether to fail the action if linting errors are found"
2836 required : false
@@ -50,68 +58,66 @@ runs:
5058 with :
5159 working-directory : ${{ inputs.working-directory }}
5260
53- - shell : bash
54- id : run-lint
55- working-directory : ${{ inputs.working-directory }}
61+ # jscpd:ignore-start
62+ - id : run-lint
63+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
5664 env :
5765 RUN_SCRIPT_COMMAND : ${{ inputs.container == 'true' && steps.get-package-manager.outputs.run-script-command || steps.setup-node.outputs.run-script-command }}
66+ WORKING_DIRECTORY : ${{ inputs.working-directory }}
5867 FAIL_ON_ERROR : ${{ inputs.fail-on-error }}
59- run : |
60- set +e # Don't exit on error, we want to process the report
61-
62- echo "👕 Running lint..."
63- $RUN_SCRIPT_COMMAND lint
64- LINT_EXIT_CODE=$?
65-
66- echo "lint-exit-code=$LINT_EXIT_CODE" >> $GITHUB_OUTPUT
67-
68- if [ "$FAIL_ON_ERROR" = "true" ] && [ $LINT_EXIT_CODE -ne 0 ]; then
69- echo "::error::Linting failed with exit code $LINT_EXIT_CODE"
70- fi
68+ with :
69+ script : |
70+ const { exec } = require('child_process');
71+ const { promisify } = require('util');
72+ const execAsync = promisify(exec);
73+ const path = require('path');
7174
72- # Always exit successfully here; we'll handle the failure later if needed
73- exit 0
75+ const workingDirectory = process.env.WORKING_DIRECTORY || '.';
76+ const runScriptCommand = process.env.RUN_SCRIPT_COMMAND;
77+ const failOnError = process.env.FAIL_ON_ERROR === 'true';
7478
75- - shell : bash
76- if : inputs.report-file != ''
77- working-directory : ${{ inputs.working-directory }}
78- env :
79- REPORT_FILE : ${{ inputs.report-file }}
80- run : |
81- set -e
79+ core.info('👕 Running lint...');
8280
83- if [ ! -f "$REPORT_FILE" ]; then
84- echo "::warning::Lint report file not found: $REPORT_FILE"
85- exit 0
86- fi
87-
88- echo "📊 Processing lint report: $REPORT_FILE"
81+ try {
82+ const { stdout, stderr } = await execAsync(`${runScriptCommand} lint`, {
83+ cwd: path.resolve(process.env.GITHUB_WORKSPACE, workingDirectory)
84+ });
85+
86+ if (stdout) core.info(stdout);
87+ if (stderr) core.warning(stderr);
88+
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);
95+
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}`);
100+ }
101+ }
102+ # jscpd:ignore-end
103+ # Process ESLint report
104+ - name : 📊 Annotate ESLint results
105+ if : always() && inputs.report-file != '' && (inputs.report-format == 'eslint' || inputs.report-format == '')
106+ uses : ataylorme/eslint-annotate-action@d57a1193d4c59cbfbf2f1529e82e2f8e0da1498d # v3.0.0
107+ with :
108+ report-json : ${{ inputs.working-directory }}/${{ inputs.report-file }}
109+ fail-on-error : false
110+ fail-on-warning : false
89111
90- # Detect report format and process accordingly
91- if echo "$REPORT_FILE" | grep -q "\.json$"; then
92- echo "Detected JSON format"
93- # Process ESLint JSON format
94- if jq -e 'type == "array"' "$REPORT_FILE" > /dev/null 2>&1; then
95- jq -r '.[] | select(.errorCount > 0 or .warningCount > 0) | .messages[] |
96- "::warning file=\(.filePath // "unknown"),line=\(.line // 1),col=\(.column // 1)::\(.message)"' \
97- "$REPORT_FILE" || true
98- fi
99- elif echo "$REPORT_FILE" | grep -q "\.xml$"; then
100- echo "Detected XML format (checkstyle)"
101- # Process checkstyle XML format
102- # This is a simplified processor; for production, consider using a dedicated tool
103- if command -v xmllint > /dev/null 2>&1; then
104- xmllint --xpath '//error' "$REPORT_FILE" 2>/dev/null | \
105- sed -E 's/<error line="([0-9]+)" column="([0-9]+)" severity="([^"]+)" message="([^"]+)" source="([^"]+)"[^>]*>/::warning line=\1,col=\2::\4/g' || true
106- else
107- echo "::warning::xmllint not available, skipping XML report processing"
108- fi
109- else
110- echo "::warning::Unknown report format for $REPORT_FILE"
111- fi
112+ # Process Checkstyle report
113+ - name : 📊 Annotate Checkstyle results
114+ if : always() && inputs.report-file != '' && inputs.report-format == 'checkstyle'
115+ uses : lcollins/checkstyle-github-action@8e0abb97e71a72c2cf9d6f0619e38002cb6e36c9 # v2.0.0
116+ with :
117+ path : ${{ inputs.working-directory }}/${{ inputs.report-file }}
112118
113119 - shell : bash
114- if : steps.run-lint.outputs.lint-exit-code != '0' && inputs.fail-on-error == 'true'
120+ if : always() && steps.run-lint.outputs.lint-exit-code != '0' && inputs.fail-on-error == 'true'
115121 run : |
116122 echo "::error::Linting failed. Please fix the errors above."
117123 exit 1
0 commit comments