1+ #! /bin/bash
2+
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 and macOS so it must adapt to the distribution that it is running.
6+
7+ if [[ " $( uname -s) " == " Linux" ]]; then
8+ # Install the basic utilities depending on the type of Linux distribution
9+ apt-get --help && apt-get update && TZ=Etc/UTC apt-get -y install curl make gpg tzdata
10+ yum --help && (curl --help && yum -y install curl) && yum install make gpg
11+ fi
12+
13+ set -e
14+
15+ while [ $# -ne 0 ]; do
16+ arg=" $1 "
17+ case " $arg " in
18+ --install-swiftly)
19+ installSwiftly=true
20+ ;;
21+ --swift-main-snapshot)
22+ swiftMainSnapshot=true
23+ ;;
24+ * )
25+ ;;
26+ esac
27+ shift
28+ done
29+
30+ if [ " $installSwiftly " == true ]; then
31+ echo " Installing swiftly"
32+
33+ if [[ " $( uname -s) " == " Linux" ]]; then
34+ curl -O https://download.swift.org/swiftly/linux/swiftly-$( uname -m) .tar.gz && tar zxf swiftly-* .tar.gz && ./swiftly init -y --skip-install
35+ . " /root/.local/share/swiftly/env.sh"
36+ else
37+ export SWIFTLY_HOME_DIR=" $( pwd) /swiftly-bootstrap"
38+ export SWIFTLY_BIN_DIR=" $SWIFTLY_HOME_DIR /bin"
39+ export SWIFTLY_TOOLCHAINS_DIR=" $SWIFTLY_HOME_DIR /toolchains"
40+
41+ 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
42+
43+ . " $SWIFTLY_HOME_DIR /env.sh"
44+ fi
45+
46+ hash -r
47+
48+ if [ -n " $GITHUB_ENV " ]; then
49+ echo " Updating GitHub environment"
50+ 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 "
51+ fi
52+
53+ selector=()
54+ runSelector=()
55+
56+ if [ " $swiftMainSnapshot " == true ]; then
57+ echo " Installing latest main-snapshot toolchain"
58+ selector=(" main-snapshot" )
59+ runSelector=(" +main-snapshot" )
60+ elif [ -f .swift-version ]; then
61+ echo " Installing selected swift toolchain from .swift-version file"
62+ selector=()
63+ runSelector=()
64+ else
65+ echo " Installing latest toolchain"
66+ selector=(" latest" )
67+ runSelector=(" +latest" )
68+ fi
69+
70+ swiftly install --post-install-file=post-install.sh " ${selector[@]} "
71+
72+ if [ -f post-install.sh ]; then
73+ echo " Performing swift toolchain post-installation"
74+ chmod u+x post-install.sh && ./post-install.sh
75+ fi
76+
77+ echo " Displaying swift version"
78+ swiftly run " ${runSelector[@]} " swift --version
79+
80+ if [[ " $( uname -s) " == " Linux" ]]; then
81+ CC=clang swiftly run " ${runSelector[@]} " " $( dirname " $0 " ) /install-libarchive.sh"
82+ fi
83+ else
84+ if [[ " $( uname -s) " == " Linux" ]]; then
85+ " $( dirname " $0 " ) /install-libarchive.sh"
86+ fi
87+ fi
0 commit comments