Skip to content

Commit 0cc4642

Browse files
authored
Convert workflows to self-hosted with Swiftly (#195)
Test with self-hosted swiftly. Prepare the docker image before trying to install swiftly. Correct the swiftly install option. Update the GitHub prep script to work with/without swiftly. Use swiftly to run the install libarchive script for the C compiler. Move proxy circularity check out of swiftly run and into the proxy. Pre-install git so that the checkout clones the repo instead of using REST to fetch it. Remove unnecessary packages for C++ compilation.
1 parent 51496e5 commit 0cc4642

File tree

6 files changed

+109
-37
lines changed

6 files changed

+109
-37
lines changed

.github/workflows/build_release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ on:
1414
type: string
1515
default: "--skip"
1616

17+
env:
18+
SWIFTLY_BOOTSTRAP_VERSION: 0.4.0-dev
19+
1720
jobs:
1821
buildrelease:
1922
name: Build Release
2023
runs-on: ubuntu-latest
2124
container:
22-
image: "swift:6.0-rhel-ubi9"
25+
image: "redhat/ubi9"
2326
steps:
2427
- name: Checkout repository
2528
uses: actions/checkout@v4
29+
- name: Prepare the action
30+
run: ./scripts/prep-gh-action.sh --install-swiftly
2631
- name: Build Release Artifact
2732
run: swift run build-swiftly-release --use-rhel-ubi9 ${{ inputs.skip }} ${{ inputs.version }}
2833
- name: Upload Release Artifact

.github/workflows/pull_request.yml

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
push:
77
branches: [main]
88

9+
env:
10+
SWIFTLY_BOOTSTRAP_VERSION: 0.4.0-dev
11+
912
jobs:
1013
soundness:
1114
name: Soundness
@@ -19,24 +22,33 @@ jobs:
1922
shell_check_enabled: false
2023
unacceptable_language_check_enabled: true
2124

22-
tests:
23-
name: Test
24-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
25-
with:
26-
linux_os_versions: "[\"jammy\", \"focal\", \"rhel-ubi9\", \"noble\", \"bookworm\", \"fedora39\"]"
27-
# We only care about the current stable release, because that's where we make our swiftly releases
28-
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\"}]"
29-
linux_pre_build_command: ./scripts/prep-gh-action.sh && ./scripts/install-libarchive.sh
30-
enable_windows_checks: false
25+
tests-selfhosted:
26+
name: Test (Self Hosted) / ${{ matrix.container }}
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12", "fedora:39"]
32+
container:
33+
image: ${{ matrix.container }}
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
- name: Prepare the action
38+
run: ./scripts/prep-gh-action.sh --install-swiftly
39+
- name: Build and Test
40+
run: swift test
3141

3242
releasebuildcheck:
3343
name: Release Build Check
3444
runs-on: ubuntu-latest
3545
container:
36-
image: "swift:6.0-rhel-ubi9"
46+
image: "redhat/ubi9"
3747
steps:
3848
- name: Checkout repository
3949
uses: actions/checkout@v4
50+
- name: Prepare the action
51+
run: ./scripts/prep-gh-action.sh --install-swiftly
4052
- name: Build Artifact
4153
run: swift run build-swiftly-release --use-rhel-ubi9 --skip "999.0.0"
4254
- name: Upload Artifact
@@ -49,27 +61,31 @@ jobs:
4961

5062
formatcheck:
5163
name: Format Check
52-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
53-
with:
54-
# We only need to run this with one swift release and on one of the linux distributions
55-
linux_os_versions: "[\"jammy\"]"
56-
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\"}]"
57-
linux_pre_build_command: ./scripts/prep-gh-action.sh
58-
linux_build_command: swift run swiftformat --lint --dryrun . || (echo "Please run 'swift run swiftformat .' to format the source code."; exit 1)
59-
enable_windows_checks: false
64+
runs-on: ubuntu-latest
65+
container:
66+
image: ubuntu:22.04
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
- name: Prepare the action
71+
run: ./scripts/prep-gh-action.sh --install-swiftly
72+
- name: Check format
73+
run: swift run swiftformat --lint --dryrun . || (echo "Please run 'swift run swiftformat .' to format the source code."; exit 1)
6074

6175
docscheck:
6276
name: Documentation Check
6377
runs-on: ubuntu-latest
6478
container:
65-
image: "swift:6.0-noble"
79+
image: ubuntu:24.04
6680
steps:
81+
- name: Install git
82+
run: apt-get update && apt-get -y install git
6783
- name: Checkout repository
6884
uses: actions/checkout@v4
6985
- name: Prepare the action
70-
run: ./scripts/prep-gh-action.sh && ./scripts/install-libarchive.sh
86+
run: ./scripts/prep-gh-action.sh --install-swiftly
7187
- name: Generate Swiftly CLI Reference and Check for Differences
72-
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)
88+
run: swift package plugin --allow-writing-to-package-directory generate-docs-reference && bash -c '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)
7389
- name: Generate Documentation Set
7490
run: swift package --allow-writing-to-directory .build/docs generate-documentation --target SwiftlyDocs --output-path .build/docs
7591
- name: Upload Documentation Artifacts

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.0
1+
6.0.3

Sources/Swiftly/Proxy.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ public enum Proxy {
5656
throw SwiftlyError(message: "No swift toolchain could be selected from either from a .swift-version file, or the default. You can try using `swiftly install <toolchain version>` to install one.")
5757
}
5858

59-
try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]))
59+
// Prevent circularities with a memento environment variable
60+
guard ProcessInfo.processInfo.environment["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
61+
throw SwiftlyError(message: "Circular swiftly proxy invocation")
62+
}
63+
let env = ["SWIFTLY_PROXY_IN_PROGRESS": "1"]
64+
65+
try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]), env)
6066
} catch let terminated as RunProgramError {
6167
exit(terminated.exitCode)
6268
} catch let error as SwiftlyError {

Sources/SwiftlyCore/Platform.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ extension Platform {
143143
let tcPath = self.findToolchainLocation(toolchain).appendingPathComponent("usr/bin")
144144
var newEnv = ProcessInfo.processInfo.environment
145145

146-
// Prevent circularities with a memento environment variable
147-
guard newEnv["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
148-
throw SwiftlyError(message: "Circular swiftly proxy invocation")
149-
}
150-
newEnv["SWIFTLY_PROXY_IN_PROGRESS"] = "1"
151-
152146
// The toolchain goes to the beginning of the PATH
153147
var newPath = newEnv["PATH"] ?? ""
154148
if !newPath.hasPrefix(tcPath.path + ":") {
@@ -164,8 +158,12 @@ extension Platform {
164158
/// In the case where the command exit with a non-zero exit code a RunProgramError is thrown with
165159
/// the exit code and program information.
166160
///
167-
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String]) async throws {
168-
try self.runProgram([command] + arguments, env: self.proxyEnv(toolchain))
161+
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String], _ env: [String: String] = [:]) async throws {
162+
var newEnv = try self.proxyEnv(toolchain)
163+
for (key, value) in env {
164+
newEnv[key] = value
165+
}
166+
try self.runProgram([command] + arguments, env: newEnv)
169167
}
170168

171169
/// Proxy the invocation of the provided command to the chosen toolchain and capture the output.

scripts/prep-gh-action.sh

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
11
#!/bin/bash
22

3-
apt-get --help && apt-get update && apt-get -y install curl make
4-
yum --help && (curl --help && yum -y install curl) && yum install make
3+
# This script does a bit of extra preparation of the docker containers used to run the GitHub workflows
4+
# that are specific to this project's needs when building/testing. Note that this script runs on
5+
# every supported Linux distribution so it must adapt to the distribution that it is running.
56

6-
(cat /etc/os-release | grep bookworm) && apt-get -y install libstdc++-12-dev gnupg2
7-
(cat /etc/os-release | grep 'Fedora Linux 39') && yum -y install libstdc++-devel libstdc++-static
7+
# Install the basic utilities depending on the type of Linux distribution
8+
apt-get --help && apt-get update && TZ=Etc/UTC apt-get -y install curl make gpg tzdata
9+
yum --help && (curl --help && yum -y install curl) && yum install make gpg
810

9-
exit 0
11+
set -e
12+
13+
while [ $# -ne 0 ]; do
14+
arg="$1"
15+
case "$arg" in
16+
--install-swiftly)
17+
installSwiftly=true
18+
;;
19+
*)
20+
;;
21+
esac
22+
shift
23+
done
24+
25+
if [ "$installSwiftly" == true ]; then
26+
echo "Installing swiftly"
27+
curl -O https://download.swift.org/swiftly/linux/swiftly-${SWIFTLY_BOOTSTRAP_VERSION}-$(uname -m).tar.gz && tar zxf swiftly-*.tar.gz && ./swiftly init -y --skip-install
28+
29+
. "/root/.local/share/swiftly/env.sh"
30+
hash -r
31+
32+
if [ -n "$GITHUB_ENV" ]; then
33+
echo "Updating GitHub environment"
34+
echo "PATH=$PATH" >> "$GITHUB_ENV" && echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV"
35+
fi
36+
37+
if [ -f .swift-version ]; then
38+
echo "Installing selected swift toolchain"
39+
swiftly install --post-install-file=post-install.sh
40+
else
41+
echo "Installing latest toolchain"
42+
swiftly install --post-install-file=post-install.sh latest
43+
fi
44+
45+
if [ -f post-install.sh ]; then
46+
echo "Performing swift toolchain post-installation"
47+
chmod u+x post-install.sh && ./post-install.sh
48+
fi
49+
50+
echo "Displaying swift version"
51+
swift --version
52+
53+
CC=clang swiftly run "$(dirname "$0")/install-libarchive.sh"
54+
else
55+
"$(dirname "$0")/install-libarchive.sh"
56+
fi

0 commit comments

Comments
 (0)