|
| 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 |
0 commit comments