Skip to content

Commit defb820

Browse files
committed
cleaner swiftly install script
1 parent 18907f8 commit defb820

File tree

4 files changed

+89
-101
lines changed

4 files changed

+89
-101
lines changed

.github/scripts/install_swiftly.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# This script is reused from Swiftly itself, see:
4+
# https://github.com/swiftlang/swiftly/blob/main/scripts/prep-gh-action.sh
5+
#
6+
# This script does a bit of extra preparation of the docker containers used to run the GitHub workflows
7+
# that are specific to this project's needs when building/testing. Note that this script runs on
8+
# every supported Linux distribution and macOS so it must adapt to the distribution that it is running.
9+
10+
if [[ "$(uname -s)" == "Linux" ]]; then
11+
# Install the basic utilities depending on the type of Linux distribution
12+
apt-get --help && apt-get update && TZ=Etc/UTC apt-get -y install curl make gpg tzdata
13+
yum --help && (curl --help && yum -y install curl) && yum install make gpg
14+
fi
15+
16+
set -e
17+
18+
while [ $# -ne 0 ]; do
19+
arg="$1"
20+
case "$arg" in
21+
snapshot)
22+
swiftMainSnapshot=true
23+
;;
24+
*)
25+
;;
26+
esac
27+
shift
28+
done
29+
30+
echo "Installing swiftly"
31+
32+
if [[ "$(uname -s)" == "Linux" ]]; then
33+
curl -O "https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz" && tar zxf swiftly-*.tar.gz && ./swiftly init -y --skip-install
34+
# shellcheck disable=SC1091
35+
. "/root/.local/share/swiftly/env.sh"
36+
else
37+
# shellcheck disable=SC2155
38+
export SWIFTLY_HOME_DIR="$(pwd)/swiftly-bootstrap"
39+
export SWIFTLY_BIN_DIR="$SWIFTLY_HOME_DIR/bin"
40+
export SWIFTLY_TOOLCHAINS_DIR="$SWIFTLY_HOME_DIR/toolchains"
41+
42+
curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && pkgutil --check-signature swiftly.pkg && pkgutil --verbose --expand swiftly.pkg "${SWIFTLY_HOME_DIR}" && tar -C "${SWIFTLY_HOME_DIR}" -xvf "${SWIFTLY_HOME_DIR}"/swiftly-*/Payload && "$SWIFTLY_HOME_DIR/bin/swiftly" init -y --skip-install
43+
44+
# shellcheck disable=SC1091
45+
. "$SWIFTLY_HOME_DIR/env.sh"
46+
fi
47+
48+
hash -r
49+
50+
if [ -n "$GITHUB_ENV" ]; then
51+
echo "Updating GitHub environment"
52+
echo "PATH=$PATH" >> "$GITHUB_ENV" && echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_TOOLCHAINS_DIR=$SWIFTLY_TOOLCHAINS_DIR" >> "$GITHUB_ENV"
53+
fi
54+
55+
selector=()
56+
runSelector=()
57+
58+
if [ "$swiftMainSnapshot" == true ]; then
59+
echo "Installing latest main-snapshot toolchain"
60+
selector=("main-snapshot")
61+
runSelector=("+main-snapshot")
62+
elif [ -n "${SWIFT_VERSION}" ]; then
63+
echo "Installing selected swift toolchain from SWIFT_VERSION environment variable"
64+
selector=("${SWIFT_VERSION}")
65+
runSelector=()
66+
elif [ -f .swift-version ]; then
67+
echo "Installing selected swift toolchain from .swift-version file"
68+
selector=()
69+
runSelector=()
70+
else
71+
echo "Installing latest toolchain"
72+
selector=("latest")
73+
runSelector=("+latest")
74+
fi
75+
76+
swiftly install --post-install-file=post-install.sh "${selector[@]}"
77+
78+
if [ -f post-install.sh ]; then
79+
echo "Performing swift toolchain post-installation"
80+
chmod u+x post-install.sh && ./post-install.sh
81+
fi
82+
83+
echo "Displaying swift version"
84+
swiftly run "${runSelector[@]}" swift --version
85+
86+
if [[ "$(uname -s)" == "Linux" ]]; then
87+
CC=clang swiftly run "${runSelector[@]}" "$(dirname "$0")/install-libarchive.sh"
88+
fi

.github/scripts/prep-gh-action.sh

Lines changed: 0 additions & 94 deletions
This file was deleted.

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ jobs:
169169
- name: Prepare CI Environment
170170
uses: ./.github/actions/prepare_env
171171
- name: Install Swiftly # we specifically install Swiftly in macOS jobs because we want a simpler way to find the right dylib paths for libraries
172-
run: ./.github/scripts/prep-gh-action.sh --install-swiftly
172+
run: ./.github/scripts/install_swiftly.sh
173173
env:
174174
SWIFT_VERSION: "${{ matrix.swift_version }}"
175175
- name: "Verify sample ${{ matrix.sample_app }}"

Samples/SwiftAndJavaJarSampleLib/ci-validate.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ then
5555
elif [ "$(uname -s)" = 'Darwin' ]
5656
then
5757
SWIFT_LIB_PATHS=$(find "$(swiftly use --print-location)" | grep dylib$ | grep libswiftCore | grep macos | head -n1 | xargs dirname)
58-
if [ -z "${SWIFT_LIB_PATHS}" ]
59-
then
60-
# if we failed to locate paths using swiftly...
61-
# try to use the the path that we know about for github actions macOS
62-
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:/Library/Developer/CommandLineTools/usr/lib/swift-5.0/macosx/"
63-
fi
6458
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(pwd)/$(find . | grep libMySwiftLibrary.dylib$ | sort | head -n1 | xargs dirname)"
6559

6660
fi

0 commit comments

Comments
 (0)