#!/usr/bin/env bash set -eux usage() { echo "Usage: $0 " >&2 exit 1 } args="$(getopt -o '' -l '' -n "$0" -- "$@")" eval "set -- $args" while true; do case "$1" in --) shift; break;; *) usage;; esac done GITID=$(git rev-parse HEAD) if [ -z "${1:-}" ]; then usage fi version="$1" prefix="zulip-server-$version" if [ "$(uname)" = "Darwin" ]; then TMPDIR=/tmp/voyager-build rm -Rf "$TMPDIR" mkdir -p "$TMPDIR" else TMPDIR=$(mktemp -d) fi if ! git diff --exit-code >/dev/null; then set +x echo "ERROR: tarballs builds are based on a commit hash so your changes " echo "will not be included; you should commit or stash them based on " echo "what you want and then try again." echo exit 1 fi TMP_CHECKOUT=$TMPDIR/$prefix TARBALL=$TMPDIR/$prefix.tar BASEDIR=$(pwd) # .gitattributes lists the files that are not exported git archive -o "$TARBALL" "--prefix=$prefix/" HEAD cd "$TMPDIR" tar -xf "$TARBALL" for i in `cat "$TMP_CHECKOUT"/tools/release-tarball-exclude.txt`; do rm -r --interactive=never "$TMP_CHECKOUT/$i"; done tar -cf "$TARBALL" "$prefix" rm -rf "$prefix" if tar -tf "$TARBALL" | grep -q -e ^zerver/tests; then echo "BUG: Excluded files remain in tarball!" exit 1 fi cd "$BASEDIR" # Check out a temporary full copy of the index to generate static files git checkout-index -f -a --prefix "$TMP_CHECKOUT/" cd "$TMP_CHECKOUT" # create var/log directory in the new temporary checkout mkdir -p "var/log" # Some settings need to be updated for update-prod-static to work # # TODO: Would be much better to instead run the below tools with some # sort of environment hack so that we don't need to create this dummy # secrets file. cat >> zproject/prod_settings_template.py <> zproject/dev-secrets.conf < build_id echo "$version" > version rm -f "$USER_PROD_STATIC_LOGPATH" mv "$BUILD_PROD_STATIC_LOGPATH" "$USER_PROD_STATIC_LOGPATH" rm -f zproject/dev-secrets.conf # We don't need duplicate copies of emoji with hashed paths, and they would break bugdown find prod-static/serve/generated/emoji/images/emoji/ -regex '.*\.[0-9a-f]+\.png' -delete cd "$TMPDIR" tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" "$prefix/staticfiles.json" "$prefix/templates/zerver/emails/compiled" "$prefix/webpack-stats-production.json" rm -rf "$prefix" gzip "$TARBALL" echo "Generated $TARBALL.gz"