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.
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
  soundness:
    name: Soundness
    uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
    with:
      api_breakage_check_enabled: false  # https://github.com/swiftlang/swift-syntax/issues/3010
      docs_check_additional_arguments: "--disable-parameters-and-returns-validation"
  verify_source_code:
    name: Validate generated code
    runs-on: ubuntu-latest
    container:
      image: swift:latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
      - name: Validate generated code
        run: "./swift-syntax-dev-utils verify-source-code --toolchain /usr"
  test_using_swift_syntax_dev_utils_linux:
    name: Run tests using swift-syntax-dev-utils (Linux)
    runs-on: ubuntu-latest
    container:
      image: swift:latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
      - name: Test
        run: "./swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain /usr"
  test_using_swift_syntax_dev_utils_windows:
    name: Run tests using swift-syntax-dev-utils (Windows)
    runs-on: windows-2022
    steps:
      - name: Pull Docker image
        id: pull_docker_image
        run: |
          $Image = "swift:windowsservercore-ltsc2022"
          docker pull $Image
          echo "image=$Image" >> "$env:GITHUB_OUTPUT"
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
      - name: Test
        run: |
          mkdir $env:TEMP\test-script
          echo @'
          Set-PSDebug -Trace 1
          $SwiftPath = where.exe swift
          swift.exe run --package-path "C:\Source\SwiftSyntaxDevUtils" swift-syntax-dev-utils test --enable-rawsyntax-validation --enable-test-fuzzing --toolchain "$SwiftPath\..\.."
          if ($LastExitCode -ne 0) {
            exit $LastExitCode
          }
          '@ >> $env:TEMP\test-script\run.ps1
          docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1
