Skip to content

Commit 73a77ea

Browse files
committed
Merge branch 'main' of github.com:cmcgee1024/swiftly into streamlined_init
2 parents e7ab371 + 4c5911a commit 73a77ea

File tree

5 files changed

+87
-49
lines changed

5 files changed

+87
-49
lines changed

.github/workflows/build_release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ jobs:
2323
steps:
2424
- name: Checkout repository
2525
uses: actions/checkout@v4
26-
- name: Build Artifact
26+
- name: Build Release Artifact
2727
run: swift run build-swiftly-release ${{ inputs.skip }} ${{ inputs.version }}
28-
- name: Upload Artifact
28+
- name: Upload Release Artifact
2929
uses: actions/upload-artifact@v4
3030
with:
31+
name: swiftly-release-x86_64
3132
path: .build/release/swiftly-*.tar.gz
3233
if-no-files-found: error
34+
- name: Build Documentation Artifacts
35+
run: swift package --allow-writing-to-directory .build/docs generate-documentation --target SwiftlyDocs --output-path .build/docs
36+
- name: Upload Documentation Artifacts
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: swiftly-docs
40+
path: .build/docs/**
41+
if-no-files-found: error

.github/workflows/pull_request.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
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
@@ -55,5 +56,27 @@ jobs:
5556
linux_os_versions: "[\"jammy\"]"
5657
linux_exclude_swift_versions: "[{\"swift_version\": \"nightly-main\"},{\"swift_version\": \"nightly-6.0\"},{\"swift_version\": \"5.8\"},{\"swift_version\": \"5.9\"},{\"swift_version\": \"5.10\"}]"
5758
linux_pre_build_command: ./scripts/prep-gh-action.sh
58-
linux_build_command: swift run swiftformat --lint --dryrun .
59+
linux_build_command: swift run swiftformat --lint --dryrun . || (echo "Please run 'swift run swiftformat .' to format the source code."; exit 1)
5960
enable_windows_checks: false
61+
62+
docscheck:
63+
name: Documentation Check
64+
runs-on: ubuntu-latest
65+
container:
66+
image: "swift:6.0-noble"
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
- name: Prepare the action
71+
run: ./scripts/prep-gh-action.sh && ./scripts/install-libarchive.sh
72+
- name: Generate Swiftly CLI Reference and Check for Differences
73+
run: swift package plugin --allow-writing-to-package-directory generate-docs-reference && git config --global --add safe.directory $(pwd) && git diff --exit-code Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md || (echo "The documentation hasn't been updated with the latest swiftly command-line reference. Please run 'swift package plugin generate-docs-reference' and commit/push the changes."; exit 1)
74+
- name: Generate Documentation Set
75+
run: swift package --allow-writing-to-directory .build/docs generate-documentation --target SwiftlyDocs --output-path .build/docs
76+
- name: Upload Documentation Artifacts
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: swiftly-docs
80+
path: .build/docs/**
81+
if-no-files-found: error
82+
retention-days: 1

Documentation/SwiftlyDocs.docc/getting-started.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ Uninstall this toolchain after you're finished with it:
7373
$ swiftly uninstall main-snapshot
7474
```
7575

76+
# Proxy
77+
78+
Swiftly downloads a list of toolchains from https://www.swift.org/ and retrieves them from Apple/Akamai CDN via https://download.swift.org.
79+
If your environment requires a proxy, Swiftly will attempt to use the standard environment variables `http_proxy`, `HTTP_PROXY`, `https_proxy` or `HTTPS_PROXY` to determine which proxy server to use instead of making a direct connection.
80+
81+
To download latest nightly snapshot using a proxy:
82+
```
83+
$ export https_proxy=http://proxy:3128
84+
$ swiftly install main-snapshot
85+
```
86+
7687
# See Also:
7788

7889
- [Install Toolchains](install-toolchains)

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,48 @@ public protocol HTTPRequestExecutor {
1010
}
1111

1212
/// An `HTTPRequestExecutor` backed by the shared `HTTPClient`.
13-
internal struct HTTPRequestExecutorImpl: HTTPRequestExecutor {
13+
internal class HTTPRequestExecutorImpl: HTTPRequestExecutor {
14+
let httpClient: HTTPClient
15+
16+
public init() {
17+
var proxy: HTTPClient.Configuration.Proxy?
18+
19+
func getProxyFromEnv(keys: [String]) -> HTTPClient.Configuration.Proxy? {
20+
let environment = ProcessInfo.processInfo.environment
21+
for key in keys {
22+
if let proxyString = environment[key],
23+
let url = URL(string: proxyString),
24+
let host = url.host,
25+
let port = url.port
26+
{
27+
return .server(host: host, port: port)
28+
}
29+
}
30+
return nil
31+
}
32+
33+
if let httpProxy = getProxyFromEnv(keys: ["http_proxy", "HTTP_PROXY"]) {
34+
proxy = httpProxy
35+
}
36+
if let httpsProxy = getProxyFromEnv(keys: ["https_proxy", "HTTPS_PROXY"]) {
37+
proxy = httpsProxy
38+
}
39+
40+
if proxy != nil {
41+
self.httpClient = HTTPClient(eventLoopGroupProvider: .singleton, configuration: HTTPClient.Configuration(proxy: proxy))
42+
} else {
43+
self.httpClient = HTTPClient.shared
44+
}
45+
}
46+
47+
deinit {
48+
if httpClient !== HTTPClient.shared {
49+
try? httpClient.syncShutdown()
50+
}
51+
}
52+
1453
public func execute(_ request: HTTPClientRequest, timeout: TimeAmount) async throws -> HTTPClientResponse {
15-
try await HTTPClient.shared.execute(request, timeout: timeout)
54+
try await self.httpClient.execute(request, timeout: timeout)
1655
}
1756
}
1857

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,7 @@ struct SwiftlyTestError: LocalizedError {
1717
let message: String
1818
}
1919

20-
var proxyExecutorInstalled = false
21-
22-
/// An `HTTPRequestExecutor` backed by an `HTTPClient` that can take http proxy
23-
/// information from the environment in either HTTP_PROXY or HTTPS_PROXY
24-
class ProxyHTTPRequestExecutorImpl: HTTPRequestExecutor {
25-
let httpClient: HTTPClient
26-
public init() {
27-
var proxy: HTTPClient.Configuration.Proxy?
28-
29-
let environment = ProcessInfo.processInfo.environment
30-
let httpProxy = environment["HTTP_PROXY"]
31-
if let httpProxy, let url = URL(string: httpProxy), let host = url.host, let port = url.port {
32-
proxy = .server(host: host, port: port)
33-
}
34-
35-
let httpsProxy = environment["HTTPS_PROXY"]
36-
if let httpsProxy, let url = URL(string: httpsProxy), let host = url.host, let port = url.port {
37-
proxy = .server(host: host, port: port)
38-
}
39-
40-
if proxy != nil {
41-
self.httpClient = HTTPClient(eventLoopGroupProvider: .singleton, configuration: HTTPClient.Configuration(proxy: proxy))
42-
} else {
43-
self.httpClient = HTTPClient.shared
44-
}
45-
}
46-
47-
public func execute(_ request: HTTPClientRequest, timeout: TimeAmount) async throws -> HTTPClientResponse {
48-
try await self.httpClient.execute(request, timeout: timeout)
49-
}
50-
51-
deinit {
52-
if httpClient !== HTTPClient.shared {
53-
try? httpClient.syncShutdown()
54-
}
55-
}
56-
}
57-
5820
class SwiftlyTests: XCTestCase {
59-
override class func setUp() {
60-
if !proxyExecutorInstalled {
61-
SwiftlyCore.httpRequestExecutor = ProxyHTTPRequestExecutorImpl()
62-
}
63-
}
64-
6521
override class func tearDown() {
6622
#if os(Linux)
6723
let deleteTestGPGKeys = Process()

0 commit comments

Comments
 (0)