From 713d356da7a5348f7b527ecfcb47360157ef4f87 Mon Sep 17 00:00:00 2001 From: Chris O'Neil Date: Fri, 2 Aug 2024 21:33:05 +0100 Subject: [PATCH] chore: script for removing s3 bin archives This is useful if something goes wrong with an RC or stable build or you just need to run the build again and you want new binaries to be uploaded to S3. Obviously it should be used with care, but in some situations it is necessary. It is extremely tedious to remove the files manually, and often when trying to do that, one of them will be missed, which can cause the whole run to fail. --- .../scripts/remove-s3-binary-archives.sh | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 resources/scripts/remove-s3-binary-archives.sh diff --git a/resources/scripts/remove-s3-binary-archives.sh b/resources/scripts/remove-s3-binary-archives.sh new file mode 100755 index 0000000000..7e4fc85c09 --- /dev/null +++ b/resources/scripts/remove-s3-binary-archives.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# This script can be useful in rare cases where you need to run the stable or rc build again. It +# will clear out all the binary archives from S3. The version numbers used are the version numbers +# from the crates on the branch on which the script is running. Obviously, use care with the script. + +architectures=( + "aarch64-apple-darwin" + "aarch64-unknown-linux-musl" + "arm-unknown-linux-musleabi" + "armv7-unknown-linux-musleabihf" + "x86_64-apple-darwin" + "x86_64-pc-windows-msvc" + "x86_64-unknown-linux-musl" +) +declare -A binary_crate_dir_mappings=( + ["faucet"]="sn_faucet" + ["nat-detection"]="nat-detection" + ["node-launchpad"]="node-launchpad" + ["safe"]="sn_cli" + ["safenode"]="sn_node" + ["safenode-manager"]="sn_node_manager" + ["safenode_rpc_client"]="sn_node_rpc_client" + ["safenodemand"]="sn_node_manager" + ["sn_auditor"]="sn_auditor" +) +declare -A binary_s3_bucket_mappings=( + ["faucet"]="sn-faucet" + ["nat-detection"]="nat-detection" + ["node-launchpad"]="node-launchpad" + ["safe"]="sn-cli" + ["safenode"]="sn-node" + ["safenode-manager"]="sn-node-manager" + ["safenode_rpc_client"]="sn-node-rpc-client" + ["safenodemand"]="sn-node-manager" + ["sn_auditor"]="sn-auditor" +) + +for arch in "${architectures[@]}"; do + for binary in "${!binary_crate_dir_mappings[@]}"; do + crate_dir="${binary_crate_dir_mappings[$binary]}" + bucket_name="${binary_s3_bucket_mappings[$binary]}" + version=$(grep "^version" < $crate_dir/Cargo.toml | head -n 1 | awk '{ print $3 }' | sed 's/\"//g') + zip_filename="${binary}-${version}-${arch}.zip" + tar_filename="${binary}-${version}-${arch}.tar.gz" + + dest="s3://${bucket_name}/${zip_filename}" + if aws s3 ls "$dest" > /dev/null 2>&1; then + aws s3 rm $dest + echo "Removed $dest" + else + echo "$dest did not exist" + fi + + dest="s3://${bucket_name}/${tar_filename}" + if aws s3 ls "$dest" > /dev/null 2>&1; then + aws s3 rm $dest + echo "Removed $dest" + else + echo "$dest did not exist" + fi + done +done