Skip to content

Commit

Permalink
[GHA] Introduce reusable matrix workflow
Browse files Browse the repository at this point in the history
# Motivation

We have a few checks that we want to run across all supported Swift versions e.g. unit tests and benchmarks. Right now we already added two matrix based jobs to the reusable workflow. This leads to a lot of duplication and harder maintenance.

# Modification

This PR splits off the current reusable workflow to only contain soundness related checks and introduces a new reusable matrix based workflow which can be customized to execute different commands.

# Result

It is now easy to setup multiple matrix based workflows.
  • Loading branch information
FranzBusch committed Jul 15, 2024
1 parent 7b03cb2 commit d53439c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 70 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ on:
types: [opened, reopened, synchronize, ready_for_review]

jobs:
call-reusable-pull-request-workflow:
call-pull-request-soundness-workflow:
name: Checks
uses: ./.github/workflows/reusable_pull_request.yml
uses: ./.github/workflows/pull_request_soundness.yml
with:
benchmarks_linux_package_path: "Benchmarks"
license_header_check_project_name: "SwiftNIO"
format_check_enabled: false

call-pull-request-unit-tests-workflow:
name: Checks
uses: ./.github/workflows/pull_request_swift_matrix.yml
with:
matrix_linux_name: "Unit tests"
matrix_linux_command: "swift test"
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ name: Pull Request
on:
workflow_call:
inputs:
unit_tests_linux_enabled:
type: boolean
description: "Boolean to enable the unit tests linux job. Defaults to true."
default: true
benchmarks_linux_enabled:
type: boolean
description: "Boolean to enable the benchmarks linux job. Defaults to true."
default: true
benchmarks_linux_package_path:
type: string
description: "Path to the package containing the benchmarks. Defaults to the repository root."
default: "."
api_breakage_check_enabled:
type: boolean
description: "Boolean to enable the API breakage check job. Defaults to true."
Expand Down Expand Up @@ -50,64 +38,10 @@ on:

## We are cancelling previously triggered workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}-soudness
cancel-in-progress: true

jobs:
unit-tests-linux:
name: Unit tests
if: ${{ inputs.unit_tests_linux_enabled }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift:
- image: swift:5.8-jammy
- image: swift:5.9-jammy
- image: swift:5.10-jammy
- image: swiftlang/swift:nightly-6.0-jammy
- image: swiftlang/swift:nightly-main-jammy
container:
image: ${{ matrix.swift.image }}
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run tests
run: swift test

benchmarks-linux:
name: Benchmarks
if: ${{ inputs.benchmarks_linux_enabled }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift:
- image: swift:5.8-jammy
swift_version: "5.8"
- image: swift:5.9-jammy
swift_version: "5.9"
- image: swift:5.10-jammy
swift_version: "5.10"
- image: swiftlang/swift:nightly-6.0-jammy
swift_version: "nightly-next"
- image: swiftlang/swift:nightly-main-jammy
swift_version: "nightly-main"
container:
image: ${{ matrix.swift.image }}
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run tests
env:
PACKAGE_PATH: ${{ inputs.benchmarks_linux_package_path }}
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
run: |
apt-get update -y -q && apt-get install -y -q libjemalloc-dev
swift package --package-path ${PACKAGE_PATH} --disable-sandbox benchmark baseline check --check-absolute-path ${PACKAGE_PATH}/Thresholds/${SWIFT_VERSION}/
api-breakage-check:
name: API breakage check
if: ${{ inputs.api_breakage_check_enabled }}
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/pull_request_swift_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Pull Request

on:
workflow_call:
inputs:
matrix_linux_name:
type: string
description: "The name of the linux matrix job."
required: true
matrix_linux_command:
type: string
description: "The command of the current Swift version linux matrix job to execute."
required: true
matrix_linux_5_8_enabled:
type: string
description: "The command of the 5.8 Swift version linux matrix job to execute."
matrix_linux_5_8_command_override:
type: string
description: "The command of the 5.8 Swift version linux matrix job to execute."
matrix_linux_5_9_enabled:
type: string
description: "The command of the 5.9 Swift version linux matrix job to execute."
matrix_linux_5_9_command_override:
type: string
description: "The command of the 5.9 Swift version linux matrix job to execute."
matrix_linux_5_10_enabled:
type: string
description: "The command of the 5.10 Swift version linux matrix job to execute."
matrix_linux_5_10_command_override:
type: string
description: "The command of the 5.10 Swift version linux matrix job to execute."
matrix_linux_nightly_next_enabled:
type: string
description: "The command of the nightly next Swift version linux matrix job to execute."
matrix_linux_nightly_next_command_override:
type: string
description: "The command of the nightly next Swift version linux matrix job to execute."
matrix_linux_nightly_main_enabled:
type: string
description: "The command of the nightly main Swift version linux matrix job to execute."
matrix_linux_nightly_main_command_override:
type: string
description: "The command of the nightly main Swift version linux matrix job to execute."

## We are cancelling previously triggered workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.matrix_linux_name }}
cancel-in-progress: true

jobs:
matrix-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift:
- image: swift:5.8-jammy
swift_version: "5.8"
- image: swift:5.9-jammy
swift_version: "5.9"
- image: swift:5.10-jammy
swift_version: "5.10"
- image: swiftlang/swift:nightly-6.0-jammy
swift_version: "nightly-next"
- image: swiftlang/swift:nightly-main-jammy
swift_version: "nightly-main"
name: ${{ inputs.matrix_linux_name }} (${{ matrix.swift.swift_version }})
container:
image: ${{ matrix.swift.image }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run matrix job
env:
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
run: |
if [ "$SWIFT_VERSION" == "5.8" ] && [ -n "${{ inputs.matrix_linux_5_8_command_override }}" ]; then
${{ inputs.matrix_linux_5_8_command_override }}
elfi [ "$SWIFT_VERSION" == "5.9" ] && [ -n "${{ inputs.matrix_linux_5_9_command_override }}" ]; then
${{ inputs.matrix_linux_5_9_command_override }}
elfi [ "$SWIFT_VERSION" == "5.10" ] && [ -n "${{ inputs.matrix_linux_5_10_command_override }}" ]; then
${{ inputs.matrix_linux_5_10_command_override }}
elfi [ "$SWIFT_VERSION" == "nightly-next" ] && [ -n "${{ inputs.matrix_linux_nightly_next_command_override }}" ]; then
${{ inputs.matrix_linux_nightly_next_command_override }}
elfi [ "$SWIFT_VERSION" == "nightly-main" ] && [ -n "${{ inputs.matrix_linux_nightly_main_command_override }}" ]; then
${{ inputs.matrix_linux_nightly_main_command_override }}
else
${{ inputs.matrix_linux_command }}
fi

0 comments on commit d53439c

Please sign in to comment.