#!/usr/bin/env bash set -eu # shellcheck source=lib/git-tools.bash . "$(dirname "$0")"/lib/git-tools.bash usage() { echo "Usage: $0 " >&2 exit 1 } args="$(getopt -o '' -l 'help' -n "$0" -- "$@")" eval "set -- $args" while true; do case "$1" in --) shift break ;; *) usage ;; esac done if [ -z "${1:-}" ]; then usage fi version="$1" prefix="zulip-server-$version" require_clean_work_tree 'build a release tarball' set -x GITID=$(git rev-parse HEAD) umask 022 OUTPUT_DIR=${OUTPUT_DIR:-$(mktemp -d)} TARBALL=$OUTPUT_DIR/$prefix.tar BASEDIR=$(pwd) git archive -o "$TARBALL" "--prefix=$prefix/" HEAD cd "$OUTPUT_DIR" tar -xf "$TARBALL" while read -r i; do rm -r --interactive=never "${OUTPUT_DIR:?}/$prefix/$i" done <"$OUTPUT_DIR/$prefix/tools/release-tarball-exclude.txt" tar -cf "$TARBALL" "$prefix" rm -rf "$prefix" if tar -tf "$TARBALL" | grep -q -e ^zerver/tests; then set +x 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 "$OUTPUT_DIR/$prefix/" # Add the Git version information file ./tools/cache-zulip-git-version if [[ "$version" =~ ^[0-9]+\.[0-9]+$ ]]; then generated_version=$(head -n1 zulip-git-version) base_version=$(head -n2 zulip-git-version | tail -n1) if [ "$generated_version" != "$version" ]; then echo "Version $version looks like a release version, but is not tagged yet! Got $generated_version" exit 1 fi if [ "$base_version" != "$version" ]; then remote="$(git config zulip.zulipRemote)" || remote=upstream echo "Commit for $version have not been pushed to remote $remote -- 'branched from' reports $base_version, not $version" exit 1 fi fi mv zulip-git-version "$OUTPUT_DIR/$prefix/" cd "$OUTPUT_DIR/$prefix" ln -s "$BASEDIR/zulip-py3-venv" . # 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 cd "$OUTPUT_DIR" tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" "$prefix/zulip-git-version" "$prefix/locale" "$prefix/staticfiles.json" "$prefix/templates/zerver/emails/compiled" "$prefix/webpack-stats-production.json" rm -rf "$prefix" gzip "$TARBALL" set +x TARBALL="$TARBALL.gz" echo "Generated $TARBALL"