Implemented automatic binary packaging + install script.

This commit is contained in:
Martin Šošić 2020-09-19 16:56:28 +02:00 committed by GitHub
parent c1f2d6dab3
commit fda67bb8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 203 additions and 4 deletions

View File

@ -45,16 +45,14 @@ script:
- stack --no-terminal test - stack --no-terminal test
after_success: after_success:
# Prepare releases to be deployed. - ./tools/make_binary_package.sh wasp-${TRAVIS_OS_NAME}-x86_64.tar.gz
- mkdir travis-releases/
- mv "$(stack path --local-install-root)/bin/wasp" "travis-releases/wasp-${TRAVIS_OS_NAME}"
deploy: deploy:
provider: releases provider: releases
api_key: api_key:
# Encrypted github access key. Generated with `travis setup --pro releases`. # Encrypted github access key. Generated with `travis setup --pro releases`.
secure: IkYVwfhHNnNncrsDk+bjv80f4tRIDwjmyYSKd3Ssiuxzz/NDGIDuWDUfIApt9skI6URaZInQhF7BPZ0llHUOHOnCsfw2c8ve/XcX9BOqsczCGI1XFrnuFiwst9aogNTupkVL4sAPz45MysENfgWEbqDWXlMgj0DgYG2qk7mpCMcY0MUkw6ZNuozjs8uM6ilVYdTKPut8cMQsJkfX+kzA3x5BfnuRNSyfs8W5DjjwZ+vVAKzdw0zL49GWBjfFfh+QRiekWqziEfFO6EyaD75VSGQKa5VUQQvmmy2CDKPayj94STBTZdmnPGK2QXwiSdJxaDS/vw2TwHyiHRZkvkRQ20kr9+tMpZjuE5mN2xiRBUt8jDjGJWCxzfL1JbBPdtShcrCofDvTwAFOT6ykd9dbfzAhEubAO6L/S0JIs0sRj/M18bXKh5VeDCabBOLfh5wGtOWy44sQ1FMW+vismA4MLYYMm5bSxjL+HWE7ijSbHOF0ew72L/cbHKXhALv48VNGVYj7wy/6MC7HXkgHyxGPUn5tx2a0oUBWkK62Asmba42i2KDed6ylChlivIijyoeg3dpYpcZjr4HfuC1e1O+NHIF8uke9yc7sNp3vdriD8HxvdmJQrbbwy3EIMSW9v5soePDTJywNEAcIwUCl6USE2fVShRuYcvhbkLYGoQMzh8U= secure: IkYVwfhHNnNncrsDk+bjv80f4tRIDwjmyYSKd3Ssiuxzz/NDGIDuWDUfIApt9skI6URaZInQhF7BPZ0llHUOHOnCsfw2c8ve/XcX9BOqsczCGI1XFrnuFiwst9aogNTupkVL4sAPz45MysENfgWEbqDWXlMgj0DgYG2qk7mpCMcY0MUkw6ZNuozjs8uM6ilVYdTKPut8cMQsJkfX+kzA3x5BfnuRNSyfs8W5DjjwZ+vVAKzdw0zL49GWBjfFfh+QRiekWqziEfFO6EyaD75VSGQKa5VUQQvmmy2CDKPayj94STBTZdmnPGK2QXwiSdJxaDS/vw2TwHyiHRZkvkRQ20kr9+tMpZjuE5mN2xiRBUt8jDjGJWCxzfL1JbBPdtShcrCofDvTwAFOT6ykd9dbfzAhEubAO6L/S0JIs0sRj/M18bXKh5VeDCabBOLfh5wGtOWy44sQ1FMW+vismA4MLYYMm5bSxjL+HWE7ijSbHOF0ew72L/cbHKXhALv48VNGVYj7wy/6MC7HXkgHyxGPUn5tx2a0oUBWkK62Asmba42i2KDed6ylChlivIijyoeg3dpYpcZjr4HfuC1e1O+NHIF8uke9yc7sNp3vdriD8HxvdmJQrbbwy3EIMSW9v5soePDTJywNEAcIwUCl6USE2fVShRuYcvhbkLYGoQMzh8U=
file: "travis-releases/wasp-${TRAVIS_OS_NAME}" file: "wasp-${TRAVIS_OS_NAME}-x86_64.tar.gz"
skip_cleanup: true skip_cleanup: true
on: on:
# Whenever we push a tagged commit, binary will be deployed to releases. # Whenever we push a tagged commit, binary will be deployed to releases.

View File

@ -17,6 +17,11 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/github/wasp-lang/wasp?branch=master&svg=true)](https://ci.appveyor.com/project/Martinsos/wasp/branch/master) [![Build Status](https://ci.appveyor.com/api/projects/status/github/wasp-lang/wasp?branch=master&svg=true)](https://ci.appveyor.com/project/Martinsos/wasp/branch/master)
## Install
To install latest release, run `curl -sSL https://raw.githubusercontent.com/wasp-lang/wasp/master/waspc/tools/install.sh | sh`!
This will work for linux/osx and will install a prebuilt binary. Since the binary is dynamically built (for now), it might not work if you are missing some packages/libraries on your OS or if your OS distro is very different from the one it was built on.
## Setup ## Setup
Install `stack`. Install `stack`.

178
waspc/tools/install.sh Executable file
View File

@ -0,0 +1,178 @@
#!/bin/sh -e
# NOTE: Heavily inspired by get-stack.hs script for installing stack.
# https://raw.githubusercontent.com/commercialhaskell/stack/stable/etc/scripts/get-stack.sh
HOME_LOCAL_BIN="$HOME/.local/bin"
HOME_LOCAL_SHARE="$HOME/.local/share"
WASP_TEMP_DIR=
FORCE=
while [ $# -gt 0 ]; do
case "$1" in
-f|--force)
FORCE="true"
shift
;;
# -d|--dest)
# DEST="$2"
# shift 2
# ;;
*)
echo "Invalid argument: $1" >&2
exit 1
;;
esac
done
main() {
trap cleanup_temp_dir EXIT
install_based_on_os
}
install_based_on_os() {
case "$(uname)" in
"Linux")
install_from_bin_package "wasp-linux-x86_64.tar.gz"
;;
"Darwin")
install_from_bin_package "wasp-osx-x86_64.tar.gz"
;;
*)
die "Sorry, this installer does not support your operating system: $(uname)."
esac
}
# TODO: Add option to specify which release to download.
# Download a Wasp binary package and install it in $HOME_LOCAL_BIN.
install_from_bin_package() {
PACKAGE_URL="https://github.com/wasp-lang/wasp/releases/latest/download/$1"
make_temp_dir
info "Downloading binary package to temporary dir and unpacking it there..."
dl_to_file "$PACKAGE_URL" "$WASP_TEMP_DIR/$1"
mkdir -p "$WASP_TEMP_DIR/wasp"
if ! tar xzf "$WASP_TEMP_DIR/$1" -C "$WASP_TEMP_DIR/wasp"; then
die "Unpacking binary package failed."
fi
DATA_DST_DIR="$HOME_LOCAL_SHARE"
create_dir_if_missing "$DATA_DST_DIR"
BIN_DST_DIR="$HOME_LOCAL_BIN"
create_dir_if_missing "$BIN_DST_DIR"
# If our install locations are already occupied (by previous wasp installation or smth else),
# inform user that they have to clean it up (or if FORCE is set, we do it for them).
if [ -e "$DATA_DST_DIR/wasp" ]; then
if [ "$FORCE" = "true" ]; then
echo "Removing already existing $DATA_DST_DIR/wasp"
rm -Ir "$DATA_DST_DIR/wasp"
else
die "$DATA_DST_DIR/wasp already exists, remove it manually in order to continue installation."
fi
fi
if [ -e "$BIN_DST_DIR/wasp" ]; then
if [ ! "$FORCE" = "true" ]; then
die "$BIN_DST_DIR/wasp already exists, remove it manually in order to continue installation."
fi
fi
info "Installing Wasp data to $DATA_DST_DIR..."
if ! mv "$WASP_TEMP_DIR/wasp" "$DATA_DST_DIR/"; then
die "Installing data to $DATA_DST_DIR failed."
fi
info "Installing Wasp executable to $BIN_DST_DIR..."
# TODO: I should make sure here that $DATA_DST_DIR is abs path.
# It works for now because we set it to HOME_LOCAL_SHARE which
# we obtained using $HOME which is absolute, but if that changes
# and it is not absolute any more, .sh file generated below
# will not work properly.
printf '#!/usr/bin/env bash\nwaspc_datadir=%s/wasp/data %s/wasp/wasp-bin "$@"\n' "$DATA_DST_DIR" "$DATA_DST_DIR" \
> "$BIN_DST_DIR/wasp"
if ! chmod +x "$BIN_DST_DIR/wasp"; then
die "Failed to make $BIN_DST_DIR/wasp executable."
fi
info "Wasp has been successfully installed! Type 'wasp' to start wasping :)."
if ! on_path "$BIN_DST_DIR"; then
info "WARNING: It looks like '$BIN_DST_DIR' is not on your PATH, add it if you want to be able to invoke wasp command directly from anywhere."
fi
}
create_dir_if_missing() {
if [ ! -d "$1" ]; then
info "$1 does not exist, creating it..."
if ! mkdir -p "$1" 2>/dev/null; then
die "Could not create directory: $1."
fi
fi
}
# Creates a temporary directory, which will be cleaned up automatically
# when the script finishes
make_temp_dir() {
WASP_TEMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t wasp)"
}
# Cleanup the temporary directory if it's been created.
# Called automatically when the script exits.
cleanup_temp_dir() {
if [ -n "$WASP_TEMP_DIR" ] ; then
rm -rf "$WASP_TEMP_DIR"
WASP_TEMP_DIR=""
fi
}
# Print a message to stderr and exit with error code.
die() {
echo "$@" >&2
exit 1
}
info() {
echo -e "\033[0;33m{= Wasp installer =}\033[0m" "$@"
}
# Download a URL to file using 'curl' or 'wget'.
dl_to_file() {
if has_curl ; then
if ! curl ${QUIET:+-sS} --fail -L -o "$2" "$1"; then
die "curl download failed: $1"
fi
elif has_wget ; then
if ! wget ${QUIET:+-q} "-O$2" "$1"; then
die "wget download failed: $1"
fi
else
die "Neither wget nor curl is available, please install one to continue."
fi
}
# Check whether 'wget' command exists.
has_wget() {
has_cmd wget
}
# Check whether 'curl' command exists.
has_curl() {
has_cmd curl
}
# Check whether the given command exists.
has_cmd() {
command -v "$1" > /dev/null 2>&1
}
# Check whether the given (query) path is listed in the PATH environment variable.
on_path() {
# We normalize PATH and query regarding ~ by ensuring ~ is expanded to $HOME, avoiding
# false negatives in case where ~ is expanded in query but not in PATH and vice versa.
local PATH_BOUNDED=":$PATH:"
local PATH_NORMALIZED="${PATH_BOUNDED//:\~/:$HOME}" # Expand all ~ that are after :
local QUERY_NORMALIZED=":${1/#\~/$HOME}:" # Expand ~ if it is first character.
echo "$PATH_NORMALIZED" | grep -q "$QUERY_NORMALIZED"
}
main

View File

@ -0,0 +1,18 @@
#!/bin/sh -e
# Takes already built binary from stack and packages it
# together with data into .tar.gz package.
DST=$(realpath ${1:-wasp.tar.gz})
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t wasp-bin-package)"
cp "$(stack path --local-install-root)"/bin/wasp "$TMP_DIR/wasp-bin"
cp -R "$(stack path --project-root)/data" "$TMP_DIR/data"
cd "$TMP_DIR"
tar -czf "$DST" *
if [ -n "$TMP_DIR" ]; then rm -rf "$TMP_DIR"; fi
echo "Generated binary package: $DST."