name: Code style check - Swift

on:
  pull_request:
    branches: [ master ]
    paths:
      - '.github/workflows/swift-code-style-check.yaml'
      - 'iphone/.swift-version'
      - 'iphone/.swiftformat'
      - 'iphone/**.swift'

jobs:
  code-style-check-swift:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Install swiftformat
        run: |
          eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"  # Homebrew is not in PATH by default.
          brew install swiftformat
          swiftformat --version

      - name: Checkout sources
        uses: actions/checkout@v6

      - name: Run swiftformat
        run: |
          eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"  # Homebrew is not in PATH by default.
          swiftformat iphone

      - name: Post swiftformat comments
        if: failure()
        uses: reviewdog/action-suggester@aa38384ceb608d00f84b4690cacc83a5aba307ff # v1.24.0
        with:
          fail_level: error
          tool_name: swiftformat
        env:
          GITHUB_TOKEN: ${{ secrets.REVIEWDOG_TOKEN }}
