diff --git a/.github/workflows/swift-test.yml b/.github/workflows/swift-test.yml index b7a0c9e..86a5b6a 100644 --- a/.github/workflows/swift-test.yml +++ b/.github/workflows/swift-test.yml @@ -60,9 +60,15 @@ on: required: false type: string default: Debug + build_flags: + description: | + Additional flags to pass to both `swift build` and `swift test` (e.g. --build-system native, -Xswiftc -warnings-as-errors). + required: false + type: string + default: '' test_flags: description: | - Additional flags to pass to `swift test` (e.g. --no-parallel, --filter, --skip). + Additional flags to pass to `swift test` only (e.g. --no-parallel, --filter, --skip). required: false type: string default: '' @@ -107,19 +113,31 @@ jobs: GIT_CONFIG_COUNT: 1 GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/.insteadOf GIT_CONFIG_VALUE_0: https://github.com/ + BUILD_FLAGS: ${{ inputs.build_flags }} run: | build_configuration="$(printf '%s' "$BUILD_CONFIGURATION" | awk '{print tolower($0)}')" + build_args=() + if [ -n "$BUILD_FLAGS" ]; then + read -r -a build_args <<< "$BUILD_FLAGS" + fi + swift build \ - --configuration "$build_configuration" + --configuration "$build_configuration" \ + "${build_args[@]}" - name: Run tests env: BUILD_CONFIGURATION: ${{ inputs.build_configuration }} GIT_CONFIG_COUNT: 1 GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/.insteadOf GIT_CONFIG_VALUE_0: https://github.com/ + BUILD_FLAGS: ${{ inputs.build_flags }} TEST_FLAGS: ${{ inputs.test_flags }} run: | build_configuration="$(printf '%s' "$BUILD_CONFIGURATION" | awk '{print tolower($0)}')" + build_args=() + if [ -n "$BUILD_FLAGS" ]; then + read -r -a build_args <<< "$BUILD_FLAGS" + fi test_args=() if [ -n "$TEST_FLAGS" ]; then read -r -a test_args <<< "$TEST_FLAGS" @@ -128,6 +146,7 @@ jobs: swift test \ --enable-code-coverage \ --configuration "$build_configuration" \ + "${build_args[@]}" \ "${test_args[@]}" - name: Generate coverage report if: ${{ (success() || failure()) && inputs.artifact_name != '' }} diff --git a/README.md b/README.md index 825f733..d023f28 100644 --- a/README.md +++ b/README.md @@ -385,6 +385,7 @@ jobs: [`swift-test.yml`](.github/workflows/swift-test.yml) runs SwiftPM tests and can upload an LCOV artifact for later coverage merging. Use it for Linux Swift package tests or simple SwiftPM test jobs. +Pass `build_flags` for options both `swift build` and `swift test` need, such as `--build-system native`, and `test_flags` for options only `swift test` accepts, such as `--filter`. ```yml jobs: