Update run-unit-tests.yml #5
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: Run pure unit tests | |
on: | |
workflow_call: | |
inputs: | |
package_root: | |
type: string | |
required: false | |
default: '' | |
description: "Specifies a subpath of the checkout to run tests and upload coverage from." | |
test_filter: | |
type: string | |
required: false | |
default: '' | |
description: "Apply a --filter to the tests that will be run." | |
with_coverage: | |
type: boolean | |
required: false | |
default: true | |
description: "Set to 'true' to collect and upload code coverage data. Defaults to 'false'." | |
coverage_ignores: | |
type: string | |
required: false | |
default: '/Tests/' | |
description: "Additional source-relative paths to ignore when generating code coverage reports." | |
with_tsan: | |
type: boolean | |
required: false | |
default: true | |
description: "Set to 'true' to run tests with Thread Sanitizer. Defaults to 'true'." | |
with_public_api_check: | |
type: boolean | |
required: false | |
default: true | |
description: "Set to 'true' to run the SwiftPM public API breakage check. Defaults to 'true'." | |
with_gh_codeql: | |
type: boolean | |
required: false | |
default: true | |
description: "Set to 'true' to run CodeQL checks. Defaults to 'true'." | |
with_deps_submission: | |
type: boolean | |
required: false | |
default: true | |
description: "Set to 'true' to submit a dependency graph to Github. Defaults to 'true'." | |
extra_flags: | |
type: string | |
required: false | |
default: '' | |
description: "Additional 'swift test' flags to be applied on when testing on all platforms." | |
env: | |
PACKAGE_ROOT: ${{ inputs.package_root != '' && format('--package-path={0}', inputs.package_root) || '' }} | |
EXTRA_FLAGS: ${{ inputs.extra_flags }} | |
WITH_TSAN: ${{ inputs.with_tsan && '' || '' }} | |
TEST_FILTER: ${{ inputs.test_filter != '' && format('--filter={0}', inputs.test_filter) || '' }} | |
defaults: | |
run: | |
shell: bash | |
# We use the unversioned "jammy" docker tag to specify the "latest" Swift release in several jobs. | |
jobs: | |
api-breakage: | |
if: ${{ inputs.with_public_api_check && !(github.event.pull_request.draft || false) && github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
container: swift:jammy | |
timeout-minutes: 20 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: { 'fetch-depth': 0 } | |
- name: Run API breakage check | |
run: | | |
git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
swift package ${PACKAGE_ROOT} diagnose-api-breaking-changes origin/main ${EXTRA_FLAGS} | |
dependency-graph: | |
if: ${{ inputs.with_deps_submission && github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
container: swift:jammy | |
permissions: | |
contents: write | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Fix Git configuration | |
run: | | |
git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
apt-get update && apt-get install -y curl | |
- name: Submit dependency graph | |
uses: vapor-community/[email protected] | |
with: | |
path: ${{ inputs.package_root != '' && inputs.package_root || github.workspace }} | |
code-coverage: | |
if: ${{ inputs.with_coverage && !(github.event.pull_request.draft || false) }} | |
runs-on: ubuntu-latest | |
container: swift:jammy | |
timeout-minutes: 30 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Run unit tests for coverage data | |
run: | | |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${TEST_FILTER} --enable-code-coverage ${EXTRA_FLAGS} | |
- name: Upload coverage data | |
uses: vapor/[email protected] | |
with: | |
package_path: ${{ inputs.package_root }} | |
ignore_paths: ${{ inputs.coverage_ignores }} | |
build_parameters: ${{ inputs.extra_flags }} | |
gh-codeql: | |
if: ${{ (false && inputs.with_gh_codeql) && !(github.event.pull_request.draft || false) }} | |
runs-on: ubuntu-latest | |
container: swift:jammy | |
permissions: { actions: write, contents: read, security-events: write } | |
timeout-minutes: 30 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Mark repo safe in non-fake global config | |
run: | | |
git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
- name: Check Swift compatibility | |
id: swift-check | |
uses: vapor/ci/.github/actions/check-compatible-swift@main | |
with: | |
package_root: ${{ inputs.package_root }} | |
- name: Initialize CodeQL | |
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }} | |
uses: github/codeql-action/init@v3 | |
with: { languages: swift } | |
- name: Perform build | |
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }} | |
run: | | |
swift build ${PACKAGE_ROOT} ${EXTRA_FLAGS} | |
- name: Run CodeQL analyze | |
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }} | |
uses: github/codeql-action/analyze@v3 | |
linux-unit: | |
if: ${{ !(github.event.pull_request.draft || false) }} | |
strategy: | |
fail-fast: false | |
matrix: | |
swift-image: | |
- swift:5.8-jammy | |
- swift:5.9-jammy | |
- swift:5.10-jammy | |
- swiftlang/swift:nightly-main-jammy | |
runs-on: ubuntu-latest | |
container: | |
image: ${{ matrix.swift-image }} | |
options: --privileged | |
timeout-minutes: 60 | |
steps: | |
- name: GH Runner bug workaround | |
run: 'if [[ "${ImageVersion}" == "20240310.1.0" ]]; then sysctl -w vm.mmap_rnd_bits=28; fi' | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Check Swift compatibility | |
id: swift-check | |
uses: vapor/ci/.github/actions/check-compatible-swift@main | |
with: | |
package_root: ${{ inputs.package_root }} | |
- name: Run unit tests | |
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }} | |
run: | | |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS} | |
macos-unit: | |
if: ${{ !(github.event.pull_request.draft || false) }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- macos-version: macos-13 | |
xcode-version: '~14.3' | |
- macos-version: macos-14 | |
xcode-version: latest | |
runs-on: ${{ matrix.macos-version }} | |
timeout-minutes: 60 | |
steps: | |
- name: Select appropriate Xcode version | |
uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: ${{ matrix.xcode-version }} | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Check Swift compatibility | |
id: swift-check | |
uses: vapor/ci/.github/actions/check-compatible-swift@main | |
with: | |
package_root: ${{ inputs.package_root }} | |
- name: Run unit tests | |
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }} | |
run: | | |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS} | |
# windows-unit: | |
# if: ${{ !(github.event.pull_request.draft || false) }} | |
# strategy: | |
# fail-fast: false | |
# matrix: | |
# swift-version: | |
# - 5.8 | |
# - 5.9 | |
# - 5.10 | |
# include: | |
# - { swift-version: 5.8, swift-branch: swift-5.8.1-RELEASE, swift-tag: 5.8.1-RELEASE } | |
# - { swift-version: 5.9, swift-branch: swift-5.9.2-RELEASE, swift-tag: 5.9.2-RELEASE } | |
# - { swift-version: 5.10, swift-branch: swift-5.10-RELEASE, swift-tag: 5.10-RELEASE } | |
# runs-on: windows-latest | |
# timeout-minutes: 60 | |
# steps: | |
# - name: Install Windows Swift toolchain | |
# uses: compnerd/gha-setup-swift@main | |
# with: | |
# branch: ${{ matrix.swift-branch }} | |
# tag: ${{ matrix.swift-tag }} | |
# - name: Check out code | |
# uses: actions/checkout@v4 | |
# - name: Run unit tests | |
# run: | | |
# SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS} |