Skip to content

Add lint and format auto-fix workflow to automatically commit fixes on PR failures#7542

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-lint-action-to-pr-checks
Open

Add lint and format auto-fix workflow to automatically commit fixes on PR failures#7542
Copilot wants to merge 4 commits intomainfrom
copilot/add-lint-action-to-pr-checks

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Overview

This PR adds an automated lint and format fixing workflow that runs when lint or format checks fail on pull requests. The workflow automatically applies fixes and commits them back to the PR.

New workflow: .github/workflows/lint-autofix.yml

The workflow:

  • Triggers when the CI workflow completes with failures on a pull request
  • Detects if the lint job and/or format job failed
  • Automatically runs appropriate fix commands based on which jobs failed:
    • Format fixes: npm run format
    • Lint fixes: npm run lint:fix, npm run lint:css:fix
  • Commits and pushes the fixes back to the PR
  • Adds a contextual comment notifying contributors which issues were fixed

Changelog

New

  • Added .github/workflows/lint-autofix.yml - Automated lint and format fixing workflow that:
    • Monitors CI workflow completion for lint and format failures
    • Intelligently detects which jobs failed (lint, format, or both)
    • Runs Prettier formatting (npm run format) when format job fails
    • Runs ESLint auto-fix (npm run lint:fix) when lint job fails
    • Runs Stylelint auto-fix (npm run lint:css:fix) when lint job fails
    • Commits fixes using github-actions[bot]
    • Adds contextual PR comment notification indicating what was fixed

Changed

N/A

Removed

N/A

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; workflow-only change, no package changes

Testing & Reviewing

The workflow will automatically trigger when:

  1. A PR has lint and/or format failures in the CI workflow
  2. The CI workflow completes with the lint and/or format job in failure state
  3. The auto-fix workflow runs, applies appropriate fixes, and commits them

To test:

  • Create a PR with intentional lint violations and/or formatting issues
  • Verify the lint-autofix workflow triggers after CI fails
  • Confirm appropriate fixes are committed and pushed back to the PR (only the necessary fix commands run)
  • Check that a contextual notification comment is added indicating what was fixed

Merge checklist

Note: This PR only adds a GitHub Actions workflow file. Browser testing and integration tests are not applicable.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add lint action to PR checks workflow in PRC repo</issue_title>
<issue_description>Proposal: Run the lint action as part of our PR checks workflow in the PRC repository.

Background:

  • Currently, lint is not automatically run in primer/view_components and primer/react as a pre-commit hook or part of the PR checks.
  • Running formatting checks via a hook is generally helpful and avoids CI failures due to minor formatting issues.
  • However, pre-commit hooks for lint can be slow and annoying, especially when pushing drafts or working locally.
  • Adding lint as a PR check aligns with common practice and is less disruptive to contributors, who will expect it as part of the review workflow.

Request:

Benefits:

  • Reduces manual linting errors and streamlines contributor experience.
  • Provides early feedback in CI without hindering local development speed.

Assigning: lesliecdubs

View original Slack conversation</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes github/primer#6398

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

⚠️ No Changeset found

Latest commit: dba0ec0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI changed the title [WIP] Add lint action to PR checks workflow in PRC repo Document: Lint action already integrated in PR checks workflow Feb 13, 2026
Copilot AI requested a review from lesliecdubs February 13, 2026 17:55
@lesliecdubs
Copy link
Member

@copilot I don't just want the check to exist, I want the workflow to run the lint action if the check fails and then commit the change

Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@lesliecdubs Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 93297131-ee29-4f9c-a146-857eebc736ec

Sorry for the inconvenience!

@lesliecdubs
Copy link
Member

@copilot I don't just want the check to exist, I want the workflow to automatically run the lint action on the PR if the check fails, and then commit the change

Co-authored-by: lesliecdubs <3902488+lesliecdubs@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot I don't just want the check to exist, I want the workflow to automatically run the lint action on the PR if the check fails, and then commit the change

I've added a new workflow .github/workflows/lint-autofix.yml (commit caefe19) that automatically runs lint fix commands and commits the changes when the lint check fails on a PR.

The workflow:

  • Triggers when the CI workflow completes with failures on a PR
  • Checks if the lint job specifically failed
  • Runs npm run lint:fix, npm run lint:css:fix, and npm run format
  • Commits and pushes the auto-fixed changes back to the PR
  • Adds a comment notifying that lint issues were automatically fixed

This ensures that lint failures are automatically resolved without requiring contributors to fix them manually.

Copilot AI changed the title Document: Lint action already integrated in PR checks workflow Add lint auto-fix workflow to automatically commit fixes on PR failures Feb 13, 2026
@lesliecdubs lesliecdubs added the skip changeset This change does not need a changelog label Feb 13, 2026
@github-actions github-actions bot temporarily deployed to storybook-preview-7542 February 13, 2026 18:28 Inactive
@lesliecdubs
Copy link
Member

@copilot update this PR so that if the "format" check also fails, we run the proper format command and then commit the changes

Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@lesliecdubs Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 05d975f0-2668-4ea9-9788-5794728dbae3

Sorry for the inconvenience!

@lesliecdubs
Copy link
Member

@copilot update this PR so that if the "format" check also fails, we run the proper format command and then commit the changes

Co-authored-by: lesliecdubs <3902488+lesliecdubs@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot update this PR so that if the "format" check also fails, we run the proper format command and then commit the changes

I've updated the workflow (commit 67cce29) to handle both lint and format failures:

Changes:

  • Renamed step check_lintcheck_jobs to check both lint and format job failures
  • Added separate format_failed and lint_failed outputs
  • Split auto-fix into two steps:
    • "Run format auto-fix" - runs npm run format when format job fails
    • "Run lint auto-fix" - runs npm run lint:fix and npm run lint:css:fix when lint job fails
  • Updated commit message to "chore: auto-fix lint and formatting issues"
  • Made PR comment contextual (shows which issues were fixed: lint, format, or both)
  • Updated workflow name to "Lint and Format Auto-fix"

The workflow now intelligently runs only the necessary fix commands based on which jobs failed.

Copilot AI changed the title Add lint auto-fix workflow to automatically commit fixes on PR failures Add lint and format auto-fix workflow to automatically commit fixes on PR failures Feb 13, 2026
@github-actions github-actions bot temporarily deployed to storybook-preview-7542 February 13, 2026 18:50 Inactive
@lesliecdubs lesliecdubs marked this pull request as ready for review February 13, 2026 18:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new GitHub Actions workflow that automatically fixes lint and formatting issues when CI checks fail on pull requests. The workflow monitors CI workflow completion, detects which specific jobs (lint or format) failed, runs the appropriate auto-fix commands, and commits the fixes back to the PR with a notification comment.

Changes:

  • Added .github/workflows/lint-autofix.yml - A workflow_run-triggered workflow that automatically applies and commits lint and format fixes when CI fails on PRs

Comment on lines +19 to +22
# Only run on pull requests where lint or format failed
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow will fail when attempting to auto-fix lint/format issues on pull requests from forks. When a PR comes from a fork, the GitHub App token won't have permission to push to the fork repository. The workflow should check if the PR is from a fork and skip execution in that case, similar to how other workflows in this repository handle forks (e.g., deploy_preview.yml checks github.event.pull_request.head.repo.full_name == 'primer/react').

Add a check in the job-level condition to skip fork PRs. You can check this by comparing the head repo with the base repo, or by adding a check in the "Get Pull Request" step to set an output indicating whether it's from a fork, then use that in subsequent step conditions.

Suggested change
# Only run on pull requests where lint or format failed
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
# Only run on pull requests from this repository where lint or format failed
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.head_repository.full_name == github.repository

Copilot uses AI. Check for mistakes.
Comment on lines +122 to +145
- name: Comment on PR
if: steps.check_jobs.outputs.should_fix == 'true' && steps.pr.outputs.number != ''
uses: actions/github-script@5c56fde4671bc2d3592fb0f2c5b5bab9ddae03b1
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const lintFailed = '${{ steps.check_jobs.outputs.lint_failed }}' === 'true';
const formatFailed = '${{ steps.check_jobs.outputs.format_failed }}' === 'true';

let message = '🤖 ';
if (lintFailed && formatFailed) {
message += 'Lint and formatting issues have been automatically fixed and committed to this PR.';
} else if (lintFailed) {
message += 'Lint issues have been automatically fixed and committed to this PR.';
} else if (formatFailed) {
message += 'Formatting issues have been automatically fixed and committed to this PR.';
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.pr.outputs.number }},
body: message
});
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow will create a PR comment even when no fixes were actually committed. The git-auto-commit-action by default doesn't fail or skip when there are no changes to commit - it just doesn't create a commit. However, the "Comment on PR" step will still run and post a misleading message saying issues were fixed.

To fix this, you can capture the output from the git-auto-commit-action step (it sets a changes_detected output) and only run the comment step when changes were actually committed. For example:

  • Add an id to the "Commit and push changes" step
  • Update the "Comment on PR" condition to also check steps.commit_step_id.outputs.changes_detected == 'true'

Copilot uses AI. Check for mistakes.

- name: Run lint auto-fix
if: steps.check_jobs.outputs.lint_failed == 'true' && steps.pr.outputs.head_ref != ''
run: |
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow doesn't run npm run lint:md auto-fix, but the CI workflow includes a markdown linting step (npm run lint:md in the lint job). While markdownlint-cli2 doesn't have a built-in --fix flag, if markdown linting failures can be auto-fixed in the future, this workflow should be updated to include those fixes as well. Consider adding a comment noting this limitation or investigating if there's a fix command available for markdown linting.

Suggested change
run: |
run: |
# Note: CI runs `npm run lint:md` for markdown linting, but markdownlint-cli2
# does not currently support auto-fix. If a markdown lint auto-fix command
# (e.g. `npm run lint:md:fix`) is added in the future, update this step to run it.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changeset This change does not need a changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants