Skip to content

Commit ec7768e

Browse files
authored
Merge branch 'main' into fix/landingpage-product-section
2 parents 037d24f + 57ad5e8 commit ec7768e

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Prettify Code
2-
# This action works with pull requests and pushes
32
on:
43
pull_request:
54
push:
@@ -9,19 +8,42 @@ on:
98
jobs:
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'
2145
uses: creyD/[email protected]
2246
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

0 commit comments

Comments
 (0)