Skip to content

Fix lint workflow and issues that were re-introduced #191

Fix lint workflow and issues that were re-introduced

Fix lint workflow and issues that were re-introduced #191

Workflow file for this run

name: Lint
# This workflow runs linting on files in the repository
# It can be configured to run on all files or just changed files
# It will fail the build if any linter fails
env:
CI: true
on:
pull_request:
workflow_dispatch:
inputs:
lint_mode:
description: 'Linting mode'
required: true
default: 'changed'
type: choice
options:
- all
- changed
jobs:
lint:
name: Lint Files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to get all history for comparing changes
- name: Set up environment
uses: ./.github/actions/setup
- name: Determine lint mode
id: lint_mode
run: |
# Default to 'changed' for push and PR events, but allow override via workflow_dispatch
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
LINT_MODE="${{ github.event.inputs.lint_mode }}"
else
LINT_MODE="changed"
fi
echo "mode=$LINT_MODE" >> $GITHUB_OUTPUT
echo "Lint mode: $LINT_MODE"
- name: Get changed files
id: changed_files
if: steps.lint_mode.outputs.mode == 'changed'
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For pull requests, compare with the base branch
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
else
# For pushes, compare with the parent commit
BASE_SHA=$(git rev-parse HEAD^)
HEAD_SHA=$(git rev-parse HEAD)
fi
echo "Base SHA: $BASE_SHA"
echo "Head SHA: $HEAD_SHA"
# Get changed files, filtering out deleted files and files in ignored directories
CHANGED_TS_JS=$(git diff --name-only --diff-filter=d $BASE_SHA $HEAD_SHA | grep -E '\.(js|ts|jsx|tsx|cjs|mjs)$' | grep -v -E '(node_modules|dist|build|cache|reports|lib|coverage|artifacts|typechain|hardhat-cache|ignition/deployments|ignition/modules/artifacts)' || true)
CHANGED_SOL=$(git diff --name-only --diff-filter=d $BASE_SHA $HEAD_SHA | grep -E '\.sol$' | grep -v -E '(node_modules|dist|build|cache|reports|lib|coverage|artifacts|typechain|hardhat-cache|ignition/deployments|ignition/modules/artifacts)' || true)
CHANGED_MD=$(git diff --name-only --diff-filter=d $BASE_SHA $HEAD_SHA | grep -E '\.md$' | grep -v -E '(node_modules|dist|build|cache|reports|lib|coverage|artifacts|typechain|hardhat-cache|ignition/deployments|ignition/modules/artifacts)' || true)
CHANGED_JSON=$(git diff --name-only --diff-filter=d $BASE_SHA $HEAD_SHA | grep -E '\.json$' | grep -v -E '(node_modules|dist|build|cache|reports|lib|coverage|artifacts|typechain|hardhat-cache|ignition/deployments|ignition/modules/artifacts)' || true)
CHANGED_YAML=$(git diff --name-only --diff-filter=d $BASE_SHA $HEAD_SHA | grep -E '\.(yml|yaml)$' | grep -v -E '(node_modules|dist|build|cache|reports|lib|coverage|artifacts|typechain|hardhat-cache|ignition/deployments|ignition/modules/artifacts)' || true)
# Save to files for later use
echo "$CHANGED_TS_JS" > changed_ts_js.txt
echo "$CHANGED_SOL" > changed_sol.txt
echo "$CHANGED_MD" > changed_md.txt
echo "$CHANGED_JSON" > changed_json.txt
echo "$CHANGED_YAML" > changed_yaml.txt
# Count changed files
TS_JS_COUNT=$(echo "$CHANGED_TS_JS" | grep -v '^$' | wc -l)
SOL_COUNT=$(echo "$CHANGED_SOL" | grep -v '^$' | wc -l)
MD_COUNT=$(echo "$CHANGED_MD" | grep -v '^$' | wc -l)
JSON_COUNT=$(echo "$CHANGED_JSON" | grep -v '^$' | wc -l)
YAML_COUNT=$(echo "$CHANGED_YAML" | grep -v '^$' | wc -l)
TOTAL_COUNT=$((TS_JS_COUNT + SOL_COUNT + MD_COUNT + JSON_COUNT + YAML_COUNT))
echo "ts_js_count=$TS_JS_COUNT" >> $GITHUB_OUTPUT
echo "sol_count=$SOL_COUNT" >> $GITHUB_OUTPUT
echo "md_count=$MD_COUNT" >> $GITHUB_OUTPUT
echo "json_count=$JSON_COUNT" >> $GITHUB_OUTPUT
echo "yaml_count=$YAML_COUNT" >> $GITHUB_OUTPUT
echo "total_count=$TOTAL_COUNT" >> $GITHUB_OUTPUT
echo "Found $TOTAL_COUNT changed files to lint:"
echo "- TypeScript/JavaScript: $TS_JS_COUNT"
echo "- Solidity: $SOL_COUNT"
echo "- Markdown: $MD_COUNT"
echo "- JSON: $JSON_COUNT"
echo "- YAML: $YAML_COUNT"
- name: Lint Solidity files
id: lint_sol
continue-on-error: true
run: |
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
echo "Linting all Solidity files in each package..."
# Run solhint in each workspace package that has contracts (check mode)
pnpm -r exec bash -c 'if [ -d "contracts" ]; then npx solhint --max-warnings=0 --noPrompt --noPoster "contracts/**/*.sol" 2>/dev/null || exit 1; fi'
# Check formatting with prettier
git ls-files '*.sol' | xargs -r npx prettier --check --cache --log-level warn
elif [ "${{ steps.changed_files.outputs.sol_count }}" -gt "0" ]; then
echo "Linting changed Solidity files..."
# Lint each changed file from its package directory
for file in $(cat changed_sol.txt); do
# Walk up to find package.json
dir="$file"
found=false
while [ "$dir" != "." ]; do
dir=$(dirname "$dir")
if [ -f "$dir/package.json" ]; then
relative_file="${file#$dir/}"
echo " Checking $file"
(cd "$dir" && npx solhint --max-warnings=0 --noPrompt --noPoster "$relative_file")
found=true
break
fi
done
if [ "$found" = false ]; then
echo "::error::No package.json found for $file - workflow needs fixing"
exit 1
fi
done
# Check formatting with prettier
cat changed_sol.txt | xargs -r npx prettier --check --cache --log-level warn
fi
- name: Lint TypeScript/JavaScript files
id: lint_ts
continue-on-error: true
run: |
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
echo "Linting all TypeScript/JavaScript files..."
git ls-files '*.js' '*.ts' '*.cjs' '*.mjs' '*.jsx' '*.tsx' | xargs -r npx eslint --max-warnings=0 --no-warn-ignored
git ls-files '*.js' '*.ts' '*.cjs' '*.mjs' '*.jsx' '*.tsx' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
elif [ "${{ steps.changed_files.outputs.ts_js_count }}" -gt "0" ]; then
echo "Linting changed TypeScript/JavaScript files..."
cat changed_ts_js.txt | xargs -r npx eslint --max-warnings=0 --no-warn-ignored
cat changed_ts_js.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
fi
- name: Lint Markdown files
id: lint_md
continue-on-error: true
run: |
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
echo "Linting all Markdown files..."
git ls-files '*.md' | xargs -r npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
git ls-files '*.md' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
elif [ "${{ steps.changed_files.outputs.md_count }}" -gt "0" ]; then
echo "Linting changed Markdown files..."
cat changed_md.txt | xargs -r npx markdownlint --ignore-path .gitignore --ignore-path .markdownlintignore
cat changed_md.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
fi
- name: Lint JSON files
id: lint_json
continue-on-error: true
run: |
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
echo "Linting all JSON files..."
# Exclude Ignition deployment artifacts and other build artifacts
git ls-files '*.json' | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; } | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
elif [ "${{ steps.changed_files.outputs.json_count }}" -gt "0" ]; then
echo "Linting changed JSON files..."
cat changed_json.txt | { grep -v -E '(ignition/deployments/.*/artifacts/|ignition/deployments/.*/build-info/|/\.openzeppelin/|deployments/.*/solcInputs/)' || true; } | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
fi
- name: Lint YAML files
id: lint_yaml
continue-on-error: true
run: |
if [ "${{ steps.lint_mode.outputs.mode }}" = "all" ]; then
echo "Linting all YAML files..."
git ls-files '*.yml' '*.yaml' | xargs -r npx yaml-lint
git ls-files '*.yml' '*.yaml' | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
elif [ "${{ steps.changed_files.outputs.yaml_count }}" -gt "0" ]; then
echo "Linting changed YAML files..."
cat changed_yaml.txt | xargs -r npx yaml-lint
cat changed_yaml.txt | xargs -r npx prettier --check --cache --log-level warn --no-error-on-unmatched-pattern
fi
- name: Check lint results
if: always()
run: |
# Check if any lint step failed
if [ "${{ steps.lint_sol.outcome }}" = "failure" ] || \
[ "${{ steps.lint_ts.outcome }}" = "failure" ] || \
[ "${{ steps.lint_md.outcome }}" = "failure" ] || \
[ "${{ steps.lint_json.outcome }}" = "failure" ] || \
[ "${{ steps.lint_yaml.outcome }}" = "failure" ]; then
echo "❌ One or more linters failed"
exit 1
else
echo "✅ All linters passed"
fi