-
Notifications
You must be signed in to change notification settings - Fork 35
113 lines (103 loc) · 3.13 KB
/
code-quality-lint.yml
File metadata and controls
113 lines (103 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Code Quality Lint
#
# Purpose:
# Reusable workflow that runs ESLint on JavaScript files and Prettier on JSON files.
#
# Parameters:
# - soft-fail: When true, lint violations are reported but do not fail the workflow (default: false)
#
# Usage Examples:
# ```yaml
# # Basic usage:
# code-quality-lint:
# uses: ./.github/workflows/code-quality-lint.yml
#
# # With soft-fail:
# code-quality-lint:
# uses: ./.github/workflows/code-quality-lint.yml
# with:
# soft-fail: true
# ```
---
name: Code Quality Lint
on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
soft-fail:
description: 'Whether to continue on lint violations'
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
code-quality-lint:
name: Code Quality Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v4.3.0
with:
node-version: '24'
- name: Install Dependencies
run: npm ci
- name: Run ESLint
shell: bash
run: |
set -euo pipefail
mkdir -p lint-results
if npx eslint . 2>&1 | tee lint-results/eslint-results.txt; then
echo "ESLint passed"
else
echo "ESLINT_FAILED=true" >> "$GITHUB_ENV"
fi
- name: Run Prettier JSON Check
shell: bash
run: |
set -euo pipefail
if npx prettier --check "**/*.json" 2>&1 | tee lint-results/prettier-results.txt; then
echo "Prettier passed"
else
echo "PRETTIER_FAILED=true" >> "$GITHUB_ENV"
fi
- name: Upload Lint Results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: code-quality-lint-results
path: lint-results/
retention-days: 30
- name: Job Summary
if: always()
shell: bash
run: |
{
echo "## Code Quality Lint Results"
echo ""
if [ "${ESLINT_FAILED:-}" = "true" ]; then
echo "- :x: ESLint: violations found"
else
echo "- :white_check_mark: ESLint: passed"
fi
if [ "${PRETTIER_FAILED:-}" = "true" ]; then
echo "- :x: Prettier JSON: formatting issues found"
else
echo "- :white_check_mark: Prettier JSON: passed"
fi
} >> "$GITHUB_STEP_SUMMARY"
- name: Fail on Lint Violations
if: always() && (env.ESLINT_FAILED == 'true' || env.PRETTIER_FAILED == 'true')
shell: bash
env:
SOFT_FAIL: ${{ inputs.soft-fail }}
run: |
if [ "$SOFT_FAIL" = "true" ]; then
echo "::warning::Code quality lint violations found (soft-fail enabled)"
else
echo "::error::Code quality lint violations found"
exit 1
fi