Skip to content

Commit 4759865

Browse files
committed
Test swiftly release artifacts in a plain Linux environment
Currently, there is no test coverage of a swiftly installation where there is no swift support at all, and nothing involving swiftly. Add a github workflow that performs a swiftly install using the release artifact. In order to facilitate this create an E2E test that performs these steps, but only in an environment where it can mutate the system. Also, make this test deployable to a plain Linux system with no swift support installed on it.
1 parent 0ce6cc5 commit 4759865

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

.github/workflows/pull_request.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,39 @@ jobs:
3939
- name: Checkout repository
4040
uses: actions/checkout@v4
4141
- name: Build Artifact
42-
run: swift run build-swiftly-release --skip "999.0.0"
42+
run: swift run build-swiftly-release --skip --tests "999.0.0"
4343
- name: Upload Artifact
4444
uses: actions/upload-artifact@v4
4545
with:
46+
name: swiftly-release-x86_64
4647
path: .build/release/swiftly-*.tar.gz
4748
if-no-files-found: error
4849
retention-days: 1
50+
- name: Upload Tests
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: swiftly-tests-x86_64
54+
path: .build/debug/test-swiftly.tar.gz
55+
if-no-files-found: error
56+
retention-days: 1
57+
58+
releasetest:
59+
name: Test Release
60+
needs: releasebuildcheck
61+
runs-on: ubuntu-latest
62+
container:
63+
image: "ubuntu:22.04"
64+
steps:
65+
- name: Download Release
66+
uses: actions/download-artifact@v4
67+
with:
68+
name: swiftly-release-x86_64
69+
- name: Download Tests
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: swiftly-tests-x86_64
73+
- name: Extract and Run Workflow Tests
74+
run: mv swiftly-*.tar.gz swiftly.tar.gz && tar zxf test-swiftly.tar.gz && SWIFTLY_SYSTEM_MUTATING=1 ./swiftlyPackageTests.xctest SwiftlyTests.E2ETests/testAutomatedWorkflow
4975

5076
formatcheck:
5177
name: Format Check

Tests/SwiftlyTests/E2ETests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,35 @@ final class E2ETests: SwiftlyTests {
6363
try await validateInstalledToolchains([installedToolchain], description: "install latest")
6464
}
6565
}
66+
67+
func testAutomatedWorkflow() async throws {
68+
try XCTSkipIf(ProcessInfo.processInfo.environment["SWIFTLY_SYSTEM_MUTATING"] == nil, "Not running test since it mutates the system and SWIFTLY_SYSTEM_MUTATING environment variable is not set. This test should be run in a throw away environment, such as a container.")
69+
70+
print("Extracting swiftly release")
71+
#if os(Linux)
72+
try Swiftly.currentPlatform.runProgram("tar", "-zxvf", "swiftly.tar.gz", quiet: false)
73+
#elseif os(macOS)
74+
try Swiftly.currentPlatform.runProgram("installer", "-pkg", "swiftly.pkg", "-target", "CurrentUserHomeDirectory", quiet: false)
75+
#endif
76+
77+
print("Running 'swiftly init --assume-yes --verbose' to install swiftly and the latest toolchain")
78+
79+
#if os(Linux)
80+
let extractedSwiftly = "./swiftly"
81+
#elseif os(macOS)
82+
let extractedSwiftly = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("usr/local/bin/swiftly").path
83+
#endif
84+
85+
try Swiftly.currentPlatform.runProgram(extractedSwiftly, "init", "--assume-yes", "--verbose", quiet: false)
86+
87+
let shell = try await Swiftly.currentPlatform.getShell()
88+
89+
try Swiftly.currentPlatform.runProgram(shell, "-l", "-c", "swiftly install --assume-yes latest --post-install-file=./post-install.sh")
90+
91+
if FileManager.default.fileExists(atPath: "./post-install.sh") {
92+
try Swiftly.currentPlatform.runProgram("./post-install.sh")
93+
}
94+
95+
try Swiftly.currentPlatform.runProgram(shell, "-l", "-c", "swift --version", quiet: false)
96+
}
6697
}

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public func runProgramEnv(_ args: String..., quiet: Bool = false, env: [String:
4040
}
4141

4242
public func runProgram(_ args: String..., quiet: Bool = false) throws {
43+
try runProgram(args, quiet: quiet)
44+
}
45+
46+
public func runProgram(_ args: [String], quiet: Bool = false) throws {
4347
let process = Process()
4448
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
4549
process.arguments = args
@@ -190,6 +194,9 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
190194
var identifier: String = "org.swift.swiftly"
191195
#endif
192196

197+
@Flag(help: "Produce a swiftly-test.tar.gz that has a standalone test suite to test the released bundle.")
198+
var tests: Bool = false
199+
193200
@Argument(help: "Version of swiftly to build the release.")
194201
var version: String
195202

@@ -243,14 +250,14 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
243250

244251
func checkSwiftRequirement() async throws -> String {
245252
guard !self.skip else {
246-
return try await self.assertTool("swift", message: "Please install swift and make sure that it is added to your path.")
253+
return try await self.assertTool("/usr/bin/swift", message: "Please install swift and make sure that it is added to your path.")
247254
}
248255

249256
guard let requiredSwiftVersion = try? self.findSwiftVersion() else {
250257
throw Error(message: "Unable to determine the required swift version for this version of swiftly. Please make sure that you `cd <swiftly_git_dir>` and there is a .swift-version file there.")
251258
}
252259

253-
let swift = try await self.assertTool("swift", message: "Please install swift \(requiredSwiftVersion) and make sure that it is added to your path.")
260+
let swift = try await self.assertTool("/usr/bin/swift", message: "Please install swift \(requiredSwiftVersion) and make sure that it is added to your path.")
254261

255262
// We also need a swift toolchain with the correct version
256263
guard let swiftVersion = try await runProgramOutput(swift, "--version"), swiftVersion.contains("Swift version \(requiredSwiftVersion)") else {
@@ -380,11 +387,33 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
380387
try runProgram(tar, "--directory=\(releaseDir)", "-czf", releaseArchive, "swiftly", "LICENSE.txt")
381388

382389
print(releaseArchive)
390+
391+
if self.tests {
392+
try runProgram(swift, "build", "--build-tests", "--pkg-config-path=\(pkgConfigPath)/lib/pkgconfig")
393+
394+
// Copy swift standard libraries to the build directory to bundle them with the test executable
395+
let swiftLibEnum = FileManager.default.enumerator(atPath: "/usr/lib/swift")
396+
var soFiles: [String] = []
397+
398+
while let file = swiftLibEnum?.nextObject() as? String {
399+
if file.hasSuffix(".so") {
400+
let baseName = file.split(separator: "/").last!
401+
try? FileManager.default.removeItem(atPath: cwd + "/.build/debug/" + baseName)
402+
try FileManager.default.copyItem(atPath: "/usr/lib/swift/" + file, toPath: cwd + "/.build/debug/" + baseName)
403+
soFiles.append(String(baseName))
404+
}
405+
}
406+
407+
try runProgram([tar, "--directory=\(cwd + "/.build/debug")", "-czf", "\(cwd + "/.build/debug/test-swiftly.tar.gz")", "swiftlyPackageTests.xctest"] + soFiles)
408+
409+
print(".build/debug/test-swiftly.tar.gz")
410+
}
383411
}
384412

385413
func buildMacOSRelease(cert: String?, identifier: String) async throws {
386414
// Check system requirements
387415
let git = try await self.assertTool("git", message: "Please install git with either `xcode-select --install` or `brew install git`")
416+
let tar = try await self.assertTool("tar", message: "Tar not found")
388417

389418
let swift = try await checkSwiftRequirement()
390419

@@ -439,5 +468,15 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
439468
".build/release/swiftly-\(self.version).pkg"
440469
)
441470
}
471+
472+
print(".build/release/swiftly-\(self.version).pkg")
473+
474+
if self.tests {
475+
try runProgram(swift, "build", "--build-tests")
476+
477+
try runProgram([tar, "--directory=.build/debug", "-czf", ".build/debug/test-swiftly.tar.gz", "swiftlyPackageTests.xctest"])
478+
479+
print(".build/debug/test-swiftly.tar.gz")
480+
}
442481
}
443482
}

0 commit comments

Comments
 (0)