Last active
September 27, 2022 19:17
-
-
Save krzyzanowskim/48f558531b78da2c9bd554a7885c59ff to your computer and use it in GitHub Desktop.
Check if PR is missing formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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