#!/bin/bash
set -u

# This runs in the actual source tree (not a copy) after a successful build.

set -x
set -e

# Update published yarn lock state
cp -v yarn.lock exagrid/previous.yarn.lock

# Update published packages state:
# 1. Merge new partial list with old complete list
PREV_LIST=exagrid/previous.package-list
TMP_LIST=exagrid/merged.package-list
./exagrid/bin/merge-package-lists "${EGB_PACKAGE_LIST}" "${PREV_LIST}" > "${TMP_LIST}"
# 2. Update both files to have merged list
mv "${EGB_PACKAGE_LIST}" "${EGB_PACKAGE_LIST}.upload"
cp -b "${TMP_LIST}" "${EGB_PACKAGE_LIST}"
mv "${TMP_LIST}" "${PREV_LIST}"

cat <<EOT

If this build is good and ends up being uploaded, be sure to indicate this by
committing the changes to exagrid/previous.* -- for example:

    eg-uploadpkg

    git add exagrid/previous.*
    git commit -m "Uploaded release $(eg-pkginfo release)"
    git push

This state information will allow the next build to target only subpackages
that have changed.

EOT
