Repository navigation
Auto format code on non-protected branches. #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
054e93d
98bca82
8730f15
155a7fd
21c2569
20b31c2
1ca1d99
7b3561d
9f2bc96
92a4a8d
d7128bf
b400a99
e577bab
7a30d10
8202590
0837313
f856122
5100fee
1ce254c
1272cf3
c9aaa8c
73a97fe
3c119b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| name: Format the code with ruff and push the changes | ||
|
niccokunzmann marked this conversation as resolved.
Resolved
|
||
| runs-on: ubuntu-latest | ||
| # | ||
| # Run conditions as safeguards | ||
| # | ||
| # This workflow EXCLUDES: | ||
| # | ||
| # - branch "main" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like I can fork to Then when I open a PR against Is that what you want? Same for the remaining exclusions below.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+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') | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: That should exclude |
||
| 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 | ||
|
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 | ||
|
niccokunzmann marked this conversation as resolved.
Resolved
niccokunzmann marked this conversation as resolved.
Resolved
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" | ||
|
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 }} | ||
Uh oh!
There was an error while loading. Please reload this page.