name: Lint # # This workflow lints the library and reports back suggested fixes # on: push: branches: - main pull_request: branches: - main types: - opened - synchronize - reopened - auto_merge_enabled permissions: contents: read pull-requests: write concurrency: group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' cancel-in-progress: true defaults: run: shell: bash jobs: # ------------------------------------------------------------- # Returns all changed pull request files. # -------------------------------------------------------------- changed_files: runs-on: ubuntu-26.04 name: Capture changed-files outputs: styles_added_files: ${{ steps.changed-files.outputs.styles_added_files }} styles_modified_files: ${{ steps.changed-files.outputs.styles_modified_files }} eslint_added_files: ${{ steps.changed-files.outputs.eslint_added_files }} eslint_modified_files: ${{ steps.changed-files.outputs.eslint_modified_files }} prettier_added_files: ${{ steps.changed-files.outputs.prettier_added_files }} prettier_modified_files: ${{ steps.changed-files.outputs.prettier_modified_files }} permissions: pull-requests: read steps: - name: Check out code uses: actions/checkout@v7 - name: Get changed files id: changed-files uses: step-security/changed-files@v47 with: files_yaml: | styles: - '*.css' - '**/*.css' - '!1st-gen/**' eslint: - '*.{js,json,ts,tsx}' - '**/*.{js,json,ts,tsx}' - '!*.d.ts' - '!**/*.d.ts' - '!1st-gen/**' prettier: - '*.{js,json,ts,tsx,css,md,mdx,yaml,yml,html}' - '**/*.{js,json,ts,tsx,css,md,mdx,yaml,yml,html}' - '!*.d.ts' - '!**/*.d.ts' - '!1st-gen/**' # --- Lint pre-compiled assets for consistency --- # lint: name: Lint runs-on: ubuntu-26.04 needs: [changed_files] # Push runs also lint the whole repo, which adds about a minute. timeout-minutes: 10 steps: # install but don't build - we're linting pre-compiled assets - name: Check out code uses: actions/checkout@v7 with: fetch-depth: 0 - name: Use Node version from .nvmrc uses: actions/setup-node@v7 with: node-version-file: '.nvmrc' cache: yarn - name: Enable Corepack run: corepack enable ## --- YARN CACHE --- ## - name: Check for cached dependencies continue-on-error: true id: cache-dependencies uses: actions/cache@v6 with: path: | .cache/yarn node_modules key: ubuntu-26.04-${{ hashFiles('.nvmrc', 'package.json', 'yarn.lock') }} ## --- INSTALL --- ## # If statement isn't needed here b/c yarn will leverage the cache if it exists - name: Install dependencies shell: bash run: yarn install --immutable - name: Validate generated version files run: node scripts/generate-versions.js --check - name: Test custom lint rules run: yarn test:linters # Reviewdog's github-pr-review reporter only works on pull requests. On # push it exits without reading stdin, so the linter crashes with EPIPE. - name: Lint styles if: ${{ github.event_name == 'pull_request' && (needs.changed_files.outputs.styles_added_files != '' || needs.changed_files.outputs.styles_modified_files != '') }} uses: reviewdog/action-stylelint@v1.33.0 with: fail_level: warning filter_mode: diff_context level: warning reporter: github-pr-review stylelint_input: '${{ needs.changed_files.outputs.styles_added_files }} ${{ needs.changed_files.outputs.styles_modified_files }} --allow-empty-input' - name: ESLint if: ${{ github.event_name == 'pull_request' && (needs.changed_files.outputs.eslint_added_files != '' || needs.changed_files.outputs.eslint_modified_files != '') }} uses: reviewdog/action-eslint@v1.36.1 with: fail_level: warning level: warning reporter: github-pr-review filter_mode: diff_context eslint_flags: '${{ needs.changed_files.outputs.eslint_added_files }} ${{ needs.changed_files.outputs.eslint_modified_files }}' # Post-merge smoke test: lint the repo on main, skipping 1st-gen to match # the pull request scope. Fails on errors only; existing warnings are # reported but don't fail the run. - name: ESLint (whole repo) if: ${{ github.event_name == 'push' }} run: yarn lint:eslint --ignore-pattern '1st-gen/**' - name: Stylelint (whole repo) if: ${{ github.event_name == 'push' }} run: yarn lint:styles - name: Prettier if: ${{ needs.changed_files.outputs.prettier_added_files != '' || needs.changed_files.outputs.prettier_modified_files != '' }} run: | FILES="${{ needs.changed_files.outputs.prettier_added_files }} ${{ needs.changed_files.outputs.prettier_modified_files }}" # Trim whitespace and skip if only whitespace remains FILES=$(echo "$FILES" | xargs) if [ -n "$FILES" ]; then yarn prettier --check $FILES fi - name: Validate AI tooling run: yarn lint:ai