Skip to content

Commit bf11fc9

Browse files
committed
Add a E2E test for testing swiftly installation in a custom location
1 parent 9365fa5 commit bf11fc9

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

.github/workflows/pull_request.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ jobs:
9494
- name: Extract and Run Workflow Tests
9595
run: cp swiftly-*.tar.gz /root/swiftly.tar.gz && cp test-swiftly-*.tar.gz /root && cd /root && tar zxf test-swiftly-*.tar.gz && ./test-swiftly -y ./swiftly.tar.gz
9696

97+
release-custom-install-test:
98+
name: Test Release - Custom Install Location
99+
needs: releasebuildcheck
100+
runs-on: ubuntu-latest
101+
container:
102+
image: "ubuntu:24.04"
103+
steps:
104+
- name: Prepare System
105+
run: apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install ca-certificates gpg tzdata ${{matrix.shell.pkg}} && chs
106+
h -s ${{matrix.shell.bin}}
107+
- name: Download Release
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: swiftly-release-x86_64
111+
- name: Download Tests
112+
uses: actions/download-artifact@v4
113+
with:
114+
name: swiftly-tests-x86_64
115+
- name: Extract and Run Workflow Tests
116+
run: cp swiftly-*.tar.gz /root/swiftly.tar.gz && cp test-swiftly-*.tar.gz /root && cd /root && tar zxf test-swiftly-*.tar.gz && ./test-swif
117+
tly -y --custom-location ./swiftly.tar.gz
118+
97119
formatcheck:
98120
name: Format Check
99121
runs-on: ubuntu-latest

Sources/TestSwiftly/TestSwiftly.swift

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct TestSwiftly: AsyncParsableCommand {
2121
@Flag(name: [.customShort("y"), .long], help: "Disable confirmation prompts by assuming 'yes'")
2222
var assumeYes: Bool = false
2323

24+
@Flag(help: "Install swiftly to a custom location, not added to the user profile.")
25+
var customLocation: Bool = false
26+
2427
@Argument var swiftlyArchive: String? = nil
2528

2629
mutating func run() async throws {
@@ -41,30 +44,40 @@ struct TestSwiftly: AsyncParsableCommand {
4144
try currentPlatform.runProgram("installer", "-pkg", swiftlyArchive, "-target", "CurrentUserHomeDirectory", quiet: false)
4245
#endif
4346

44-
print("Running 'swiftly init --assume-yes --verbose' to install swiftly and the latest toolchain")
45-
4647
#if os(Linux)
4748
let extractedSwiftly = "./swiftly"
4849
#elseif os(macOS)
4950
let extractedSwiftly = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".swiftly/bin/swiftly").path
5051
#endif
5152

52-
try currentPlatform.runProgram(extractedSwiftly, "init", "--assume-yes", "--skip-install", quiet: false)
53-
53+
var env = ProcessInfo.processInfo.environment
5454
let shell = try await currentPlatform.getShell()
55+
var customLoc: URL?
5556

56-
var env = ProcessInfo.processInfo.environment
57+
if self.customLocation {
58+
let customLoc = currentPlatform.getTempFilePath()
5759

58-
// Setting this environment helps to ensure that the profile gets sourced with bash, even if it is not in an interactive shell
59-
if shell.hasSuffix("bash") {
60-
env["BASH_ENV"] = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".profile").path
61-
} else if shell.hasSuffix("zsh") {
62-
env["ZDOTDIR"] = FileManager.default.homeDirectoryForCurrentUser.path
63-
} else if shell.hasSuffix("fish") {
64-
env["XDG_CONFIG_HOME"] = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config").path
65-
}
60+
print("Installing swiftly to custom location \(customLoc.path).")
61+
env["SWIFTLY_HOME_DIR"] = customLoc.path
62+
env["SWIFTLY_BIN_DIR"] = customLoc.appendingPathComponent("bin").path
63+
env["SWIFTLY_TOOLCHAIN_DIR"] = customLoc.appendingPathComponent("toolchains").path
6664

67-
try currentPlatform.runProgram(shell, "-l", "-c", "swiftly install --assume-yes latest --post-install-file=./post-install.sh", quiet: false, env: env)
65+
try currentPlatform.runProgram(extractedSwiftly, "init", "--assume-yes", "--no-modify-profile", "--skip-install", quiet: false, env: env)
66+
try currentPlatform.runProgram(shell, "-l", "-c", ". \"\(customLoc.path)/env.sh\" && swiftly install --assume-yes latest --post-install-file=./post-install.sh", quiet: false, env: env)
67+
} else {
68+
print("Installing swiftly to the default location.")
69+
// Setting this environment helps to ensure that the profile gets sourced with bash, even if it is not in an interactive shell
70+
if shell.hasSuffix("bash") {
71+
env["BASH_ENV"] = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".profile").path
72+
} else if shell.hasSuffix("zsh") {
73+
env["ZDOTDIR"] = FileManager.default.homeDirectoryForCurrentUser.path
74+
} else if shell.hasSuffix("fish") {
75+
env["XDG_CONFIG_HOME"] = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config").path
76+
}
77+
78+
try currentPlatform.runProgram(extractedSwiftly, "init", "--assume-yes", "--skip-install", quiet: false, env: env)
79+
try currentPlatform.runProgram(shell, "-l", "-c", "swiftly install --assume-yes latest --post-install-file=./post-install.sh", quiet: false, env: env)
80+
}
6881

6982
var swiftReady = false
7083

@@ -77,7 +90,9 @@ struct TestSwiftly: AsyncParsableCommand {
7790
swiftReady = true
7891
}
7992

80-
if swiftReady {
93+
if let customLoc = customLoc, swiftReady {
94+
try currentPlatform.runProgram(shell, "-l", "-c", ". \"\(customLoc.path)/env.sh\" && swift --version", quiet: false, env: env)
95+
} else if swiftReady {
8196
try currentPlatform.runProgram(shell, "-l", "-c", "swift --version", quiet: false, env: env)
8297
}
8398
}

0 commit comments

Comments
 (0)