Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert workflows to self-hosted with Swiftly #195

Merged
merged 48 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7b0c5e1
Test with self-hosted swiftly
cmcgee1024 Dec 24, 2024
4c98101
Prepare the docker image before trying to install swiftly
cmcgee1024 Dec 24, 2024
8eef5a1
Hard code the architecture
cmcgee1024 Dec 24, 2024
13116b8
Correct the swiftly install option
cmcgee1024 Dec 24, 2024
19b6983
Add gpg to the action prep script
cmcgee1024 Dec 24, 2024
1aaf5a8
Remove Ubuntu 20.04
cmcgee1024 Dec 24, 2024
1e48edd
chmod the post install script
cmcgee1024 Dec 24, 2024
393d842
Pre-configure tzdata package
cmcgee1024 Dec 24, 2024
e12bf8d
Use swiftly to run the install libarchive script for the C compiler
cmcgee1024 Dec 24, 2024
4fb93e1
Correct swiftly path
cmcgee1024 Dec 24, 2024
9771ba3
Correct swiftly path
cmcgee1024 Dec 24, 2024
8fc1a86
Correct path to swift
cmcgee1024 Dec 24, 2024
29ae892
Disable fail fast, and run tests outside of proxy
cmcgee1024 Dec 24, 2024
13323a9
Move proxy circularity check out of swiftly run
cmcgee1024 Dec 24, 2024
4c77cc6
Reduce tests to just jammy, and rely on swiftly being added to the path
cmcgee1024 Dec 24, 2024
c558f76
Move swiftly to be a system binary to be on the path
cmcgee1024 Dec 24, 2024
342de12
Try and get swiftly into the shell environment
cmcgee1024 Dec 24, 2024
2ce77ac
Add assume-yes to the swiftly init and use swiftly run to set PATH
cmcgee1024 Dec 24, 2024
b03507a
Update the path for subsequent worklow steps
cmcgee1024 Dec 24, 2024
d3e1329
Another attempt at updating the path for subsequent steps
cmcgee1024 Dec 24, 2024
fb1d088
Add more detailed environment info
cmcgee1024 Dec 24, 2024
03845ef
Show environment file
cmcgee1024 Dec 24, 2024
d881d83
Display the shell that is in use
cmcgee1024 Dec 24, 2024
fb75fdb
Force bash shell when updating the environment
cmcgee1024 Dec 24, 2024
a659f48
Remove extra echo statements and update all swiftly environment varia…
cmcgee1024 Dec 24, 2024
38b5a40
Extract swiftly bootstrap version and arch out of the job steps
cmcgee1024 Dec 24, 2024
e76ad1d
Missing quote
cmcgee1024 Dec 24, 2024
5c7be85
Convert jobs to bootstrap with swiftly
cmcgee1024 Dec 24, 2024
40d2eef
Install libarchive before documentation check
cmcgee1024 Dec 24, 2024
b4431a8
Update documentation check to a newer ubuntu
cmcgee1024 Dec 24, 2024
02ef1a8
Fix cli reference check
cmcgee1024 Dec 24, 2024
1a04f8a
Fix quoting problem
cmcgee1024 Dec 24, 2024
129055d
Capture more details
cmcgee1024 Dec 24, 2024
b65571f
Capture more details
cmcgee1024 Dec 24, 2024
5d6764d
Capture more details
cmcgee1024 Dec 25, 2024
f9d0594
Pre-install git so that the checkout clones the repo instead of using…
cmcgee1024 Dec 25, 2024
765e280
Re-add the exit code option to the git diff
cmcgee1024 Dec 25, 2024
335a25a
Consolidate the swiftly and libarchive install into the prep script
cmcgee1024 Dec 25, 2024
443619c
Fix quotes
cmcgee1024 Dec 25, 2024
154ef74
Skip attempt to run post install script if it does not exist
cmcgee1024 Dec 25, 2024
a46fc4e
Fix test job names
cmcgee1024 Dec 25, 2024
3f2172d
Add more checks the github prep script
cmcgee1024 Dec 25, 2024
d9391f0
Fix test coverage for Ubuntu 20.04
cmcgee1024 Dec 26, 2024
25ff40d
Move Ubuntu 20.04 to self-hosted
cmcgee1024 Jan 10, 2025
8c1cd93
Remove unnecessary packages for C++ compilation
cmcgee1024 Jan 16, 2025
2f46918
Merge branch 'main' of github.com:cmcgee1024/swiftly into self-host-g…
cmcgee1024 Jan 16, 2025
9a1a3f5
Merge branch 'main' of github.com:cmcgee1024/swiftly into self-host-g…
cmcgee1024 Jan 27, 2025
b40a5c2
Correct the error type
cmcgee1024 Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ on:
type: string
default: "--skip"

env:
SWIFTLY_BOOTSTRAP_VERSION: 0.4.0-dev

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans to convert this to 0.4.0 proper?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once we have a final 0.4.0 release we can update this env and use it.


jobs:
buildrelease:
name: Build Release
runs-on: ubuntu-latest
container:
image: "swift:6.0-rhel-ubi9"
image: "redhat/ubi9"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly
- name: Build Release Artifact
run: swift run build-swiftly-release --use-rhel-ubi9 ${{ inputs.skip }} ${{ inputs.version }}
- name: Upload Release Artifact
Expand Down
58 changes: 37 additions & 21 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
push:
branches: [main]

env:
SWIFTLY_BOOTSTRAP_VERSION: 0.4.0-dev

jobs:
soundness:
name: Soundness
Expand All @@ -19,24 +22,33 @@ jobs:
shell_check_enabled: false
unacceptable_language_check_enabled: true

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

releasebuildcheck:
name: Release Build Check
runs-on: ubuntu-latest
container:
image: "swift:6.0-rhel-ubi9"
image: "redhat/ubi9"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly
- name: Build Artifact
run: swift run build-swiftly-release --use-rhel-ubi9 --skip "999.0.0"
- name: Upload Artifact
Expand All @@ -49,27 +61,31 @@ jobs:

formatcheck:
name: Format Check
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
# We only need to run this with one swift release and on one of the linux distributions
linux_os_versions: "[\"jammy\"]"
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\"}]"
linux_pre_build_command: ./scripts/prep-gh-action.sh
linux_build_command: swift run swiftformat --lint --dryrun . || (echo "Please run 'swift run swiftformat .' to format the source code."; exit 1)
enable_windows_checks: false
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly
- name: Check format
run: swift run swiftformat --lint --dryrun . || (echo "Please run 'swift run swiftformat .' to format the source code."; exit 1)

docscheck:
name: Documentation Check
runs-on: ubuntu-latest
container:
image: "swift:6.0-noble"
image: ubuntu:24.04
steps:
- name: Install git
run: apt-get update && apt-get -y install git
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare the action
run: ./scripts/prep-gh-action.sh && ./scripts/install-libarchive.sh
run: ./scripts/prep-gh-action.sh --install-swiftly
- name: Generate Swiftly CLI Reference and Check for Differences
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)
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)
- name: Generate Documentation Set
run: swift package --allow-writing-to-directory .build/docs generate-documentation --target SwiftlyDocs --output-path .build/docs
- name: Upload Documentation Artifacts
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0
6.0.3
8 changes: 7 additions & 1 deletion Sources/Swiftly/Proxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public enum Proxy {
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.")
}

try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]))
// Prevent circularities with a memento environment variable
guard ProcessInfo.processInfo.environment["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
throw SwiftlyError(message: "Circular swiftly proxy invocation")
}
let env = ["SWIFTLY_PROXY_IN_PROGRESS": "1"]

try await Swiftly.currentPlatform.proxy(toolchain, binName, Array(CommandLine.arguments[1...]), env)
} catch let terminated as RunProgramError {
exit(terminated.exitCode)
} catch let error as SwiftlyError {
Expand Down
14 changes: 6 additions & 8 deletions Sources/SwiftlyCore/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ extension Platform {
let tcPath = self.findToolchainLocation(toolchain).appendingPathComponent("usr/bin")
var newEnv = ProcessInfo.processInfo.environment

// Prevent circularities with a memento environment variable
guard newEnv["SWIFTLY_PROXY_IN_PROGRESS"] == nil else {
throw SwiftlyError(message: "Circular swiftly proxy invocation")
}
newEnv["SWIFTLY_PROXY_IN_PROGRESS"] = "1"

// The toolchain goes to the beginning of the PATH
var newPath = newEnv["PATH"] ?? ""
if !newPath.hasPrefix(tcPath.path + ":") {
Expand All @@ -164,8 +158,12 @@ extension Platform {
/// In the case where the command exit with a non-zero exit code a RunProgramError is thrown with
/// the exit code and program information.
///
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String]) async throws {
try self.runProgram([command] + arguments, env: self.proxyEnv(toolchain))
public func proxy(_ toolchain: ToolchainVersion, _ command: String, _ arguments: [String], _ env: [String: String] = [:]) async throws {
var newEnv = try self.proxyEnv(toolchain)
for (key, value) in env {
newEnv[key] = value
}
try self.runProgram([command] + arguments, env: newEnv)
}

/// Proxy the invocation of the provided command to the chosen toolchain and capture the output.
Expand Down
57 changes: 52 additions & 5 deletions scripts/prep-gh-action.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
#!/bin/bash

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

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

exit 0
set -e

while [ $# -ne 0 ]; do
arg="$1"
case "$arg" in
--install-swiftly)
installSwiftly=true
;;
*)
;;
esac
shift
done

if [ "$installSwiftly" == true ]; then
echo "Installing swiftly"
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

. "/root/.local/share/swiftly/env.sh"
hash -r

if [ -n "$GITHUB_ENV" ]; then
echo "Updating GitHub environment"
echo "PATH=$PATH" >> "$GITHUB_ENV" && echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV"
fi

if [ -f .swift-version ]; then
echo "Installing selected swift toolchain"
swiftly install --post-install-file=post-install.sh
else
echo "Installing latest toolchain"
swiftly install --post-install-file=post-install.sh latest
fi

if [ -f post-install.sh ]; then
echo "Performing swift toolchain post-installation"
chmod u+x post-install.sh && ./post-install.sh
fi

echo "Displaying swift version"
swift --version

CC=clang swiftly run "$(dirname "$0")/install-libarchive.sh"
else
"$(dirname "$0")/install-libarchive.sh"
fi
Loading