-
Notifications
You must be signed in to change notification settings - Fork 125
70 lines (61 loc) · 2.07 KB
/
format.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Format check
on:
pull_request:
branches:
- main
paths:
- '**.py'
jobs:
find-changed-files:
runs-on: ubuntu-latest
outputs:
files: ${{ steps.git-diff-files.outputs.files }}
name: Detect added and changed files
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create json diff
uses: GrantBirki/git-diff-action@v2
id: git-diff
with:
base_branch: origin/main
search_path: '**.py'
json_diff_file_output: diff.json
file_output_only: 'true'
# Ignore deleted files
git_options: '--no-color --diff-filter=d'
- name: Convert json diff to matrix array
id: git-diff-files
env:
JSON_DIFF: ${{ steps.git-diff.outputs.json-diff-path }}
run: |
# Github output expects oneliners, use compact mode
files=$(cat $JSON_DIFF | jq -c -r '[.files[] | {path: .path}]')
echo "files=$files" >> $GITHUB_OUTPUT
ruff-format:
needs: find-changed-files
if: ${{ needs.find-changed-files.outputs.files != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
files: ${{ fromJSON(needs.find-changed-files.outputs.files) }}
name: Check file ${{ matrix.files.path }}
steps:
- uses: actions/checkout@v4
- name: Run ruff format check for ${{ matrix.files.path }}
id: format-check
uses: astral-sh/ruff-action@v1
# Allow the job run to pass when this step fails
continue-on-error: true
with:
args: "format --check --diff"
src: "${{ matrix.files.path }}"
version: 0.8.1
- name: Annotate unformatted file
if: ${{ steps.format-check.outcome }} == 'failure'
env:
JOB_URL: "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
run: |
echo "::notice file=${{ matrix.files.path }},title=Unformatted file::Consider running 'ruff format ${{ matrix.files.path }}'%0ASee $JOB_URL for more details"