-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information
1 parent
7b03cb2
commit f8f021f
Showing
4 changed files
with
152 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Pull Request | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
name: | ||
type: string | ||
description: "The name of the workflow used for the concurrency group." | ||
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.name }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
linux: | ||
name: ${{ matrix.swift.swift_version }} | ||
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 }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Run matrix job | ||
env: | ||
SWIFT_VERSION: ${{ matrix.swift.swift_version }} | ||
COMMAND: ${{ inputs.matrix_linux_command }} | ||
COMMAND_OVERRIDE_5_8: ${{ inputs.matrix_linux_5_8_command_override }} | ||
COMMAND_OVERRIDE_5_9: ${{ inputs.matrix_linux_5_9_command_override }} | ||
COMMAND_OVERRIDE_5_10: ${{ inputs.matrix_linux_5_10_command_override }} | ||
COMMAND_OVERRIDE_NIGHTLY_NEXT: ${{ inputs.matrix_linux_nightly_next_command_override }} | ||
COMMAND_OVERRIDE_NIGHTLY_MAIN: ${{ inputs.matrix_linux_nightly_main_command_override }} | ||
run: | | ||
apt-get -qq update && apt-get -qq -y install curl | ||
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the SwiftNIO open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
set -euo pipefail | ||
|
||
log() { printf -- "** %s\n" "$*" >&2; } | ||
error() { printf -- "** ERROR: %s\n" "$*" >&2; } | ||
fatal() { error "$@"; exit 1; } | ||
|
||
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset" | ||
test -n "${COMMAND:-}" || fatal "COMMAND unset" | ||
swift_version="$SWIFT_VERSION" | ||
command="$COMMAND" | ||
command_5_8="$COMMAND_OVERRIDE_5_8" | ||
command_5_9="$COMMAND_OVERRIDE_5_9" | ||
command_5_10="$COMMAND_OVERRIDE_5_10" | ||
command_nightly_next="$COMMAND_OVERRIDE_NIGHTLY_NEXT" | ||
command_nightly_main="$COMMAND_OVERRIDE_NIGHTLY_MAIN" | ||
|
||
if [ "$swift_version" == "5.8" ] && [ -n "$command_5_8" ]; then | ||
log "Running 5.8 command override" | ||
eval "$command_5_8" | ||
elif [ "$swift_version" == "5.9" ] && [ -n "$command_5_9" ]; then | ||
log "Running 5.9 command override" | ||
eval "$command_5_9" | ||
elif [ "$swift_version" == "5.10" ] && [ -n "$command_5_10" ]; then | ||
log "Running 5.10 command override" | ||
eval "$command_5_10" | ||
elif [ "$swift_version" == "nightly-next" ] && [ -n "$command_nightly_next" ]; then | ||
log "Running nightly next command override" | ||
eval "$command_nightly_next" | ||
elif [ "$swift_version" == "nightly-main" ] && [ -n "$command_nightly_main" ]; then | ||
log "Running nightly main command override" | ||
eval "$command_nightly_main" | ||
else | ||
log "Running default command" | ||
eval "$command" | ||
fi |