1
0
nixfiles/pkgs/update-from-hydra/update-from-hydra.sh

82 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
BUILD_OUTPUT="out"
while [[ $# -gt 0 ]]; do
case $1 in
--hydra-url)
HYDRA_URL="$2"
shift
shift
;;
--hydra-project)
HYDRA_PROJECT="$2"
shift
shift
;;
--hydra-jobset)
HYDRA_JOBSET="$2"
shift
shift
;;
--hydra-job)
HYDRA_JOB="$2"
shift
shift
;;
--nix-store-uri)
NIX_STORE_URI="$2"
shift
shift
;;
--build-output)
BUILD_OUTPUT="$2"
shift
shift
;;
--gcroot-name)
GCROOT_NAME="$2"
shift
shift
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
ARGS+=("$1")
shift
;;
esac
done
set -- "${ARGS[@]}"
HYDRA_JOB_URL="${HYDRA_URL}/job/${HYDRA_PROJECT}/${HYDRA_JOBSET}/${HYDRA_JOB}/latest-finished"
RESULT_PATH="$1"
echo "Updating ${RESULT_PATH} from ${HYDRA_PROJECT}:${HYDRA_JOBSET}:${HYDRA_JOB} output ${BUILD_OUTPUT}"
echo "Make sure symlink directory exist"
mkdir -p "$(dirname "${RESULT_PATH}")"
echo "Fetching job output"
STORE_PATH="$(curl -s -L -H "Accept: application/json" "${HYDRA_JOB_URL}" | jq -r ".buildoutputs.${BUILD_OUTPUT}.path")"
echo "Copying path"
nix copy --from "${NIX_STORE_URI}" "${STORE_PATH}"
echo "Activate path"
ln -fsn "${STORE_PATH}" "${RESULT_PATH}"
if [[ -n $GCROOT_NAME ]]; then
GCROOT_PATH="/nix/var/nix/gcroots/update-from-hydra/${GCROOT_NAME}"
echo "Add to gcroot ${GCROOT_PATH}"
mkdir -p "$(dirname "${GCROOT_PATH}")"
ln -fsn "${RESULT_PATH}" "${GCROOT_PATH}"
fi