From 054e93df569d326ad069a20cfa788069441874a7 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:06:34 +0100 Subject: [PATCH 01/20] Auto format code with ruff --- .github/workflows/ruff-format.yml | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ruff-format.yml diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml new file mode 100644 index 000000000..c71108183 --- /dev/null +++ b/.github/workflows/ruff-format.yml @@ -0,0 +1,37 @@ +name: Automaticallly format the code with ruff +on: + pull_request: + branches: + - 'main' + paths: + - '**.py' + +jobs: + ruff: + permissions: + contents: write + name: Format the code with ruff and push the changes + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - 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 + - name: Format the code with ruff + run: ruff format + - name: Format the code with ruff check + run: ruff check --fix + - name: Create + run: | + git status + git diff + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git commit -am "Format with ruff" + git push origin HEAD:${{ github.head_ref }} --no-verify \ No newline at end of file From 98bca822652cb6ebd01913c49ad97a9b8677cb05 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:07:16 +0100 Subject: [PATCH 02/20] modify __init__.py to be formatted --- src/icalendar/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/icalendar/__init__.py b/src/icalendar/__init__.py index 9b22ac85d..81be579c5 100644 --- a/src/icalendar/__init__.py +++ b/src/icalendar/__init__.py @@ -178,3 +178,5 @@ "version", "version_tuple", ] + + From 8730f1566db1a5b374a8481a9f0e76cf64f17c77 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:10:16 +0100 Subject: [PATCH 03/20] Check for changes --- .github/workflows/ruff-format.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index c71108183..2247c45ca 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -30,8 +30,13 @@ jobs: - name: Create run: | git status - git diff - git config user.email "github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git commit -am "Format with ruff" - git push origin HEAD:${{ github.head_ref }} --no-verify \ No newline at end of file + if ! git diff --exit-code; then + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git commit -am "Format with ruff + + See https://icalendar--1199.org.readthedocs.build/en/1199/contribute/development.html#code-format" + git push origin HEAD:${{ github.head_ref }} --no-verify + else + echo "No changes to commit" + fi \ No newline at end of file From 155a7fdce50f8a81fb3ac1d8159d57e089eafaad Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:25:06 +0100 Subject: [PATCH 04/20] Use a different action to push the git commit --- .github/workflows/ruff-format.yml | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 2247c45ca..56c5ec034 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -27,16 +27,27 @@ jobs: run: ruff format - name: Format the code with ruff check run: ruff check --fix - - name: Create + - name: Show the changes run: | git status - if ! git diff --exit-code; then - git config user.email "github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git commit -am "Format with ruff - - See https://icalendar--1199.org.readthedocs.build/en/1199/contribute/development.html#code-format" - git push origin HEAD:${{ github.head_ref }} --no-verify - else - echo "No changes to commit" - fi \ No newline at end of file + git diff --exit-code + - name: Commit and push the changes if there are any + uses: EndBug/add-and-commit@v9 + with: + author_name: GitHub Actions Bot + author_email: github-actions[bot]@users.noreply.github.com + message: | + Format with ruff + + See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format + + # The way the action should handle pathspec errors from the add and remove commands. Three options are available: + # - ignore -> errors will be logged but the step won't fail + # - exitImmediately -> the action will stop right away, and the step will fail + # - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail. + # Default: ignore + pathspec_error_handling: ignore + + # Whether to push the commit and, if any, its tags to the repo. It can also be used to set the git push arguments (see the paragraph below for more info) + # Default: true + push: true From 21c256975b2f3e7b2af48944d631ab72ad5fa28d Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:29:39 +0100 Subject: [PATCH 05/20] do not fail if changes are there --- .github/workflows/ruff-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 56c5ec034..8e2c8c297 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -30,7 +30,7 @@ jobs: - name: Show the changes run: | git status - git diff --exit-code + git diff - name: Commit and push the changes if there are any uses: EndBug/add-and-commit@v9 with: From 20b31c2430aa3c108a5df5fa3d9c85814459fd37 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 17:54:55 +0100 Subject: [PATCH 06/20] Use another action step to push changes --- .github/workflows/ruff-format.yml | 37 ++++++++++++++----------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 8e2c8c297..d1657b306 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -10,10 +10,19 @@ jobs: ruff: permissions: contents: write + pull-requests: write name: Format the code with ruff and push the changes runs-on: ubuntu-latest + env: + GIT_COMMIT_MESSAGE: | + Format with ruff + + See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v6 with: @@ -31,23 +40,11 @@ jobs: run: | git status git diff - - name: Commit and push the changes if there are any - uses: EndBug/add-and-commit@v9 + 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" + - name: Push changes + uses: ad-m/github-push-action@master with: - author_name: GitHub Actions Bot - author_email: github-actions[bot]@users.noreply.github.com - message: | - Format with ruff - - See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format - - # The way the action should handle pathspec errors from the add and remove commands. Three options are available: - # - ignore -> errors will be logged but the step won't fail - # - exitImmediately -> the action will stop right away, and the step will fail - # - exitAtEnd -> the action will go on, every pathspec error will be logged at the end, the step will fail. - # Default: ignore - pathspec_error_handling: ignore - - # Whether to push the commit and, if any, its tags to the repo. It can also be used to set the git push arguments (see the paragraph below for more info) - # Default: true - push: true + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.head_ref }} \ No newline at end of file From 1ca1d9999863d0f34828167823d72a3624b80442 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:40:24 +0100 Subject: [PATCH 07/20] Run action on push of branch --- .github/workflows/ruff-format.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index d1657b306..5c6e2bfb7 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -1,18 +1,17 @@ name: Automaticallly format the code with ruff on: - pull_request: - branches: - - 'main' + push: paths: - '**.py' jobs: - ruff: + ruff-format: permissions: contents: write pull-requests: write name: Format the code with ruff and push the changes runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') == false && 'refs/heads/main' != github.ref && ! (startsWith(github.ref, 'refs/heads/' && endsWith(github.ref, '.x'))) env: GIT_COMMIT_MESSAGE: | Format with ruff @@ -21,7 +20,8 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: ${{ github.head_ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v6 From 7b3561d5caf03634fb4471ef87e6f0aea4fc3c1b Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:41:46 +0100 Subject: [PATCH 08/20] format on push --- .github/workflows/ruff-format.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 5c6e2bfb7..336f8e717 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -1,8 +1,6 @@ name: Automaticallly format the code with ruff on: - push: - paths: - - '**.py' + - push jobs: ruff-format: From 9f2bc964056bda798f364d56858fcb944af780b3 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:45:40 +0100 Subject: [PATCH 09/20] do not specify branch --- .github/workflows/ruff-format.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 336f8e717..46e52292f 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -45,4 +45,3 @@ jobs: uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.head_ref }} \ No newline at end of file From 92a4a8dc15f0bc968a2845c924a98a3d87288922 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:47:01 +0100 Subject: [PATCH 10/20] use ref_name for branch --- .github/workflows/ruff-format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 46e52292f..b8b2551c1 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -45,3 +45,4 @@ jobs: uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref_name }} From d7128bfe0a11be900663b44f9ec75d60181addfd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 17 Feb 2026 17:47:27 +0000 Subject: [PATCH 11/20] Format with ruff See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format --- src/icalendar/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/icalendar/__init__.py b/src/icalendar/__init__.py index 81be579c5..9b22ac85d 100644 --- a/src/icalendar/__init__.py +++ b/src/icalendar/__init__.py @@ -178,5 +178,3 @@ "version", "version_tuple", ] - - From b400a9980f5f93b19a348b32165f7d12675a0025 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:48:30 +0100 Subject: [PATCH 12/20] Update .github/workflows/ruff-format.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/ruff-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index b8b2551c1..6929f5b4f 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -1,4 +1,4 @@ -name: Automaticallly format the code with ruff +name: Automatically format the code with ruff on: - push From e577babdebf63576ff64f99aef18fc8c7b89baef Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 18:49:50 +0100 Subject: [PATCH 13/20] log changes --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e23090023..0a7c3b6cf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,7 +27,7 @@ We still recommend checking out the new features and giving feedback in the repo Minor changes ~~~~~~~~~~~~~ -- ... +- Pull Requests are formatted automatically. :pr:`1208` Breaking changes ~~~~~~~~~~~~~~~~ From 7a30d10fe42786dde83295b3a6908c134350ff86 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 21:46:40 +0100 Subject: [PATCH 14/20] fix push action Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/ruff-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 6929f5b4f..c46373fad 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -42,7 +42,7 @@ jobs: git config --local user.name "github-actions[bot]" git commit -a -m "${GIT_COMMIT_MESSAGE}" || echo "No changes to commit" - name: Push changes - uses: ad-m/github-push-action@master + uses: ad-m/github-push-action@v1.0.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{ github.ref_name }} From 820259013474a0a6b92111a114f5135e2a72a60f Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 21:47:16 +0100 Subject: [PATCH 15/20] Update CHANGES.rst Co-authored-by: Steve Piercy --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0a7c3b6cf..305fb9b89 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,7 +27,7 @@ We still recommend checking out the new features and giving feedback in the repo Minor changes ~~~~~~~~~~~~~ -- Pull Requests are formatted automatically. :pr:`1208` +- Pull requests from remote forks are formatted automatically. :pr:`1208` Breaking changes ~~~~~~~~~~~~~~~~ From f85612223d84621147118f0c5fd94156b762f056 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Tue, 17 Feb 2026 22:17:06 +0100 Subject: [PATCH 16/20] Fix run condition of auto formatting --- .github/workflows/ruff-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index c46373fad..3bb4bc9f2 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -9,7 +9,7 @@ jobs: pull-requests: write name: Format the code with ruff and push the changes runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') == false && 'refs/heads/main' != github.ref && ! (startsWith(github.ref, 'refs/heads/' && endsWith(github.ref, '.x'))) + if: ! startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main' && ! (startsWith(github.ref, 'refs/heads/') && endsWith(github.ref, '.x')) && ! startsWith(github.ref, 'refs/heads/release') env: GIT_COMMIT_MESSAGE: | Format with ruff From 1ce254c032cdd19897df88c543cd2ee33e81dc11 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 18 Feb 2026 09:58:14 +0100 Subject: [PATCH 17/20] remove unused repository scope and add commit step --- .github/workflows/ruff-format.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 3bb4bc9f2..f961c5e34 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -18,9 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: 0 + fetch-depth: 1 - name: Set up Python uses: actions/setup-python@v6 with: @@ -38,6 +36,8 @@ jobs: 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" From 1272cf3e031810b472db2fdfaae6f9cd4d027b77 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 18 Feb 2026 09:59:26 +0100 Subject: [PATCH 18/20] Apply suggestions from Sashank Co-authored-by: Sashank --- .github/workflows/ruff-format.yml | 2 +- CHANGES.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index f961c5e34..841ba3cf0 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -16,7 +16,7 @@ jobs: See https://icalendar.readthedocs.io/en/stable/contribute/development.html#code-format steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 1 - name: Set up Python diff --git a/CHANGES.rst b/CHANGES.rst index 5ad1c05ac..07d5bc92a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,7 +27,7 @@ We still recommend checking out the new features and giving feedback in the repo Minor changes ~~~~~~~~~~~~~ -- Pull requests from remote forks are formatted automatically. :pr:`1208` +- Branches pushed to the repository are formatted automatically with ruff. :pr:`1208` Breaking changes ~~~~~~~~~~~~~~~~ From c9aaa8cd8e4d1da65c1b3c380c1bc5e596848e76 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 18 Feb 2026 10:05:17 +0100 Subject: [PATCH 19/20] correct run condition --- .github/workflows/ruff-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 841ba3cf0..1959d08b7 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -9,7 +9,7 @@ jobs: pull-requests: write name: Format the code with ruff and push the changes runs-on: ubuntu-latest - if: ! startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main' && ! (startsWith(github.ref, 'refs/heads/') && endsWith(github.ref, '.x')) && ! startsWith(github.ref, 'refs/heads/release') + 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') env: GIT_COMMIT_MESSAGE: | Format with ruff From 73a97fefced5d42233b425d8ac2275b32204c2ce Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 18 Feb 2026 11:42:59 +0100 Subject: [PATCH 20/20] Document the auto-formatting workflow --- .github/workflows/ruff-format.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/ruff-format.yml b/.github/workflows/ruff-format.yml index 1959d08b7..7226306d8 100644 --- a/.github/workflows/ruff-format.yml +++ b/.github/workflows/ruff-format.yml @@ -1,4 +1,12 @@ 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 @@ -9,6 +17,16 @@ jobs: pull-requests: write name: Format the code with ruff and push the changes runs-on: ubuntu-latest + # + # Run conditions as safeguards + # + # This workflow EXCLUDES: + # + # - branch "main" + # - 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') env: GIT_COMMIT_MESSAGE: |