Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions .github/workflows/prettify_code.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Prettify Code
# This action works with pull requests and pushes
on:
pull_request:
push:
Expand All @@ -9,19 +8,42 @@ on:
jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Prettify code
- name: Fetch base branch
if: github.event_name == 'pull_request'
run: git fetch origin ${{ github.event.pull_request.base.ref }}

- name: Get changed files
id: changed-files
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
BASE_SHA="origin/${{ github.event.pull_request.base.ref }}"
else
BASE_SHA="${{ github.event.before }}"
fi

# Get files and store as space-separated string
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMR -z $BASE_SHA HEAD | \
grep -zE '\.(js|md)$' | \
xargs -0 -r)

if [ -n "$CHANGED_FILES" ]; then
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "has_files=true" >> $GITHUB_OUTPUT
echo "Changed files: $CHANGED_FILES"
else
echo "has_files=false" >> $GITHUB_OUTPUT
fi

- name: Check code formatting
if: steps.changed-files.outputs.has_files == 'true'
uses: creyD/[email protected]
with:
# This part is also where you can pass other options, for example:
prettier_version: 2.8.8
prettier_options: --write **/*.{js,md}
same_commit: true

prettier_options: --check ${{ steps.changed-files.outputs.files }}
dry: true
Loading