Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e6d4322c5 |
@@ -1,72 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended",
|
||||
"plugin:react-hooks/recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
'airbnb',
|
||||
'prettier',
|
||||
],
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
},
|
||||
"globals": {
|
||||
JSX: "readonly"
|
||||
},
|
||||
plugins: [
|
||||
'react',
|
||||
'@typescript-eslint'
|
||||
],
|
||||
rules: {
|
||||
'linebreak-style': 0,
|
||||
'no-underscore-dangle': 0,
|
||||
"no-shadow": "off",
|
||||
|
||||
"import/prefer-default-export": "off",
|
||||
"import/extensions": "off",
|
||||
"import/no-unresolved": "off",
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
devDependencies: true,
|
||||
},
|
||||
],
|
||||
|
||||
'react/no-unstable-nested-components': [
|
||||
'error',
|
||||
{ allowAsProps: true },
|
||||
],
|
||||
"react/jsx-filename-extension": [
|
||||
"error",
|
||||
{
|
||||
extensions: [".tsx", ".jsx"],
|
||||
},
|
||||
],
|
||||
|
||||
"react/require-default-props": "off",
|
||||
"react/jsx-props-no-spreading": "off",
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/no-shadow": "error"
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.ts'],
|
||||
rules: {
|
||||
'no-undef': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Checks
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
checks:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci --prefer-offline
|
||||
|
||||
# ci-checks.sh always exits 0: findings become issues, not failed builds.
|
||||
- name: Run checks
|
||||
env:
|
||||
API_BASE: ${{ github.server_url }}/api/v1
|
||||
REPO: ${{ github.repository }}
|
||||
# Prefer a PAT with issue write scope (secret: GITEA_TOKEN).
|
||||
# Default GITHUB_TOKEN is usually scoped to this repo only.
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "No GITEA_TOKEN/GITHUB_TOKEN available to file issues"
|
||||
exit 0
|
||||
fi
|
||||
export TOKEN
|
||||
bash scripts/ci-checks.sh
|
||||
@@ -0,0 +1,90 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import { fixupConfigRules } from '@eslint/compat';
|
||||
import globals from 'globals';
|
||||
import js from '@eslint/js';
|
||||
import airbnb from 'eslint-config-airbnb';
|
||||
import prettier from 'eslint-config-prettier';
|
||||
import tsParser from '@typescript-eslint/parser';
|
||||
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
||||
import importPlugin from 'eslint-plugin-import';
|
||||
import jsxAllyPlugin from 'eslint-plugin-jsx-a11y';
|
||||
import reactPlugin from 'eslint-plugin-react';
|
||||
import reactHooksPlugin from 'eslint-plugin-react-hooks';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Config entries without `files` only match .js/.mjs, so every entry needs the same file set.
|
||||
const files = ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts', '**/*.tsx'];
|
||||
|
||||
// eslint-config-airbnb 19 is legacy-only: `extends` are paths to rule modules and flat config
|
||||
// rejects `extends`/`env`/`parserOptions`, so take their rules and set the env here instead.
|
||||
const airbnbRules = (config) => (config.extends || []).flatMap((p) => airbnbRules(require(p))).concat(config);
|
||||
|
||||
// Plugins are registered once (redefining a plugin is an error) and fixed up so the legacy
|
||||
// rules that call context.getFilename still work.
|
||||
export default [
|
||||
...fixupConfigRules([
|
||||
{
|
||||
files,
|
||||
plugins: {
|
||||
react: reactPlugin,
|
||||
'react-hooks': reactHooksPlugin,
|
||||
'@typescript-eslint': tsPlugin,
|
||||
import: importPlugin,
|
||||
'jsx-a11y': jsxAllyPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
globals: { ...globals.browser, ...globals.es2021, JSX: 'readonly' },
|
||||
},
|
||||
},
|
||||
]),
|
||||
...[
|
||||
js.configs.recommended,
|
||||
reactPlugin.configs.flat.recommended,
|
||||
reactHooksPlugin.configs.flat.recommended,
|
||||
tsPlugin.configs['flat/eslint-recommended'],
|
||||
tsPlugin.configs['flat/recommended'],
|
||||
...airbnbRules(airbnb),
|
||||
prettier,
|
||||
{
|
||||
rules: {
|
||||
'linebreak-style': 0,
|
||||
'no-underscore-dangle': 0,
|
||||
"no-shadow": "off",
|
||||
|
||||
"import/prefer-default-export": "off",
|
||||
"import/extensions": "off",
|
||||
"import/no-unresolved": "off",
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
devDependencies: true,
|
||||
},
|
||||
],
|
||||
|
||||
'react/no-unstable-nested-components': [
|
||||
'error',
|
||||
{ allowAsProps: true },
|
||||
],
|
||||
"react/jsx-filename-extension": [
|
||||
"error",
|
||||
{
|
||||
extensions: [".tsx", ".jsx"],
|
||||
},
|
||||
],
|
||||
|
||||
"react/require-default-props": "off",
|
||||
"react/jsx-props-no-spreading": "off",
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/no-shadow": "error"
|
||||
},
|
||||
},
|
||||
].flatMap((config) => (Array.isArray(config) ? config : [config]).map((config) => ({ files, rules: config.rules || {}, ...(config.settings ? { settings: config.settings } : {}) }))),
|
||||
{ files: ['*.ts'], rules: { 'no-undef': 'off' } },
|
||||
];
|
||||
Generated
+58
@@ -85,6 +85,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
|
||||
"@eslint/compat": "2.1.1",
|
||||
"@eslint/js": "10.0.1",
|
||||
"@monaco-editor/react": "4.7.0",
|
||||
"@rollup/plugin-inject": "5.0.5",
|
||||
"@rollup/plugin-wasm": "6.2.2",
|
||||
@@ -109,6 +111,7 @@
|
||||
"eslint-plugin-jsx-a11y": "6.10.2",
|
||||
"eslint-plugin-react": "7.37.5",
|
||||
"eslint-plugin-react-hooks": "7.1.1",
|
||||
"globals": "17.13.0",
|
||||
"monaco-editor": "0.52.2",
|
||||
"prettier": "3.9.4",
|
||||
"typescript": "6.0.3",
|
||||
@@ -2260,6 +2263,27 @@
|
||||
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/compat": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/compat/-/compat-2.1.1.tgz",
|
||||
"integrity": "sha512-rMcy8GSrwNzcISX/BlTDY/GLB4eCopEuy9woIls3To+15OLxykZrxxq+WUcylCPCQ6F4MujjBM1DX5V1aqI3Vw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@eslint/core": "^1.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^8.40 || 9 || 10"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"eslint": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/config-array": {
|
||||
"version": "0.23.5",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.5.tgz",
|
||||
@@ -2340,6 +2364,27 @@
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/js": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz",
|
||||
"integrity": "sha512-zeR9k5pd4gxjZ0abRoIaxdc7I3nDktoXZk2qOv9gCNWx3mVwEn32VRhyLaRsDiJjTs0xq/T8mfPtyuXu7GWBcA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://eslint.org/donate"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^10.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"eslint": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/object-schema": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.5.tgz",
|
||||
@@ -7332,6 +7377,19 @@
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/globals": {
|
||||
"version": "17.13.0",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-17.13.0.tgz",
|
||||
"integrity": "sha512-RwMTC61u7hrG3ZJMkZQOK4JLJrKS8QtoTii63EmWvFXHqycY9FObBJQCbsLxSO8kjKhWE5kV1GC+Vb1g3RI0Zg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/globalthis": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz",
|
||||
|
||||
@@ -97,6 +97,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
|
||||
"@eslint/compat": "2.1.1",
|
||||
"@eslint/js": "10.0.1",
|
||||
"@monaco-editor/react": "4.7.0",
|
||||
"@rollup/plugin-inject": "5.0.5",
|
||||
"@rollup/plugin-wasm": "6.2.2",
|
||||
@@ -121,6 +123,7 @@
|
||||
"eslint-plugin-jsx-a11y": "6.10.2",
|
||||
"eslint-plugin-react": "7.37.5",
|
||||
"eslint-plugin-react-hooks": "7.1.1",
|
||||
"globals": "17.13.0",
|
||||
"monaco-editor": "0.52.2",
|
||||
"prettier": "3.9.4",
|
||||
"typescript": "6.0.3",
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
# Files one open Gitea issue per rule key, deduped by the marker line in the issue body.
|
||||
# Never exits non-zero: findings are reported, not enforced.
|
||||
set -u
|
||||
|
||||
API_BASE="${API_BASE:?API_BASE is required}"
|
||||
REPO="${REPO:?REPO is required}"
|
||||
TOKEN="${TOKEN:?TOKEN is required}"
|
||||
LABEL="ci-checks"
|
||||
SHOW="${SHOW:-50}"
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FINDINGS="$WORK/findings.tsv"
|
||||
: > "$FINDINGS"
|
||||
|
||||
# key<TAB>violation, one line per finding.
|
||||
npx eslint src --format json > "$WORK/eslint.json" || true
|
||||
jq -r --arg root "$PWD" '.[] | .filePath as $f | .messages[] | select(.ruleId) | "eslint/" + .ruleId + "\t" + (($f | ltrimstr($root + "/")) + ":" + (.line | tostring))' "$WORK/eslint.json" >> "$FINDINGS"
|
||||
|
||||
npx prettier --check . > "$WORK/prettier.log" 2>&1 || true
|
||||
sed -nE 's/^\[warn\] (.*)$/prettier\t\1/p' "$WORK/prettier.log" >> "$FINDINGS"
|
||||
|
||||
npx tsc --noEmit > "$WORK/tsc.log" 2>&1 || true
|
||||
sed -nE 's/^(.*)\(([0-9]+),([0-9]+)\): error (TS[0-9]+):.*/tsc\/\4\t\1(\2,\3)/p' "$WORK/tsc.log" >> "$FINDINGS"
|
||||
|
||||
api() { # api METHOD PATH [JSON] -> response body on stdout, non-zero on HTTP failure
|
||||
local method=$1 path=$2 data=${3-} code
|
||||
code=$(curl -sS -o "$WORK/resp" -w '%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
||||
${data:+-d "$data"} "$API_BASE/repos/$REPO$path") || return 1
|
||||
case "$code" in
|
||||
200 | 201) cat "$WORK/resp" ;;
|
||||
*) echo "HTTP $code $method $path: $(cat "$WORK/resp")" >&2; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
body() { # body KEY HASH VIOLATIONS_FILE
|
||||
printf '<!-- ci-check: %s -->\n<!-- ci-check-hash: %s -->\n\n`%s`: %d violations.\n\n```text\n' \
|
||||
"$1" "$2" "$1" "$(wc -l < "$3")"
|
||||
head -n "$SHOW" "$3"
|
||||
printf '```\n'
|
||||
}
|
||||
|
||||
LABEL_ID=$(api GET "/labels?limit=100" | jq -r --arg n "$LABEL" '[.[] | select(.name == $n) | .id] | first // empty')
|
||||
if [ -z "$LABEL_ID" ]; then
|
||||
LABEL_ID=$(api POST "/labels" "$(jq -n --arg n "$LABEL" '{name: $n, color: "006060"}')" | jq -r '.id')
|
||||
fi
|
||||
|
||||
OPEN=$(api GET "/issues?state=open&limit=100" | jq -c --arg l "$LABEL" '[.[] | select((.labels // []) | any(.name == $l))]')
|
||||
|
||||
for key in $(cut -f1 "$FINDINGS" | sort -u); do
|
||||
vf="$WORK/violations.tsv"
|
||||
awk -F'\t' -v k="$key" '$1 == k' "$FINDINGS" | sort > "$vf"
|
||||
hash=$(sha256sum < "$vf" | cut -d' ' -f1)
|
||||
row=$(echo "$OPEN" | jq -c --arg k "$key" '.[] | select((.body // "") | contains("<!-- ci-check: " + $k + " -->"))' | head -1)
|
||||
|
||||
if [ -z "$row" ]; then
|
||||
api POST "/issues" "$(jq -n --arg t "ci-check: $key" --arg b "$(body "$key" "$hash" "$vf")" --argjson l "$LABEL_ID" '{title: $t, body: $b, labels: [$l]}')" > /dev/null
|
||||
elif ! echo "$row" | jq -e --arg h "$hash" '(.body // "") | contains("<!-- ci-check-hash: " + $h + " -->")' > /dev/null; then
|
||||
api PATCH "/issues/$(jq -r '.number' <<< "$row")" "$(jq -n --arg b "$(body "$key" "$hash" "$vf")" '{body: $b}')" > /dev/null
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$OPEN" | jq -r '.[] | [((.body // "") | capture("<!-- ci-check: (?<k>[^ ]+) -->").k), .number] | @tsv' > "$WORK/keys.tsv"
|
||||
|
||||
while IFS=$'\t' read -r key number; do
|
||||
if ! grep -qF -- "$key"$'\t' "$FINDINGS"; then
|
||||
api PATCH "/issues/$number" '{"state": "closed"}' > /dev/null
|
||||
fi
|
||||
done < "$WORK/keys.tsv"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user