Skip to content

Commit 38f3c36

Browse files
committed
GHA: Enable Testing on macOS and Linux
Update GitHub actions to also execute the automated tests on macOS and Linux platforms. Relates to: #9427 Issue: rdar://165491718
1 parent 19ad914 commit 38f3c36

10 files changed

Lines changed: 281 additions & 78 deletions

File tree

.github/scripts/prebuild.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
##
1212
##===----------------------------------------------------------------------===##
1313

14-
set -e
14+
set -ex
1515

1616
if [[ $(uname) == Darwin ]] ; then
1717
if [[ "$INSTALL_CMAKE" == "1" ]] ; then
@@ -43,10 +43,16 @@ elif command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy
4343
# Debug symbols
4444
apt-get install -y libc6-dbg
4545

46+
# SwiftPM requirements
47+
apt-get install -y zip unzip
48+
4649
if [[ "$INSTALL_CMAKE" == "1" ]] ; then
4750
apt-get install -y cmake ninja-build
4851
fi
4952

53+
# Install test dependencies
54+
apt-get install -y python3
55+
5056
# Android NDK
5157
dpkg_architecture="$(dpkg --print-architecture)"
5258
if [[ "$SKIP_ANDROID" != "1" ]] && [[ "$dpkg_architecture" == amd64 ]] ; then
@@ -82,4 +88,13 @@ elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2
8288
# Debug symbols
8389
yum install -y yum-utils
8490
debuginfo-install -y glibc
91+
92+
# Install test dependencies
93+
yum install --assumeyes python3
94+
95+
# SwiftPM requirements
96+
yum install -y zip unzip
8597
fi
98+
99+
env | sort
100+
uname -a

.github/workflows/pull_request.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ jobs:
1919
name: Build
2020
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.11
2121
with:
22-
enable_cross_pr_testing: true
22+
enable_cross_pr_testing: false
2323
linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]'
24+
linux_host_archs: '["x86_64", "aarch64"]'
2425
linux_swift_versions: '["nightly-main", "nightly-6.2"]'
2526
linux_pre_build_command: ./.github/scripts/prebuild.sh
2627
linux_build_command: 'swift run swift-build --build-tests'
@@ -29,11 +30,8 @@ jobs:
2930
windows_pre_build_command: 'Invoke-Program .\.github\scripts\prebuild.ps1'
3031
windows_build_command: 'Invoke-Program swift run -Xlinker /ignore:4217 --configuration release swift-build --build-tests --scratch-path .tests'
3132
enable_windows_checks: true
32-
enable_macos_checks: true
33-
macos_exclude_xcode_versions: "[{\"xcode_version\": \"16.4\"}]"
34-
macos_build_command: 'swift run swift-build --build-tests'
33+
enable_macos_checks: false
3534
enable_ios_checks: false
36-
# ios_build_command: 'swift run swift-build --build-tests --sdk \"$(xcrun --sdk iphoneos --show-sdk-path)\" --triple arm64-apple-ios'
3735

3836
soundness:
3937
name: Soundness
@@ -50,6 +48,51 @@ jobs:
5048
python_lint_check_enabled: true
5149
yamllint_check_enabled: true
5250

51+
build-and-test-posix:
52+
needs: [soundness]
53+
strategy:
54+
fail-fast: false
55+
name: "Build and Test"
56+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.11
57+
with:
58+
enable_cross_pr_testing: false
59+
enable_windows_checks: false
60+
enable_linux_checks: true
61+
# linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]'
62+
linux_host_archs: '["x86_64", "aarch64"]'
63+
linux_swift_versions: '["6.2.0"]' # '["nightly-main", "6.2.0"]'
64+
linux_pre_build_command: ./.github/scripts/prebuild.sh
65+
linux_build_command: 'swift run swift-test --parallel --experimental-xunit-message-failure --xunit-output linux-xunit.xml'
66+
enable_macos_checks: true
67+
# Need to run against macOS OSS Toolchain: https://github.com/swiftlang/github-workflows/issues/240
68+
macos_build_timeout: 120
69+
macos_xcode_versions: "[\"26.4\"]"
70+
# macos_env_vars: |
71+
# SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
72+
macos_build_command: 'swift build --product swiftpm-testing-helper && swift run swift-test --parallel --experimental-xunit-message-failure --xunit-output macos-xunit.xml'
73+
enable_ios_checks: false
74+
# ios_build_timeout: 240
75+
# ios_build_command: 'swift build --product swiftpm-testing-helper --sdk \"$(xcrun --sdk iphoneos --show-sdk-path)\" --triple arm64-apple-ios && swift run swift-test--parallel --sdk \"$(xcrun --sdk iphoneos --show-sdk-path)\" --triple arm64-apple-ios --experimental-xunit-message-failure --xunit-output ios-xunit.xml'
76+
77+
build-and-test-al2:
78+
needs: [soundness]
79+
strategy:
80+
fail-fast: false
81+
name: "Build and Test"
82+
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@0.0.11
83+
with:
84+
enable_cross_pr_testing: false
85+
# linux_publish_test_results: true
86+
enable_linux_checks: true
87+
linux_os_versions: '["amazonlinux2"]'
88+
linux_host_archs: '["x86_64", "aarch64"]'
89+
linux_swift_versions: '["6.2.0"]'
90+
linux_pre_build_command: ./.github/scripts/prebuild.sh
91+
linux_build_command: 'swift run swift-test --parallel --experimental-xunit-message-failure --xunit-output linux-xunit.xml'
92+
enable_windows_checks: false
93+
enable_macos_checks: false
94+
enable_ios_checks: false
95+
5396
integration-tests:
5497
name: Integration Tests
5598
needs: [soundness]

Sources/_InternalTestSupport/ProcessInfo+hostutils.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import Foundation
1313

1414
extension ProcessInfo {
15-
public static func isHostAmazonLinux2(_ content: String? = nil) -> Bool {
15+
package static func isHost(osName: String, _ content: String? = nil) -> Bool {
1616
let contentString: String
1717
if let content {
1818
contentString = content
@@ -24,8 +24,35 @@ extension ProcessInfo {
2424
return false
2525
}
2626
}
27-
let al2_name = "PRETTY_NAME=\"Amazon Linux 2\""
28-
return contentString.contains(al2_name)
27+
return contentString.contains(osName)
2928
}
3029

30+
public static func isHostAmazonLinux2() -> Bool {
31+
let name = "PRETTY_NAME=\"Amazon Linux 2\""
32+
return Self.isHost(osName: name)
33+
}
34+
35+
public static func isHostUbuntu20_04_bookworm() -> Bool {
36+
let name = "PRETTY_NAME=\"Ubuntu 20.04"
37+
return Self.isHost(osName: name)
38+
}
39+
40+
public static func isHostUbuntu22_04_jammy() -> Bool {
41+
let name = "PRETTY_NAME=\"Ubuntu 22.04"
42+
return Self.isHost(osName: name)
43+
}
44+
45+
public static func isHostUbuntu24_04_noble() -> Bool {
46+
let name = "PRETTY_NAME=\"Ubuntu 24.04"
47+
return Self.isHost(osName: name)
48+
}
49+
50+
public static func isHostRHEL9() -> Bool {
51+
do {
52+
let name = "PRETTY_NAME=\"Red Hat Enterprise Linux 9"
53+
return Self.isHost(osName: name)
54+
} catch {
55+
return false
56+
}
57+
}
3158
}

Sources/_InternalTestSupport/XCTAssertHelpers.swift

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,50 @@ public func XCTSkipOnWindows(because reason: String? = nil, skipPlatformCi: Bool
9797
#endif
9898
}
9999

100-
public func _requiresTools(_ executable: String) throws {
100+
public func XCTSkipOnAmazonLinux2(because reason: String, file: StaticString = #filePath, line: UInt = #line) throws {
101+
swiftTestingTestCalledAnXCTestAPI()
102+
try XCTSkipIf(
103+
ProcessInfo.isHostAmazonLinux2(),
104+
"Skiping test: \(reason)",
105+
file: file,
106+
line: line,
107+
)
108+
}
109+
110+
public func XCTSkipOnUbuntu20_04_bookworm(because reason: String, file: StaticString = #filePath, line: UInt = #line) throws {
111+
swiftTestingTestCalledAnXCTestAPI()
112+
try XCTSkipIf(
113+
ProcessInfo.isHostUbuntu20_04_bookworm(),
114+
"Skiping test: \(reason)",
115+
file: file,
116+
line: line,
117+
)
118+
}
119+
120+
public func XCTSkipOnUbuntu22_04_jammy(because reason: String, file: StaticString = #filePath, line: UInt = #line) throws {
121+
swiftTestingTestCalledAnXCTestAPI()
122+
try XCTSkipIf(
123+
ProcessInfo.isHostUbuntu22_04_jammy(),
124+
"Skiping test: \(reason)",
125+
file: file,
126+
line: line,
127+
)
128+
}
129+
130+
public func _requiresTools(
131+
_ executable: String,
132+
fs: FileSystem = localFileSystem,
133+
) throws {
101134
func getAsyncProcessArgs(_ executable: String) -> [String] {
102135
#if os(Windows)
103136
let args = ["cmd.exe", "/c", "where.exe", executable]
104137
#else
105-
let args = ["which", executable]
138+
let command = if fs.exists("/usr/bin/which") {
139+
"/usr/bin/which"
140+
} else {
141+
"/usr/bin/whereis"
142+
}
143+
let args = [command, executable]
106144
#endif
107145
return args
108146
}

Tests/BasicsTests/AsyncProcessTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ final class AsyncProcessTests: XCTestCase {
493493
func testAsyncStreamHighLevelAPI() async throws {
494494
// rdar://133548796
495495
try XCTSkipIfPlatformCI()
496+
try XCTSkipOnAmazonLinux2(because: "Test process crashes")
496497
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was stalled.")
497498

498499
let result = try await AsyncProcess.popen(

Tests/BasicsTests/ProcessInfoTests.swift

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,54 @@ fileprivate struct Content {
4646
struct ProcessInfoExtensionTests {
4747

4848
@Suite
49-
struct isAmazonLinux2 {
49+
struct isHost {
5050
@Test(
5151
arguments: [
52-
(contentUT: "", expected: false),
53-
(contentUT: "PRETTY_NAME=", expected: false),
54-
(contentUT: "PRETTY_NAME=foo", expected: false),
55-
(contentUT: "PRETTY_NAME=amzn", expected: false),
56-
(contentUT: "PRETTY_NAME=Amazon Linux 2", expected: false),
57-
(contentUT: "PRETTY_NAME=Amazon Linux 2023.6.20250107", expected: false),
58-
(contentUT: " PRETTY_NAME=amzn", expected: false),
59-
(contentUT: "PRETTY_NAME=\"Amazon Linux 2\"", expected: true),
60-
(contentUT: "PRETTY_NAME=\"Amazon Linux 2 (something else)\"", expected: false),
52+
(
53+
contentUT: "",
54+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
55+
expected: false,
56+
),
57+
(
58+
contentUT: "PRETTY_NAME=",
59+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
60+
expected: false,
61+
),
62+
(
63+
contentUT: "PRETTY_NAME=foo",
64+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
65+
expected: false,
66+
),
67+
(
68+
contentUT: "PRETTY_NAME=amzn",
69+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
70+
expected: false,
71+
),
72+
(
73+
contentUT: "PRETTY_NAME=Amazon Linux 2",
74+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
75+
expected: false,
76+
),
77+
(
78+
contentUT: "PRETTY_NAME=Amazon Linux 2023.6.20250107",
79+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
80+
expected: false,
81+
),
82+
(
83+
contentUT: " PRETTY_NAME=amzn",
84+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
85+
expected: false,
86+
),
87+
(
88+
contentUT: "PRETTY_NAME=\"Amazon Linux 2\"",
89+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
90+
expected: true,
91+
),
92+
(
93+
contentUT: "PRETTY_NAME=\"Amazon Linux 2 (something else)\"",
94+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
95+
expected: false,
96+
),
6197
(
6298
contentUT: """
6399
NAME="Amazon Linux"
@@ -71,6 +107,7 @@ struct ProcessInfoExtensionTests {
71107
HOME_URL="https://amazonlinux.com/"
72108
SUPPORT_END="2026-06-30"
73109
""",
110+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
74111
expected: true
75112
),
76113
(
@@ -86,6 +123,7 @@ struct ProcessInfoExtensionTests {
86123
HOME_URL="https://amazonlinux.com/"
87124
SUPPORT_END="2026-06-30"
88125
""",
126+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
89127
expected: false
90128
),
91129
(
@@ -101,6 +139,7 @@ struct ProcessInfoExtensionTests {
101139
HOME_URL="https://amazonlinux.com/"
102140
SUPPORT_END="2026-06-30"
103141
""",
142+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
104143
expected: false
105144
),
106145
(
@@ -116,6 +155,7 @@ struct ProcessInfoExtensionTests {
116155
HOME_URL="https://amazonlinux.com/"
117156
SUPPORT_END="2026-06-30"
118157
""",
158+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
119159
expected: false
120160
),
121161
(
@@ -137,30 +177,33 @@ struct ProcessInfoExtensionTests {
137177
VENDOR_URL="https://aws.amazon.com/"
138178
SUPPORT_END="2028-03-15"
139179
""",
180+
hostToMatch: "PRETTY_NAME=\"Amazon Linux 2\"",
140181
expected: false,
141182
)
142183
], prefixAndSuffixData,
143184
)
144185
fileprivate func isAmazonLinux2ReturnsExpectedValue(
145-
data: (contentUT: String, expected: Bool),
186+
data: (contentUT: String, hostToMatch: String, expected: Bool),
146187
content: Content,
147188
) async throws {
148189
let content = content.getContent(data.contentUT)
149190

150-
let actual = ProcessInfo.isHostAmazonLinux2(content)
191+
let actual = ProcessInfo.isHost(osName: data.hostToMatch, content)
151192

152193
#expect(actual == data.expected, "Content is: '\(content)'")
153194
}
154195

155196
@Test(
156-
"isHostAmazonLinux2 returns false when not executed on Linux",
197+
"isHost* returns false when not executed on Linux",
157198
.skipHostOS(.linux),
158199
.tags(Tag.TestSize.medium),
159200
)
160-
func isAmazonLinux2ReturnsFalseWhenNotRunOnLinux() {
161-
let actual = ProcessInfo.isHostAmazonLinux2()
201+
func concreteIsHostReturnsFalseWhenNotRunOnLinux() {
202+
let actualAL2 = ProcessInfo.isHostAmazonLinux2()
203+
#expect(actualAL2 == false)
162204

163-
#expect(actual == false)
205+
let actualRHEL9 = ProcessInfo.isHostRHEL9()
206+
#expect(actualRHEL9 == false)
164207
}
165208
}
166-
}
209+
}

0 commit comments

Comments
 (0)