Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active September 27, 2022 19:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzyzanowskim/48f558531b78da2c9bd554a7885c59ff to your computer and use it in GitHub Desktop.
Save krzyzanowskim/48f558531b78da2c9bd554a7885c59ff to your computer and use it in GitHub Desktop.
Check if PR is missing formatting
name: auto-format
on: pull_request
jobs:
format:
# Check if the PR is not from a fork
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run SwiftFormat
id: git-check
run: |
docker pull ghcr.io/nicklockwood/swiftformat:latest
docker run --rm -v ${{ github.workspace }}:/work -w /work ghcr.io/nicklockwood/swiftformat:latest "**/*.swift"
echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
- name: Check code formatting status
if: steps.git-check.outputs.modified == 'true'
run: |
echo "::error::Code need formatting (run swiftformat)"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment