Skip to content

Commit 6db29c3

Browse files
committed
ci: use s3api for release immutability check
1 parent 7458100 commit 6db29c3

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

.github/workflows/rust-release.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,22 @@ jobs:
295295
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
296296
run: |
297297
set -euo pipefail
298-
PREFIX="s3://${BUCKET}/${PROJECT}/${VERSION}/"
298+
PREFIX="${PROJECT}/${VERSION}/"
299299
immutability_check_err="/tmp/immutability-check.err"
300300
trap 'rm -f "${immutability_check_err}"' EXIT
301-
if ! existing_prefix_listing="$(aws s3 ls "${PREFIX}" --endpoint-url "${R2_ENDPOINT}" 2>"${immutability_check_err}")"; then
302-
echo "Failed to check release immutability for ${PREFIX}." >&2
301+
if ! existing_prefix_listing="$(aws s3api list-objects-v2 \
302+
--bucket "${BUCKET}" \
303+
--prefix "${PREFIX}" \
304+
--max-keys 1 \
305+
--endpoint-url "${R2_ENDPOINT}" \
306+
--output json 2>"${immutability_check_err}")"; then
307+
echo "Failed to check release immutability for s3://${BUCKET}/${PREFIX}." >&2
303308
cat "${immutability_check_err}" >&2
304309
exit 1
305310
fi
306311
rm -f "${immutability_check_err}"
307-
if [[ -n "${existing_prefix_listing}" ]]; then
308-
echo "Release prefix already exists: ${PREFIX}"
312+
if jq -e '.Contents | type == "array" and length > 0' >/dev/null <<<"${existing_prefix_listing}"; then
313+
echo "Release prefix already exists: s3://${BUCKET}/${PREFIX}"
309314
echo "Refusing to overwrite immutable release artifacts."
310315
exit 1
311316
fi

0 commit comments

Comments
 (0)