forked from zephyrproject-rtos/west
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (59 loc) · 1.91 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
name: Format check
on:
pull_request:
branches:
- main
paths:
- '**.py'
jobs:
generate:
runs-on: ubuntu-latest
outputs:
added: ${{ steps.git-diff-filter.outputs.added }}
changed: ${{ steps.git-diff-filter.outputs.changed }}
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
with:
base_branch: origin/main
search_path: '**.py'
git_options: '--no-color --full-index --unified=0'
json_diff_file_output: diff.json
# do not print any diff output to the console (safety first)
file_output_only: true
- name: Filter json diff
id: git-diff-filter
env:
JSON_DIFF: ${{ steps.git-diff-action.outputs.json-diff-path }}
run: |
# Filter files that only have deletions
added=$(cat $JSON_DIFF | jq -c -r '.files | map(select(.type == "AddedFile"))')
echo "added=$added" >> $GITHUB_OUTPUT
changed=$(cat $JSON_DIFF | jq -c -r '.files | map(select(.type == "ChangedFile")) | map(select(.chunks[].changes[].type == "AddedLine"))')
echo "changed=$changed" >> $GITHUB_OUTPUT
check-added:
needs: generate
if: ${{ needs.generate.outputs.added != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
added: ${{ fromJSON(needs.generate.outputs.added) }}
name: Format check (${{ matrix.added.path }})
steps:
- uses: astral-sh/ruff-action@v1
with:
args: "format --check --diff"
# check-changed:
# needs: generate
# runs-on: ubuntu-latest
# strategy:
# matrix: ${{ fromJSON(needs.generate.outputs.matrix) }}
# name: Print diff (${{ matrix.path }})
# steps:
# - name: Print json diff
# run: |
# echo "${{ matrix.path }}"