Skip to content

Commit 5b96584

Browse files
authored
ci(contracts): enable latest artifact fallback logic (#18310)
* ci(contracts): enable latest artifact fallback logic - add --fallback-to-latest flag to pull-artifacts.sh - enable fallback forcontracts tests, coverage, and upgrade jobs in ci config - extract download_and_extract helper function in pull-artifacts.sh - add path traversal protection with --exclude='*../*' flag to tar commands * test: trigger artifact fallback by modifying test file * fix(scripts): address bots security concerns in pull-artifacts.sh - add secure curl flags (--fail, --location, --connect-timeout, --max-time, --tlsv1.2) to prevent hangs and enforce TLS - update path traversal exclusion pattern from '*../*' to '*..*' to block all paths containing '..' anywhere - revert test comment change used for CI testing
1 parent 403f6d4 commit 5b96584

File tree

2 files changed

+70
-50
lines changed

2 files changed

+70
-50
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ jobs:
933933
command: forge --version
934934
working_directory: packages/contracts-bedrock
935935
- run:
936-
name: Pull artifacts
937-
command: bash scripts/ops/pull-artifacts.sh
936+
name: Pull artifacts with latest fallback
937+
command: bash scripts/ops/pull-artifacts.sh --fallback-to-latest
938938
working_directory: packages/contracts-bedrock
939939
- go-restore-cache:
940940
namespace: packages/contracts-bedrock/scripts/go-ffi
@@ -1103,8 +1103,8 @@ jobs:
11031103
command: forge --version
11041104
working_directory: packages/contracts-bedrock
11051105
- run:
1106-
name: Pull artifacts
1107-
command: bash scripts/ops/pull-artifacts.sh
1106+
name: Pull artifacts with latest fallback
1107+
command: bash scripts/ops/pull-artifacts.sh --fallback-to-latest
11081108
working_directory: packages/contracts-bedrock
11091109
- run:
11101110
name: Install lcov
@@ -1200,8 +1200,8 @@ jobs:
12001200
command: forge --version
12011201
working_directory: packages/contracts-bedrock
12021202
- run:
1203-
name: Pull artifacts
1204-
command: bash scripts/ops/pull-artifacts.sh
1203+
name: Pull artifacts with latest fallback
1204+
command: bash scripts/ops/pull-artifacts.sh --fallback-to-latest
12051205
working_directory: packages/contracts-bedrock
12061206
- run:
12071207
name: Write pinned block number for cache key

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

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,45 @@ echoerr() {
1616
echo "$@" 1>&2
1717
}
1818

19+
download_and_extract() {
20+
local archive_name=$1
21+
22+
echoerr "> Downloading..."
23+
curl --fail --location --connect-timeout 30 --max-time 300 --tlsv1.2 -o "$archive_name" "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name"
24+
echoerr "> Done."
25+
26+
echoerr "> Cleaning up existing artifacts..."
27+
rm -rf artifacts
28+
rm -rf forge-artifacts
29+
rm -rf cache
30+
echoerr "> Done."
31+
32+
echoerr "> Extracting artifacts..."
33+
if [[ "$archive_name" == *.tar.zst ]]; then
34+
zstd -dc "$archive_name" | tar -xf - --exclude='*..*'
35+
else
36+
tar -xzvf "$archive_name" --exclude='*..*'
37+
fi
38+
echoerr "> Done."
39+
40+
echoerr "> Cleaning up."
41+
rm "$archive_name"
42+
echoerr "> Done."
43+
exit 0
44+
}
45+
1946
# Check for help flag
2047
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
2148
usage
2249
fi
2350

51+
# Check for fallback-to-latest flag
52+
USE_LATEST_FALLBACK=false
53+
if [ "${1:-}" = "--fallback-to-latest" ]; then
54+
USE_LATEST_FALLBACK=true
55+
echoerr "> Fallback to latest enabled"
56+
fi
57+
2458
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2559
CONTRACTS_DIR="$SCRIPT_DIR/../.."
2660

@@ -41,57 +75,43 @@ echoerr "> Checking for existing artifacts..."
4175
if [ "$HAS_ZSTD" = true ]; then
4276
archive_name_zst="artifacts-v1-$checksum.tar.zst"
4377
exists_zst=$(curl -s -o /dev/null --fail -LI "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst" || echo "fail")
44-
78+
4579
if [ "$exists_zst" != "fail" ]; then
46-
echoerr "> Found .tar.zst artifacts. Downloading..."
47-
curl -o "$archive_name_zst" "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst"
48-
echoerr "> Done."
49-
50-
echoerr "> Cleaning up existing artifacts..."
51-
rm -rf artifacts
52-
rm -rf forge-artifacts
53-
rm -rf cache
54-
echoerr "> Done."
55-
56-
echoerr "> Extracting existing artifacts..."
57-
zstd -dc "$archive_name_zst" | tar -xf -
58-
echoerr "> Done."
59-
60-
echoerr "> Cleaning up."
61-
rm "$archive_name_zst"
62-
echoerr "> Done."
63-
exit 0
80+
download_and_extract "$archive_name_zst"
81+
fi
82+
83+
# Try latest fallback if enabled
84+
if [ "$USE_LATEST_FALLBACK" = true ]; then
85+
echoerr "> Exact checksum not found, trying latest artifacts..."
86+
archive_name_zst="artifacts-v1-latest.tar.zst"
87+
exists_latest_zst=$(curl -s -o /dev/null --fail -LI "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_zst" || echo "fail")
88+
89+
if [ "$exists_latest_zst" != "fail" ]; then
90+
download_and_extract "$archive_name_zst"
91+
fi
6492
fi
6593
fi
6694

6795
archive_name_gz="artifacts-v1-$checksum.tar.gz"
6896
exists_gz=$(curl -s -o /dev/null --fail -LI "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz" || echo "fail")
6997

7098
if [ "$exists_gz" == "fail" ]; then
71-
echoerr "> No existing artifacts found, exiting."
72-
exit 0
73-
fi
74-
75-
if [ "$HAS_ZSTD" = true ]; then
76-
echoerr "> Only .tar.gz artifacts available (zstd format not found)."
77-
else
78-
echoerr "> Found .tar.gz artifacts (zstd not available)."
99+
# Try latest fallback if enabled
100+
if [ "$USE_LATEST_FALLBACK" = true ]; then
101+
echoerr "> Exact checksum not found, trying latest artifacts..."
102+
archive_name_gz="artifacts-v1-latest.tar.gz"
103+
exists_latest_gz=$(curl -s -o /dev/null --fail -LI "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz" || echo "fail")
104+
105+
if [ "$exists_latest_gz" == "fail" ]; then
106+
echoerr "> No existing artifacts found (including latest), exiting."
107+
exit 0
108+
fi
109+
110+
echoerr "> Found latest .tar.gz artifacts."
111+
else
112+
echoerr "> No existing artifacts found, exiting."
113+
exit 0
114+
fi
79115
fi
80116

81-
echoerr "> Cleaning up existing artifacts..."
82-
rm -rf artifacts
83-
rm -rf forge-artifacts
84-
rm -rf cache
85-
echoerr "> Done."
86-
87-
echoerr "> Downloading artifacts..."
88-
curl -o "$archive_name_gz" "https://storage.googleapis.com/oplabs-contract-artifacts/$archive_name_gz"
89-
echoerr "> Done."
90-
91-
echoerr "> Extracting existing artifacts..."
92-
tar -xzvf "$archive_name_gz"
93-
echoerr "> Done."
94-
95-
echoerr "> Cleaning up."
96-
rm "$archive_name_gz"
97-
echoerr "> Done."
117+
download_and_extract "$archive_name_gz"

0 commit comments

Comments
 (0)