|
| 1 | +# =============================================================== |
| 2 | +# 🕸️ Web Lint & Static Analysis - Frontend Code Quality Gate |
| 3 | +# =============================================================== |
| 4 | +# Authors: Mihai Criveti |
| 5 | +# - runs each web linter in its own matrix job for visibility |
| 6 | +# - mirrors the actual CLI commands used locally (no `make`) |
| 7 | +# - ensures fast-failure isolation: one failure doesn't hide others |
| 8 | +# - installs tools per-job without package.json |
| 9 | +# - logs are grouped and plain-text for readability |
| 10 | +# --------------------------------------------------------------- |
| 11 | + |
| 12 | +name: Web Lint & Static Analysis |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: ["main"] |
| 17 | + pull_request: |
| 18 | + branches: ["main"] |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + lint-web: |
| 25 | + strategy: |
| 26 | + fail-fast: false |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + # ------------------------------------------------------- |
| 30 | + # 🧼 HTML/CSS/JS Linters & Validators |
| 31 | + # ------------------------------------------------------- |
| 32 | + - id: htmlhint |
| 33 | + cmd: | |
| 34 | + npm install --no-save --legacy-peer-deps htmlhint |
| 35 | + npx htmlhint "mcpgateway/templates/*.html" |
| 36 | +
|
| 37 | + - id: stylelint |
| 38 | + cmd: | |
| 39 | + npm install --no-save --legacy-peer-deps stylelint stylelint-config-standard @stylistic/stylelint-config stylelint-order |
| 40 | + npx stylelint "mcpgateway/static/*.css" |
| 41 | +
|
| 42 | + - id: eslint |
| 43 | + cmd: | |
| 44 | + npm install --no-save --legacy-peer-deps \ |
| 45 | + eslint \ |
| 46 | + eslint-config-standard \ |
| 47 | + eslint-config-prettier \ |
| 48 | + eslint-plugin-import \ |
| 49 | + eslint-plugin-n \ |
| 50 | + eslint-plugin-prettier \ |
| 51 | + eslint-plugin-promise \ |
| 52 | + prettier |
| 53 | + npx eslint "mcpgateway/static/*.js" |
| 54 | +
|
| 55 | + # ------------------------------------------------------- |
| 56 | + # 🔒 Security Scanners |
| 57 | + # ------------------------------------------------------- |
| 58 | + - id: retire |
| 59 | + cmd: | |
| 60 | + npm install --no-save --legacy-peer-deps retire |
| 61 | + npx retire --path mcpgateway/static |
| 62 | +
|
| 63 | + - id: npm-audit |
| 64 | + cmd: | |
| 65 | + if [ ! -f package.json ]; then |
| 66 | + npm init -y >/dev/null |
| 67 | + fi |
| 68 | + npm audit --audit-level=high || true |
| 69 | +
|
| 70 | + # ------------------------------------------------------- |
| 71 | + # 🔍 Additional Code Quality Tools |
| 72 | + # ------------------------------------------------------- |
| 73 | + - id: jshint |
| 74 | + cmd: | |
| 75 | + npm install --no-save --legacy-peer-deps jshint |
| 76 | + if [ -f .jshintrc ]; then |
| 77 | + npx jshint --config .jshintrc "mcpgateway/static/*.js" |
| 78 | + else |
| 79 | + npx jshint --esversion=11 "mcpgateway/static/*.js" |
| 80 | + fi |
| 81 | +
|
| 82 | + - id: jscpd |
| 83 | + cmd: | |
| 84 | + npm install --no-save --legacy-peer-deps jscpd |
| 85 | + npx jscpd "mcpgateway/static/" "mcpgateway/templates/" |
| 86 | +
|
| 87 | + # - id: markuplint |
| 88 | + # cmd: | |
| 89 | + # npm install --no-save --legacy-peer-deps markuplint |
| 90 | + # npx markuplint mcpgateway/templates/* |
| 91 | + |
| 92 | + name: ${{ matrix.id }} |
| 93 | + runs-on: ubuntu-latest |
| 94 | + |
| 95 | + steps: |
| 96 | + # ----------------------------------------------------------- |
| 97 | + # 0️⃣ Checkout |
| 98 | + # ----------------------------------------------------------- |
| 99 | + - name: ⬇️ Checkout source |
| 100 | + uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + fetch-depth: 1 |
| 103 | + |
| 104 | + # ----------------------------------------------------------- |
| 105 | + # 1️⃣ Node.js Setup |
| 106 | + # ----------------------------------------------------------- |
| 107 | + - name: 📦 Set up Node.js |
| 108 | + uses: actions/setup-node@v4 |
| 109 | + with: |
| 110 | + node-version: '20' |
| 111 | + |
| 112 | + # ----------------------------------------------------------- |
| 113 | + # 2️⃣ Run Linter (install and execute in one step) |
| 114 | + # ----------------------------------------------------------- |
| 115 | + - name: 🔍 Run ${{ matrix.id }} |
| 116 | + run: ${{ matrix.cmd }} |
| 117 | + |
| 118 | + # ------------------------------------------------------- |
| 119 | + # 🐍 Python-based JS Security Scanner (separate job) |
| 120 | + # ------------------------------------------------------- |
| 121 | + nodejsscan: |
| 122 | + name: nodejsscan |
| 123 | + runs-on: ubuntu-latest |
| 124 | + |
| 125 | + steps: |
| 126 | + # ----------------------------------------------------------- |
| 127 | + # 0️⃣ Checkout |
| 128 | + # ----------------------------------------------------------- |
| 129 | + - name: ⬇️ Checkout source |
| 130 | + uses: actions/checkout@v4 |
| 131 | + with: |
| 132 | + fetch-depth: 1 |
| 133 | + |
| 134 | + # ----------------------------------------------------------- |
| 135 | + # 1️⃣ Python Setup |
| 136 | + # ----------------------------------------------------------- |
| 137 | + - name: 🐍 Set up Python |
| 138 | + uses: actions/setup-python@v5 |
| 139 | + with: |
| 140 | + python-version: "3.12" |
| 141 | + cache: pip |
| 142 | + |
| 143 | + # ----------------------------------------------------------- |
| 144 | + # 2️⃣ Install nodejsscan |
| 145 | + # ----------------------------------------------------------- |
| 146 | + - name: 🔧 Install nodejsscan |
| 147 | + run: | |
| 148 | + python3 -m pip install --upgrade pip |
| 149 | + pip install nodejsscan |
| 150 | +
|
| 151 | + # ----------------------------------------------------------- |
| 152 | + # 3️⃣ Run nodejsscan |
| 153 | + # ----------------------------------------------------------- |
| 154 | + - name: 🔒 Run nodejsscan |
| 155 | + run: | |
| 156 | + nodejsscan --directory ./mcpgateway/static |
0 commit comments