Format source code and run git diff instead of listing first
#512
Workflow file for this run
This file contains hidden or 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: Pull request | |
| # PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs). | |
| # As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. We'd prefer not re-triggering testing on a normal user's PR in this case, but skipping them causes the checks to reset. | |
| permissions: | |
| contents: read | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize, ready_for_review] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| tests: | |
| name: Test | |
| uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main | |
| with: | |
| enable_cross_pr_testing: true | |
| soundness: | |
| name: Soundness | |
| uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main | |
| with: | |
| license_header_check_project_name: "Swift.org" | |
| api_breakage_check_allowlist_path: "api-breakages.txt" | |
| compatibility_check: | |
| # Format a list of real-world projects that enforce formatting using the latest swift-format version. | |
| name: Check compatibility with real world projects | |
| runs-on: ubuntu-latest | |
| container: | |
| image: swift:6.2 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Check out related PRs | |
| run: | | |
| apt-get update && apt-get install -y curl | |
| curl -s https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/cross-pr-checkout.swift > /tmp/cross-pr-checkout.swift | |
| swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}" | |
| - name: Build | |
| run: swift build --configuration release | |
| - name: Write check script | |
| run: | | |
| cat > /tmp/check-formatting.sh <<EOL | |
| #!/usr/bin/env sh | |
| set -ex | |
| cd "$1" | |
| # Format and run `git diff` first because this yields more insightful results than `swift-format lint` | |
| .build/release/swift-format --in-place --parallel --recursive . | |
| git diff | |
| # Linting may discover issues that weren't changed during formatting (such as diagnosing lowercase classes). Check that we didn't introduce any new lint errors. | |
| .build/release/swift-format lint --parallel --recursive --strict . | |
| EOL | |
| chmod a+x /tmp/check-formatting.sh | |
| - name: Format swift-format | |
| run: /tmp/check-formatting.sh . | |
| - name: Checkout swift-syntax | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: swiftlang/swift-syntax | |
| persist-credentials: false | |
| path: swift-syntax | |
| - name: Format swift-syntax | |
| run: /tmp/check-formatting.sh swift-syntax | |
| - name: Checkout sourcekit-lsp | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: swiftlang/sourcekit-lsp | |
| persist-credentials: false | |
| path: sourcekit-lsp | |
| - name: Format sourcekit-lsp | |
| run: /tmp/check-formatting.sh sourcekit-lsp |