From 9d9214fa3796c6fc7aae308a9adef4196659a46f Mon Sep 17 00:00:00 2001 From: Chris O'Neil Date: Thu, 4 Jul 2024 14:14:13 +0100 Subject: [PATCH] ci: prevent s3 files being overwritten If a released binary has been uploaded to S3, it should be prevented from being overwritten. If it is being overwritten, it could very well be suggestive of a mistake somewhere. If you really want to intentionally overwrite the file for some reason, remove it from the S3 bucket manually, then run the workflow again. --- Justfile | 9 ++++++++- test.sh | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 test.sh diff --git a/Justfile b/Justfile index 02ab46ba20..a6d1e7d24e 100644 --- a/Justfile +++ b/Justfile @@ -378,7 +378,14 @@ upload-release-assets-to-s3 bin_name: cd deploy/{{bin_name}} for file in *.zip *.tar.gz; do - aws s3 cp "$file" "s3://$bucket/$file" --acl public-read + dest="s3://$bucket/$file" + if aws s3 ls "$dest" > /dev/null 2>&1; then + echo "$dest already exists. This suggests an error somewhere." + echo "If you intentionally want to overwrite, remove the file and run the workflow again." + exit 1 + else + aws s3 cp "$file" "$dest" --acl public-read + fi done node-man-integration-tests: diff --git a/test.sh b/test.sh new file mode 100755 index 0000000000..3b5662f3c5 --- /dev/null +++ b/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +BUCKET_NAME="your-bucket-name" +DESTINATION_PATH="s3://nat-detection/nat-detection-0.1.0-aarch64-unknown-linux-musl.zip" +LOCAL_FILE_PATH="path/to/local/file" + +if aws s3 ls "$DESTINATION_PATH" > /dev/null 2>&1; then + echo "Error: Destination file already exists in the bucket." + exit 1 +else + echo "will upload" +fi