Skip to content

Conversation

@Artur-
Copy link
Member

@Artur- Artur- commented Oct 7, 2025

Merges the separate formatter workflow into the validation workflow with
automatic commit and push capabilities for formatting changes.

Changes:

  • Deleted standalone .github/workflows/formatter.yml
  • Integrated formatter as first job in validation.yml workflow
  • Added auto-commit functionality using PAT token (VAADIN_BOT_TOKEN)
  • Formatter now commits and pushes changes when formatting issues detected
  • Workflow stops after committing, new workflow run is triggered by the commit
  • On second run, detects bot commit and skips formatting, proceeds to validation
  • Changed workflow permissions to include contents:write for pushing commits
  • Build and test jobs only run if formatter succeeds (no changes or after bot commit)

Infinite loop prevention:

  • Checks if last commit author is github-actions[bot]
  • If true, skips formatting step and proceeds to validation
  • Prevents endless formatting cycles if formatter is inconsistent

Token requirements:

  • Requires VAADIN_BOT_TOKEN secret with repo and workflow permissions
  • Workflow fails immediately if token is not configured
  • PAT needed because GITHUB_TOKEN cannot trigger workflow runs

PR comment behavior:

  • Posts comment when formatting changes are auto-committed
  • Deletes comment when formatting is correct
  • Includes list of files that were modified

@Artur- Artur- force-pushed the flow-spotless-update branch 2 times, most recently from 58cd01c to 52aec19 Compare October 7, 2025 13:06
@github-actions
Copy link

github-actions bot commented Oct 7, 2025

Test Results

1 281 files  ±0  1 281 suites  ±0   1h 16m 39s ⏱️ -36s
8 876 tests ±0  8 809 ✅ ±0  67 💤 ±0  0 ❌ ±0 
9 329 runs   - 5  9 252 ✅  - 5  77 💤 ±0  0 ❌ ±0 

Results for commit 12f7a91. ± Comparison against base commit ee5139e.

♻️ This comment has been updated with latest results.

@Artur- Artur- force-pushed the flow-spotless-update branch from b217255 to 347f208 Compare October 8, 2025 06:44
@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Oct 8, 2025
@Artur- Artur- force-pushed the flow-spotless-update branch from a1b95ee to 347f208 Compare October 8, 2025 09:32
Merges the separate formatter workflow into the validation workflow with
automatic commit and push capabilities for formatting changes.

Changes:
- Deleted standalone .github/workflows/formatter.yml
- Integrated formatter as first job in validation.yml workflow
- Added auto-commit functionality using PAT token (VAADIN_BOT_TOKEN)
- Formatter now commits and pushes changes when formatting issues detected
- Workflow stops after committing, new workflow run is triggered by the commit
- On second run, detects bot commit and skips formatting, proceeds to validation
- Changed workflow permissions to include contents:write for pushing commits
- Build and test jobs only run if formatter succeeds (no changes or after bot commit)

Infinite loop prevention:
- Checks if last commit author is github-actions[bot]
- If true, skips formatting step and proceeds to validation
- Prevents endless formatting cycles if formatter is inconsistent

Token requirements:
- Requires VAADIN_BOT_TOKEN secret with repo and workflow permissions
- Workflow fails immediately if token is not configured
- PAT needed because GITHUB_TOKEN cannot trigger workflow runs

PR comment behavior:
- Posts comment when formatting changes are auto-committed
- Deletes comment when formatting is correct
- Includes list of files that were modified

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Artur- Artur- force-pushed the flow-spotless-update branch from ff69418 to 37e8c75 Compare October 8, 2025 09:38
@Artur- Artur- changed the title feat: add auto-commit formatter workflow with loop prevention feat: auto-commit code formatting changes in CI workflow Oct 8, 2025
@Artur- Artur- requested review from ZheSun88 and mshabarov October 8, 2025 09:39
@Artur- Artur- marked this pull request as ready for review October 8, 2025 09:39
@vaadin-bot vaadin-bot added +0.0.1 and removed +1.0.0 labels Oct 8, 2025
@platosha
Copy link
Contributor

Just a question: do I understand correctly, that this change makes validation workflow unusable for external contributor PRs, since the bot cannot push to respective branches? If so, would it make sense to introduce a fallback to just checking formatting in the absence of push access?

@Artur-
Copy link
Member Author

Artur- commented Oct 10, 2025

Most often contributors tend to check the checkbox that maintainers can make updates. Does this mean that formatting will also work? I have not tried

@platosha platosha changed the title feat: auto-commit code formatting changes in CI workflow build: merge code formatter CI workflow with the validation build, test only after formatter succeeds Oct 13, 2025
build:
formatter:
needs: check-permissions
if: github.event_name == 'pull_request_target'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, this condition needs to removed or adjusted. I tried dispatching this workflow from the PR branch manually using the dispatch button, here's what happened:

  • it skipped the formatter job because it was not the pull_request_target event,
  • then it skipped the build job probably because formatter is required,
  • then it skipped the testing jobs also,
  • ...and then it reported a false positive, oh no!

See: https://github.com/vaadin/flow/actions/runs/18466985120

Keeping the manual dispatch function working is useful for enabling maintainers to verify workflow changes from PR branches. Let's not limit the supported triggers. If auto-commit from the formatter isn't appropriate, it could fallback to checking only.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated this

Integrated latest changes from main while preserving auto-commit formatter:
- Kept auto-commit formatter in validation.yml (no separate formatter.yml)
- Added JAVA_VERSION and PR_NUMBER environment variables
- Added api-diff-labeling job for automatic PR version labeling
- Incorporated all code changes from main (signal binding, Abbr component, etc.)
- Updated to use env.JAVA_VERSION for JDK setup steps
- Kept parallel unit test count at 3

The auto-commit formatter functionality is preserved - formatting issues
will be automatically committed to PRs instead of blocking them.
@github-actions github-actions bot added +0.1.0 and removed +0.0.1 labels Oct 30, 2025
@vaadin-bot vaadin-bot added +0.0.1 and removed +0.1.0 labels Oct 30, 2025
Changes:
- Remove restrictive 'if: pull_request_target' condition from formatter job
- Make auto-commit steps conditional on pull_request_target event
- Add check-only mode that fails on formatting errors for other triggers
- Update checkout to work with both PR and dispatch events
- Update build job to proceed when formatter is skipped
- Make PR comments conditional on pull_request_target

This allows maintainers to manually dispatch the workflow from PR branches
for testing workflow changes, while preserving auto-commit for PRs and
check-only validation for other triggers.

Addresses feedback from @platosha
@github-actions github-actions bot added +0.1.0 and removed +0.0.1 labels Oct 30, 2025
@vaadin-bot vaadin-bot added +0.0.1 and removed +0.1.0 labels Oct 30, 2025
Performance improvements:
- Add step to detect changed Java files compared to target branch
- Use spotless ratchetFrom feature to only format changed files
- Skip formatter entirely when no Java files have changed
- Update all dependent step conditions to handle skipped formatter

This significantly speeds up the formatter job, especially for:
- Large PRs with changes in specific modules
- PRs that don't modify Java files (e.g., documentation changes)
- Repositories with many files

The ratchetFrom feature compares against the PR base branch and only
applies formatting to files that have been modified, added, or renamed.
@github-actions github-actions bot added +0.1.0 and removed +0.0.1 labels Oct 30, 2025
@vaadin-bot vaadin-bot added +0.0.1 and removed +0.1.0 labels Oct 30, 2025
Major performance improvement by detecting which modules contain changed
files and running spotless only on those specific modules using Maven's
-pl (--projects) flag.

Changes:
- Detect unique Maven module paths from changed Java files
- Pass module list to mvn spotless:apply using -pl flag
- Combined with ratchetFrom for maximum efficiency

Performance impact:
- Before: Maven processes ALL modules (~50+) even for single file change
- After: Maven only processes affected modules (typically 1-3)

Example scenarios:
- Change in flow-server only: formats 1 module instead of 50+
- Change in 3 modules: formats 3 modules instead of 50+
- Nested modules (flow-plugins/flow-maven-plugin) handled correctly

This dramatically reduces formatter execution time from minutes to seconds
for typical PRs that touch only a few modules.
@github-actions github-actions bot added +0.1.0 and removed +0.0.1 labels Oct 30, 2025
@vaadin-bot vaadin-bot added +0.0.1 and removed +0.1.0 labels Oct 30, 2025
@sonarqubecloud
Copy link

@Artur-
Copy link
Member Author

Artur- commented Oct 30, 2025

Changed so the formatter finds changed files + modules and only runs the formatter there. Speeds it up by a minute or so when only one file is changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants