Skip to content

Commit 30ae79d

Browse files
committed
Allow proper diffbase for only checking files in current PR.
See norio-nomura#38 which has stalled.
1 parent 9f4dcd7 commit 30ae79d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- uses: actions/checkout@v1
24+
// Simple usage
2425
- name: GitHub Action for SwiftLint
2526
uses: norio-nomura/action-swiftlint@3.2.1
27+
// With custom argument
2628
- name: GitHub Action for SwiftLint with --strict
2729
uses: norio-nomura/action-swiftlint@3.2.1
2830
with:
2931
args: --strict
32+
// Only checks files changed in the PR
33+
- name: Fetch base ref
34+
run: |
35+
git fetch --prune --no-tags --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/heads/${{ github.base_ref }}
3036
- name: GitHub Action for SwiftLint (Only files changed in the PR)
3137
uses: norio-nomura/action-swiftlint@3.2.1
3238
env:
3339
DIFF_BASE: ${{ github.base_ref }}
40+
DIFF_HEAD: HEAD
41+
// Runs on different workspace
3442
- name: GitHub Action for SwiftLint (Different working directory)
3543
uses: norio-nomura/action-swiftlint@3.2.1
3644
env:

entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ then
2020
cd ${WORKING_DIRECTORY}
2121
fi
2222

23-
if ! ${DIFF_BASE+false};
24-
then
23+
if [ -n "$DIFF_BASE" ] && [ -n "$DIFF_HEAD" ]; then
24+
changedFiles=$(git --no-pager diff --name-only --relative $DIFF_HEAD $DIFF_BASE -- '*.swift')
25+
26+
if [ -z "$changedFiles" ]
27+
then
28+
echo "No Swift file changed"
29+
exit
30+
fi
31+
elif [ -n "$DIFF_BASE" ]; then
2532
changedFiles=$(git --no-pager diff --name-only --relative FETCH_HEAD $(git merge-base FETCH_HEAD $DIFF_BASE) -- '*.swift')
2633

2734
if [ -z "$changedFiles" ]

0 commit comments

Comments
 (0)