scripts: add publishing scripts

This commit is contained in:
Ryan Heywood 2024-05-16 02:01:10 -04:00
parent 491d19469a
commit d759982853
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 62 additions and 0 deletions

View File

@ -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"]]))

15
scripts/publish.sh Normal file
View File

@ -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

View File

@ -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"