-
Notifications
You must be signed in to change notification settings - Fork 124
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
ci: Add format check workflow #766
base: main
Are you sure you want to change the base?
Changes from 1 commit
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,56 @@ | ||||||
name: Format check | ||||||
|
||||||
on: | ||||||
pull_request: | ||||||
branches: | ||||||
- main | ||||||
paths: | ||||||
- '**.py' | ||||||
|
||||||
jobs: | ||||||
generate: | ||||||
runs-on: ubuntu-latest | ||||||
outputs: | ||||||
files: ${{ steps.git-diff-filter.outputs.files }} | ||||||
name: Detect added and changed files | ||||||
|
||||||
steps: | ||||||
- uses: actions/checkout@v4 | ||||||
with: | ||||||
fetch-depth: 0 | ||||||
|
||||||
- uses: GrantBirki/git-diff-action@v2 | ||||||
id: git-diff-action | ||||||
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. Can you make this name (slightly) different from the action name? Right now it's confusing to tell which object is being referred to. |
||||||
with: | ||||||
base_branch: origin/main | ||||||
search_path: '**.py' | ||||||
# Ignore deleted files | ||||||
git_options: '--no-color --diff-filter=d' | ||||||
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. Are you really sure |
||||||
|
||||||
- name: Filter json diff | ||||||
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. Filter what? It should be possible to have a clue without reading the code. 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. Doesn't |
||||||
id: git-diff-filter | ||||||
env: | ||||||
JSON_DIFF: ${{ steps.git-diff-action.outputs.json-diff }} | ||||||
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. Using |
||||||
run: | | ||||||
files=$(echo $JSON_DIFF | jq -c -r '[.files[] | {path: .path}]') | ||||||
echo "files=$files" >> $GITHUB_OUTPUT | ||||||
check-files: | ||||||
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.
Suggested change
|
||||||
needs: generate | ||||||
if: ${{ needs.generate.outputs.files != '[]' }} | ||||||
runs-on: ubuntu-latest | ||||||
# Allow the workflow run to pass when this job fails | ||||||
continue-on-error: true | ||||||
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. Does this just change red to green? If yes then I don't like it, sorry for the confusion. https://github.com/orgs/community/discussions/15452 If formatting fails then the check should be red to draw attention, then maintainers should be able to merge anyway. |
||||||
strategy: | ||||||
matrix: | ||||||
files: ${{ fromJSON(needs.generate.outputs.files) }} | ||||||
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. Wow! |
||||||
name: Check file ${{ matrix.files.path }} | ||||||
steps: | ||||||
- uses: actions/checkout@v4 | ||||||
- uses: astral-sh/ruff-action@v1 | ||||||
with: | ||||||
args: "format --check --diff" | ||||||
src: "${{ matrix.files.path }}" | ||||||
- if: ${{ failure() }} | ||||||
run: | | ||||||
echo "::warning file=${{ matrix.files.path }},title=File format check failed::Run 'ruff format ${{ matrix.files.path }}'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name is part of the "user interface" so can it be a bit longer and more specific?
find-changed-files
or better...