diff --git a/README.md b/README.md index 2740a26..88de13a 100644 --- a/README.md +++ b/README.md @@ -21,16 +21,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + // Simple usage - name: GitHub Action for SwiftLint uses: norio-nomura/action-swiftlint@3.2.1 + // With custom argument - name: GitHub Action for SwiftLint with --strict uses: norio-nomura/action-swiftlint@3.2.1 with: args: --strict + // Only checks files changed in the PR + - name: Fetch base ref + run: | + git fetch --prune --no-tags --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/heads/${{ github.base_ref }} - name: GitHub Action for SwiftLint (Only files changed in the PR) uses: norio-nomura/action-swiftlint@3.2.1 env: DIFF_BASE: ${{ github.base_ref }} + DIFF_HEAD: HEAD + // Runs on different workspace - name: GitHub Action for SwiftLint (Different working directory) uses: norio-nomura/action-swiftlint@3.2.1 env: diff --git a/entrypoint.sh b/entrypoint.sh index a01922b..20897fa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,8 +20,15 @@ then cd ${WORKING_DIRECTORY} fi -if ! ${DIFF_BASE+false}; -then +if [ -n "$DIFF_BASE" ] && [ -n "$DIFF_HEAD" ]; then + changedFiles=$(git --no-pager diff --name-only --relative $DIFF_HEAD $DIFF_BASE -- '*.swift') + + if [ -z "$changedFiles" ] + then + echo "No Swift file changed" + exit + fi +elif [ -n "$DIFF_BASE" ]; then changedFiles=$(git --no-pager diff --name-only --relative FETCH_HEAD $(git merge-base FETCH_HEAD $DIFF_BASE) -- '*.swift') if [ -z "$changedFiles" ]