From d7599828535001b14bab17a3c999e6520e7606d4 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 16 May 2024 02:01:10 -0400 Subject: [PATCH] scripts: add publishing scripts --- scripts/generate-dependency-queue.py | 18 +++++++++++++++++ scripts/publish.sh | 15 ++++++++++++++ scripts/sign-new-versions.sh | 29 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 scripts/generate-dependency-queue.py create mode 100644 scripts/publish.sh create mode 100644 scripts/sign-new-versions.sh diff --git a/scripts/generate-dependency-queue.py b/scripts/generate-dependency-queue.py new file mode 100644 index 0000000..c2bf758 --- /dev/null +++ b/scripts/generate-dependency-queue.py @@ -0,0 +1,18 @@ +import json +import sys + +priority_queue = [] +packages = json.load(sys.stdin)["packages"] + +def iter_packages(package_name): + package = next((package for package in packages if package["name"] == package_name), None) + if package is not None and package["source"] is None: + for dependency in package["dependencies"]: + iter_packages(dependency["name"]) + if package_name not in priority_queue: + priority_queue.append(package_name) + +iter_packages("keyfork") +for package_name in priority_queue: + package = next((package for package in packages if package["name"] == package_name), None) + print(" ".join([package["name"], package["version"]])) diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 0000000..69a9d37 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,15 @@ +set -eu +set -o pipefail + +scripts_dir="$(dirname $0)" +python_script="$scripts_dir/generate-dependency-queue.py" +registry_url="https://git.distrust.co/api/packages/public/cargo" +search_url="${registry_url}/api/v1/crates" + +cargo metadata --format-version=1 | python3 "$python_script" | while read crate version; do + # Verify the package does not exist + if ! curl "${search_url}?q=${crate}" 2>/dev/null | jq -e "$(printf '.crates | .[] | select(.name == "%s" and .max_version == "%s")' "$crate" "$version")" >/dev/null; then + cargo publish --registry distrust -p "$crate" + fi +done + diff --git a/scripts/sign-new-versions.sh b/scripts/sign-new-versions.sh new file mode 100644 index 0000000..769aa07 --- /dev/null +++ b/scripts/sign-new-versions.sh @@ -0,0 +1,29 @@ +set -eu +set -o pipefail + +LAST_REF="$1" +CURRENT_REF="${2:-HEAD}" + +temp_file="$(mktemp)" + +cargo metadata --format-version=1 | jq -r '.packages[] | select(.source == null) | .name + " " + .manifest_path + " " + .version' > "$temp_file" + +while read crate manifest_path version <&3; do + crate_path="$(dirname $manifest_path)" + git_log="$(git log --format='%h %s' "$LAST_REF"..HEAD "$crate_path")" + git_tag="$(git tag --list "$crate-v${version}")" + if test ! -z "$git_log" -a -z "$git_tag"; then + { + echo "${crate} v${version}" + echo "" + echo "\`\`\`" + echo "$git_log" + echo "\`\`\`" + echo "" + echo "# Crate: ${crate} ${version}" + } | git tag --sign "${crate}-v${version}" -F - -e + echo "Making new tag: ${crate}-v${version}" + fi +done 3<"$temp_file" + +rm "$temp_file"