#!/usr/bin/env nix-shell #!nix-shell -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github jq if [ "$#" -gt 3 ] || [[ "$1" == -* ]]; then echo "Regenerates packaging data for the ERPNext packages." echo "Usage: $0 [git bench release tag] [git erpnext release tag] [git frappe release tag]" exit 1 fi bench_version="$1" erpnext_version="$2" frappe_version="$3" set -euo pipefail if [ -z "$bench_version" ]; then bench_version="$(wget --quiet --output-document=- "https://api.github.com/repos/frappe/bench/releases?per_page=1" | jq --raw-output '.[0].tag_name')" fi if [ -z "$erpnext_version" ]; then erpnext_version="$(wget --quiet --output-document=- "https://api.github.com/repos/frappe/erpnext/releases?per_page=1" | jq --raw-output '.[0].tag_name')" fi if [ -z "$frappe_version" ]; then frappe_version="$(wget --quiet --output-document=- "https://api.github.com/repos/frappe/frappe/releases?per_page=1" | jq --raw-output '.[0].tag_name')" fi # strip leading "v" bench_version="${bench_version#v}" erpnext_version="${erpnext_version#v}" frappe_version="${frappe_version#v}" # Bench echo "Prefetching bench source version $bench_version from GitHub ..." bench_src_hash=$(nix-prefetch-github frappe bench --rev "v${bench_version}" | jq --raw-output .hash) # Erpnext echo "Prefetching erpnext source version $erpnext_version from GitHub ..." erpnext_src="https://raw.githubusercontent.com/frappe/erpnext/v$erpnext_version" erpnext_src_hash="$(nix-prefetch-github frappe erpnext --rev "v${erpnext_version}" | jq --raw-output .hash)" erpnext_tmpdir=$(mktemp --directory) trap 'rm -rf "$erpnext_tmpdir"' EXIT pushd "$erpnext_tmpdir" &> /dev/null wget --quiet "$erpnext_src/yarn.lock" echo "Prefetching erpnext yarn dependencies ..." erpnext_yarn_hash=$(prefetch-yarn-deps yarn.lock) popd &> /dev/null # Frappe echo "Prefetching frappe source version $frappe_version from GitHub ..." frappe_src="https://raw.githubusercontent.com/frappe/frappe/v$frappe_version" frappe_src_hash="$(nix-prefetch-github frappe frappe --rev "v${frappe_version}" | jq --raw-output .hash)" frappe_tmpdir=$(mktemp --directory) trap 'rm -rf "$frappe_tmpdir"' EXIT pushd "$frappe_tmpdir" &> /dev/null wget --quiet "$frappe_src/yarn.lock" echo "Prefetching frappe yarn dependencies ..." frappe_yarn_hash=$(prefetch-yarn-deps yarn.lock) popd &> /dev/null echo "Saving updated versions and hashes to pin.nix file ..." cat > pin.nix << EOF { benchVersion = "$bench_version"; erpnextVersion = "$erpnext_version"; frappeVersion = "$frappe_version"; hashes = { "benchSrcHash" = "$bench_src_hash"; "erpnextSrcHash" = "$erpnext_src_hash"; "erpnextYarnHash" = "$erpnext_yarn_hash"; "frappeSrcHash" = "$frappe_src_hash"; "frappeYarnHash" = "$frappe_yarn_hash"; }; } EOF