File tree Expand file tree Collapse file tree 1 file changed +30
-8
lines changed
Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Original file line number Diff line number Diff line change 11name : Prettify Code
2- # This action works with pull requests and pushes
32on :
43 pull_request :
54 push :
98jobs :
109 prettier :
1110 runs-on : ubuntu-latest
12-
1311 steps :
1412 - name : Checkout
1513 uses : actions/checkout@v4
1614 with :
17- ref : ${{ github.head_ref }}
1815 fetch-depth : 0
1916
20- - name : Prettify code
17+ - name : Fetch base branch
18+ if : github.event_name == 'pull_request'
19+ run : git fetch origin ${{ github.event.pull_request.base.ref }}
20+
21+ - name : Get changed files
22+ id : changed-files
23+ run : |
24+ if [ "${{ github.event_name }}" == "pull_request" ]; then
25+ BASE_SHA="origin/${{ github.event.pull_request.base.ref }}"
26+ else
27+ BASE_SHA="${{ github.event.before }}"
28+ fi
29+
30+ # Get files and store as space-separated string
31+ CHANGED_FILES=$(git diff --name-only --diff-filter=ACMR -z $BASE_SHA HEAD | \
32+ grep -zE '\.(js|md)$' | \
33+ xargs -0 -r)
34+
35+ if [ -n "$CHANGED_FILES" ]; then
36+ echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
37+ echo "has_files=true" >> $GITHUB_OUTPUT
38+ echo "Changed files: $CHANGED_FILES"
39+ else
40+ echo "has_files=false" >> $GITHUB_OUTPUT
41+ fi
42+
43+ - name : Check code formatting
44+ if : steps.changed-files.outputs.has_files == 'true'
21452246 with :
23- # This part is also where you can pass other options, for example:
2447 prettier_version : 2.8.8
25- prettier_options : --write **/*.{js,md}
26- same_commit : true
27-
48+ prettier_options : --check ${{ steps.changed-files.outputs.files }}
49+ dry : true
You can’t perform that action at this time.
0 commit comments