Skip to content

Commit bfeb73f

Browse files
fix: Artifact publishing script
1 parent a6b8553 commit bfeb73f

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

packages/contracts-bedrock/scripts/ops/publish-artifacts.sh

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fi
2828
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2929
CONTRACTS_DIR="$SCRIPT_DIR/../.."
3030
DEPLOY_BUCKET="oplabs-contract-artifacts"
31+
BUCKET_URL="https://storage.googleapis.com/$DEPLOY_BUCKET"
3132

3233
cd "$CONTRACTS_DIR"
3334

@@ -60,19 +61,27 @@ fi
6061

6162
checksum=$(bash scripts/ops/calculate-checksum.sh)
6263

64+
archive_name_gz="artifacts-v1-$checksum.tar.gz"
65+
archive_name_zst="artifacts-v1-$checksum.tar.zst"
66+
67+
upload_url_gz="$BUCKET_URL/$archive_name_gz"
68+
upload_url_zst="$BUCKET_URL/$archive_name_zst"
69+
70+
upload_artifacts=("$archive_name_gz")
71+
6372
echoerr "> Checksum: $checksum"
6473
echoerr "> Checking for existing artifacts..."
6574

6675
if [ "$HAS_ZSTD" = true ]; then
67-
upload_url_zst="https://storage.googleapis.com/$DEPLOY_BUCKET/artifacts-v1-$checksum.tar.zst"
6876
exists_zst=$(curl -s -o /dev/null --fail -LI "$upload_url_zst" || echo "fail")
6977
if [ "$exists_zst" != "fail" ] && [ "$FORCE" = false ]; then
7078
echoerr "> Existing artifacts found (.tar.zst), nothing to do. Use --force to overwrite."
7179
exit 0
7280
fi
81+
82+
upload_artifacts+=("$archive_name_zst")
7383
fi
7484

75-
upload_url_gz="https://storage.googleapis.com/$DEPLOY_BUCKET/artifacts-v1-$checksum.tar.gz"
7685
exists_gz=$(curl -s -o /dev/null --fail -LI "$upload_url_gz" || echo "fail")
7786

7887
if [ "$exists_gz" != "fail" ] && [ "$FORCE" = false ]; then
@@ -93,23 +102,21 @@ rm -f COMMIT
93102
commit=$(git rev-parse HEAD)
94103
echo "$commit" > COMMIT
95104

105+
tar_args=("artifacts" "forge-artifacts" "COMMIT")
106+
if [ -d "cache" ]; then
107+
tar_args+=("cache")
108+
echoerr "> Including cache directory in archive"
109+
else
110+
echoerr "> Cache directory not found, excluding from archive"
111+
fi
112+
96113

97114
if [ "$HAS_ZSTD" = true ]; then
98115
echoerr "> Compressing artifacts (.tar.gz and .tar.zst)..."
99116

100117
# Create intermediate tar file first for reliable compression
101118
temp_tar="artifacts-v1-$checksum.tar"
102-
tar_args="artifacts forge-artifacts COMMIT"
103-
if [ -d "cache" ]; then
104-
tar_args="$tar_args cache"
105-
echoerr "> Including cache directory in archive"
106-
else
107-
echoerr "> Cache directory not found, excluding from archive"
108-
fi
109-
"$tar" -cf "$temp_tar" "$tar_args"
110-
111-
archive_name_gz="artifacts-v1-$checksum.tar.gz"
112-
archive_name_zst="artifacts-v1-$checksum.tar.zst"
119+
"$tar" -cf "$temp_tar" "${tar_args[@]}"
113120

114121
gzip -9 < "$temp_tar" > "$archive_name_gz" &
115122
gz_pid=$!
@@ -140,33 +147,25 @@ if [ "$HAS_ZSTD" = true ]; then
140147
fi
141148
else
142149
echoerr "> Compressing artifacts (.tar.gz)..."
143-
archive_name_gz="artifacts-v1-$checksum.tar.gz"
144-
tar_args="artifacts forge-artifacts COMMIT"
145-
if [ -d "cache" ]; then
146-
tar_args="$tar_args cache"
147-
echoerr "> Including cache directory in archive"
148-
else
149-
echoerr "> Cache directory not found, excluding from archive"
150-
fi
151-
"$tar" -czf "$archive_name_gz" "$tar_args"
150+
151+
"$tar" -czf "$archive_name_gz" "${tar_args[@]}"
152152
du -sh "$archive_name_gz" | awk '{$1=$1};1' # trim leading whitespace
153153
echoerr "> Created .tar.gz archive"
154154
fi
155155

156156
echoerr "> Done."
157157

158-
echoerr "> Uploading artifacts to GCS..."
158+
echoerr "> Uploading artifacts to $BUCKET_URL..."
159159

160160
# Force single-stream upload to improve reliability
161161
gcloud config set storage/parallel_composite_upload_enabled False
162-
if [ "$HAS_ZSTD" = true ]; then
163-
gcloud --verbosity="info" storage cp "$archive_name_gz" "$archive_name_zst" "gs://$DEPLOY_BUCKET/"
164-
echoerr "> Uploaded to: $upload_url_gz"
165-
echoerr "> Uploaded to: $upload_url_zst"
166-
else
167-
gcloud --verbosity="info" storage cp "$archive_name_gz" "gs://$DEPLOY_BUCKET/$archive_name_gz"
168-
echoerr "> Uploaded to: $upload_url_gz"
169-
fi
162+
163+
# Upload the artifacts
164+
gcloud --verbosity="info" storage cp "${upload_artifacts[@]}" "gs://$DEPLOY_BUCKET/"
165+
166+
for artifact_name in "${upload_artifacts[@]}"; do
167+
echoerr "> Uploaded to: $BUCKET_URL/$artifact_name"
168+
done
170169

171170
echoerr "> Done."
172171

0 commit comments

Comments
 (0)