#!/usr/bin/env bash
# Usage: script/package-tarball
# Script to build a tarball release package from the current HEAD version.
# The package version comes from `git-describe --tags' so the release tag should
# be in place before this command is run.
set -e

# Change into project root
cd "$(dirname "$0")"/..

# Basic package name and version.
PKG_BASE="github-backup-utils"
PKG_VERS="$(git describe --tags)"
PKG_NAME="${PKG_BASE}-${PKG_VERS}"

# Run git-archive to generate tarball
echo "Creating ${PKG_NAME}.tar.gz ..."
mkdir -p dist
git archive \
  --format=tar.gz \
  --prefix="$PKG_NAME/" \
  --output="dist/${PKG_NAME}.tar.gz" \
  HEAD

# List archive contents for review
gzip -dc < "dist/${PKG_NAME}.tar.gz" | tar tf -

# Output location
echo "Package dist/${PKG_NAME}.tar.gz OK"
