Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/ruff-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Automatically format the code with ruff
#
# This files solves the problem that files might be committed without prior formatting.
#
# - New contributors might forget to properly install the pre-commit hooks
# - Web edits might not be properly formatted. (line too long, bad spacing, ...)
#
# This file runs on the repository of the branch and updates the branch with fixes.
#
on:
- push

jobs:
ruff-format:
permissions:
contents: write
pull-requests: write
Comment thread
niccokunzmann marked this conversation as resolved.
Resolved
name: Format the code with ruff and push the changes
Comment thread
niccokunzmann marked this conversation as resolved.
Resolved
runs-on: ubuntu-latest
#
# Run conditions as safeguards
#
# This workflow EXCLUDES:
#
# - branch "main"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sounds like I can fork to stevepiercy/icalendar, push to my main and it won't run.

Then when I open a PR against collective/icalendar on its main branch, it still won't run.

Is that what you want?

Same for the remaining exclusions below.

@niccokunzmann niccokunzmann Feb 18, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think, that is a good start.

It can be extended to format main on other repos as that is where first -timers often start like in #1205. I would do that another time, and it requires more consideration.

I think, I prefer it if main stays main and can be fast-forwarded to collective/calendar's main.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Honestly, I think automatically rewriting pull requests is a bad idea all around. Pull requests should be intentional and deliberate, which is something only humans can do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That is ok. I will not talk about the value. I see value. I would like to see if this is technically correct. Then, I will merge it or someone else does it and we see if it makes sense. We can remove it if it gets in the way of contribution.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Honestly, I think automatically rewriting pull requests is a bad idea all around. Pull requests should be intentional and deliberate, which is something only humans can do.

+1

# - tags
# - branches that end with ".x" (e.g. "6.x", "7.x")
# - branches that start with "release" (e.g. "release-7.0.2")
#
if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') && !(startsWith(github.ref, 'refs/heads/') && endsWith(github.ref, '.x')) && !startsWith(github.ref, 'refs/heads/release')

@niccokunzmann niccokunzmann Feb 18, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ! at the start was ignored by GitHub. I re-ordered the condition to not start with that.

In the downloaded log zip, there is a system.txt showing:

(
  true && (
  ('refs/heads/auto-format' != 'refs/heads/main')
  && !startsWith('refs/heads/auto-format', 'refs/tags/') 
  && !(
    startsWith('refs/heads/auto-format', 'refs/heads/')
    && endsWith('refs/heads/auto-format', '.x')
  )
  && !startsWith('refs/heads/auto-format', 'refs/heads/release')))

That should exclude main, all .x branches and tags as well as the release-... branches created by the maintenance tasks of releasing.

env:
GIT_COMMIT_MESSAGE: |
Format with ruff

See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.14
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . --group formatting
Comment thread
niccokunzmann marked this conversation as resolved.
Resolved
- name: Format the code with ruff
run: ruff format
- name: Format the code with ruff check
run: ruff check --fix
Comment thread
niccokunzmann marked this conversation as resolved.
Resolved
Comment thread
niccokunzmann marked this conversation as resolved.
Resolved
Comment thread
SashankBhamidi marked this conversation as resolved.
Resolved
- name: Show the changes
run: |
git status
git diff
- name: Commit changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "${GIT_COMMIT_MESSAGE}" || echo "No changes to commit"
Comment thread
SashankBhamidi marked this conversation as resolved.
Resolved
- name: Push changes
uses: ad-m/github-push-action@v1.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We still recommend checking out the new features and giving feedback in the repo
Minor changes
~~~~~~~~~~~~~

- Branches pushed to the repository are formatted automatically with ruff. :pr:`1208`
- Use ruff 0.15.0 for code formatting in :file:`tox.ini`. :pr:`1215`

Breaking changes
Expand Down