Skip to content

Commit 9886f3c

Browse files
committed
[GHA] Introduce reusable matrix workflow
# 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.
1 parent 7b03cb2 commit 9886f3c

File tree

4 files changed

+150
-71
lines changed

4 files changed

+150
-71
lines changed

.github/workflows/pull_request.yml

+18-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@ on:
55
types: [opened, reopened, synchronize, ready_for_review]
66

77
jobs:
8-
call-reusable-pull-request-workflow:
9-
name: Checks
10-
uses: ./.github/workflows/reusable_pull_request.yml
8+
call-pull-request-soundness-workflow:
9+
name: Soundness
10+
uses: ./.github/workflows/pull_request_soundness.yml
1111
with:
12-
benchmarks_linux_package_path: "Benchmarks"
1312
license_header_check_project_name: "SwiftNIO"
1413
format_check_enabled: false
14+
15+
call-pull-request-unit-tests-workflow:
16+
name: Unit tests
17+
uses: ./.github/workflows/pull_request_swift_matrix.yml
18+
with:
19+
matrix_linux_name: "Unit tests"
20+
matrix_linux_command: "swift test -Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
21+
22+
call-pull-request-benchmark-workflow:
23+
name: Benchmarks
24+
uses: ./.github/workflows/pull_request_swift_matrix.yml
25+
with:
26+
matrix_linux_name: "Benchmarks"
27+
matrix_linux_command: "apt-get update -y -q && apt-get install -y -q libjemalloc-dev && swift package --package-path /Benchmarks --disable-sandbox benchmark baseline check --check-absolute-path Benchmarks/Thresholds/${SWIFT_VERSION}/
28+
"

.github/workflows/reusable_pull_request.yml renamed to .github/workflows/pull_request_soundness.yml

+1-67
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ name: Pull Request
33
on:
44
workflow_call:
55
inputs:
6-
unit_tests_linux_enabled:
7-
type: boolean
8-
description: "Boolean to enable the unit tests linux job. Defaults to true."
9-
default: true
10-
benchmarks_linux_enabled:
11-
type: boolean
12-
description: "Boolean to enable the benchmarks linux job. Defaults to true."
13-
default: true
14-
benchmarks_linux_package_path:
15-
type: string
16-
description: "Path to the package containing the benchmarks. Defaults to the repository root."
17-
default: "."
186
api_breakage_check_enabled:
197
type: boolean
208
description: "Boolean to enable the API breakage check job. Defaults to true."
@@ -50,64 +38,10 @@ on:
5038

5139
## We are cancelling previously triggered workflow runs
5240
concurrency:
53-
group: ${{ github.workflow }}-${{ github.ref }}
41+
group: ${{ github.workflow }}-${{ github.ref }}-soudness
5442
cancel-in-progress: true
5543

5644
jobs:
57-
unit-tests-linux:
58-
name: Unit tests
59-
if: ${{ inputs.unit_tests_linux_enabled }}
60-
runs-on: ubuntu-latest
61-
strategy:
62-
fail-fast: false
63-
matrix:
64-
swift:
65-
- image: swift:5.8-jammy
66-
- image: swift:5.9-jammy
67-
- image: swift:5.10-jammy
68-
- image: swiftlang/swift:nightly-6.0-jammy
69-
- image: swiftlang/swift:nightly-main-jammy
70-
container:
71-
image: ${{ matrix.swift.image }}
72-
timeout-minutes: 20
73-
steps:
74-
- name: Checkout repository
75-
uses: actions/checkout@v4
76-
- name: Run tests
77-
run: swift test
78-
79-
benchmarks-linux:
80-
name: Benchmarks
81-
if: ${{ inputs.benchmarks_linux_enabled }}
82-
runs-on: ubuntu-latest
83-
strategy:
84-
fail-fast: false
85-
matrix:
86-
swift:
87-
- image: swift:5.8-jammy
88-
swift_version: "5.8"
89-
- image: swift:5.9-jammy
90-
swift_version: "5.9"
91-
- image: swift:5.10-jammy
92-
swift_version: "5.10"
93-
- image: swiftlang/swift:nightly-6.0-jammy
94-
swift_version: "nightly-next"
95-
- image: swiftlang/swift:nightly-main-jammy
96-
swift_version: "nightly-main"
97-
container:
98-
image: ${{ matrix.swift.image }}
99-
timeout-minutes: 20
100-
steps:
101-
- name: Checkout repository
102-
uses: actions/checkout@v4
103-
- name: Run tests
104-
env:
105-
PACKAGE_PATH: ${{ inputs.benchmarks_linux_package_path }}
106-
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
107-
run: |
108-
apt-get update -y -q && apt-get install -y -q libjemalloc-dev
109-
swift package --package-path ${PACKAGE_PATH} --disable-sandbox benchmark baseline check --check-absolute-path ${PACKAGE_PATH}/Thresholds/${SWIFT_VERSION}/
110-
11145
api-breakage-check:
11246
name: API breakage check
11347
if: ${{ inputs.api_breakage_check_enabled }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Pull Request
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
name:
7+
type: string
8+
description: "The name of the workflow used for the concurrency group."
9+
required: true
10+
matrix_linux_command:
11+
type: string
12+
description: "The command of the current Swift version linux matrix job to execute."
13+
required: true
14+
matrix_linux_5_8_enabled:
15+
type: string
16+
description: "The command of the 5.8 Swift version linux matrix job to execute."
17+
matrix_linux_5_8_command_override:
18+
type: string
19+
description: "The command of the 5.8 Swift version linux matrix job to execute."
20+
matrix_linux_5_9_enabled:
21+
type: string
22+
description: "The command of the 5.9 Swift version linux matrix job to execute."
23+
matrix_linux_5_9_command_override:
24+
type: string
25+
description: "The command of the 5.9 Swift version linux matrix job to execute."
26+
matrix_linux_5_10_enabled:
27+
type: string
28+
description: "The command of the 5.10 Swift version linux matrix job to execute."
29+
matrix_linux_5_10_command_override:
30+
type: string
31+
description: "The command of the 5.10 Swift version linux matrix job to execute."
32+
matrix_linux_nightly_next_enabled:
33+
type: string
34+
description: "The command of the nightly next Swift version linux matrix job to execute."
35+
matrix_linux_nightly_next_command_override:
36+
type: string
37+
description: "The command of the nightly next Swift version linux matrix job to execute."
38+
matrix_linux_nightly_main_enabled:
39+
type: string
40+
description: "The command of the nightly main Swift version linux matrix job to execute."
41+
matrix_linux_nightly_main_command_override:
42+
type: string
43+
description: "The command of the nightly main Swift version linux matrix job to execute."
44+
45+
## We are cancelling previously triggered workflow runs
46+
concurrency:
47+
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
48+
cancel-in-progress: true
49+
50+
jobs:
51+
linux:
52+
name: ${{ matrix.swift.swift_version }}
53+
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
swift:
58+
- image: swift:5.8-jammy
59+
swift_version: "5.8"
60+
- image: swift:5.9-jammy
61+
swift_version: "5.9"
62+
- image: swift:5.10-jammy
63+
swift_version: "5.10"
64+
- image: swiftlang/swift:nightly-6.0-jammy
65+
swift_version: "nightly-next"
66+
- image: swiftlang/swift:nightly-main-jammy
67+
swift_version: "nightly-main"
68+
container:
69+
image: ${{ matrix.swift.image }}
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v4
73+
- name: Run matrix job
74+
env:
75+
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
76+
COMMAND: ${{ inputs.matrix_linux_command }}
77+
COMMAND_OVERRIDE_5_8: ${{ inputs.matrix_linux_5_8_command_override }}
78+
COMMAND_OVERRIDE_5_9: ${{ inputs.matrix_linux_5_9_command_override }}
79+
COMMAND_OVERRIDE_5_10: ${{ inputs.matrix_linux_5_10_command_override }}
80+
COMMAND_OVERRIDE_NIGHTLY_NEXT: ${{ inputs.matrix_linux_nightly_next_command_override }}
81+
COMMAND_OVERRIDE_NIGHTLY_MAIN: ${{ inputs.matrix_linux_nightly_main_command_override }}
82+
run: ./scripts/check-matrix-step.sh

scripts/check-matrix-step.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftNIO open source project
5+
##
6+
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
set -euo pipefail
16+
17+
log() { printf -- "** %s\n" "$*" >&2; }
18+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
19+
fatal() { error "$@"; exit 1; }
20+
21+
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset"
22+
test -n "${COMMAND:-}" || fatal "COMMAND unset"
23+
swift_version="$SWIFT_VERSION"
24+
command="$COMMAND"
25+
command_5_8="$COMMAND_OVERRIDE_5_8"
26+
command_5_9="$COMMAND_OVERRIDE_5_9"
27+
command_5_10="$COMMAND_OVERRIDE_5_10"
28+
command_nightly_next="$COMMAND_OVERRIDE_NIGHTLY_NEXT"
29+
command_nightly_main="$COMMAND_OVERRIDE_NIGHTLY_MAIN"
30+
31+
if [ "$swift_version" == "5.8" ] && [ -n "$command_5_8" ]; then
32+
log "Running 5.8 command override"
33+
eval "$command_5_8"
34+
elif [ "$swift_version" == "5.9" ] && [ -n "$command_5_9" ]; then
35+
log "Running 5.9 command override"
36+
eval "$command_5_9"
37+
elif [ "$swift_version" == "5.10" ] && [ -n "$command_5_10" ]; then
38+
log "Running 5.10 command override"
39+
eval "$command_5_10"
40+
elif [ "$swift_version" == "nightly-next" ] && [ -n "$command_nightly_next" ]; then
41+
log "Running nightly next command override"
42+
eval "$command_nightly_next"
43+
elif [ "$swift_version" == "nightly-main" ] && [ -n "$command_nightly_main" ]; then
44+
log "Running nightly main command override"
45+
eval "$command_nightly_main"
46+
else
47+
log "Running default command"
48+
eval "$command"
49+
fi

0 commit comments

Comments
 (0)