#!/usr/bin/env bash # # Usage: stage-artifacts.sh [projects] # # Copies the deployed files of the given projects to the output directory under their deployed name, # skipping those identical to the deployed file, and lists the projects with copied files in # state-dir/deployed-projects. Reads state-dir/deploy-artifacts (" " # per line, written by affected-projects.sh) and state-dir/deployed-hashes (sha256sum output of the deployed files). set -euo pipefail state="$1" output="$2" projects=" ${3:-} " mkdir -p "$output" : > "${state}/deployed-projects" while read -r project source name; do if [[ "$projects" != *" ${project} "* ]]; then continue fi hash="$(sha256sum "$source" | cut -d ' ' -f 1)" if grep -qxF "${hash} ${name}" "${state}/deployed-hashes"; then echo "${name} from ${project} is unchanged" else echo "Staging ${name} from ${project}" cp "$source" "${output}/${name}" echo "$project" >> "${state}/deployed-projects" fi done < "${state}/deploy-artifacts"