Skip to content

Commit 5689959

Browse files
authored
Merge branch 'main' into zeus-V2-json-configs
2 parents 939e783 + bfd6a52 commit 5689959

7 files changed

Lines changed: 597 additions & 2 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Collect local binary sizes and write a JSON artifact.
3+
# The report job handles baseline comparison.
4+
#
5+
# Required env: RUNNER_OS
6+
7+
set -euo pipefail
8+
9+
RUNNER_OS="${RUNNER_OS:-unknown}"
10+
11+
echo "Collecting local binary sizes..."
12+
13+
python3 - "$RUNNER_OS" <<'PYEOF'
14+
import json, os, sys
15+
16+
runner_os = sys.argv[1]
17+
skip_ext = ('.sig', '.jar', '.rpm', '.deb', '.pkg', '.msi', '.tar.gz', '.gz', '.zip')
18+
skip_names = ('CWAGENT_VERSION', 'buildMSI.zip')
19+
20+
binaries = {}
21+
for root, dirs, files in os.walk("build/bin"):
22+
for fname in files:
23+
filepath = os.path.join(root, fname)
24+
rel_path = os.path.relpath(filepath, "build/bin")
25+
segments = rel_path.replace("\\", "/").split("/")
26+
if len(segments) != 2:
27+
continue
28+
if any(fname.endswith(ext) for ext in skip_ext):
29+
continue
30+
if fname in skip_names:
31+
continue
32+
key = "/".join(segments)
33+
binaries[key] = os.path.getsize(filepath)
34+
35+
output_file = f"size-report-{runner_os}.json"
36+
with open(output_file, "w") as f:
37+
json.dump({"binaries": binaries}, f, indent=2)
38+
39+
print(f"Wrote {output_file} ({len(binaries)} binaries)")
40+
PYEOF
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
# Record binary sizes to DynamoDB after a main merge.
3+
# Reads sizes from S3 (binaries already uploaded by BuildAndUpload job).
4+
#
5+
# Required env: S3_BUCKET, COMMIT_HASH, COMMIT_DATE, TAG (optional)
6+
7+
set -euo pipefail
8+
9+
TABLE_NAME="CWABinarySizes"
10+
S3_BUCKET="${S3_BUCKET:?S3_BUCKET is required}"
11+
COMMIT_HASH="${COMMIT_HASH:?COMMIT_HASH is required}"
12+
COMMIT_DATE="${COMMIT_DATE:?COMMIT_DATE is required}"
13+
TAG="${TAG:-}"
14+
REGION="us-west-2"
15+
16+
S3_PREFIX="integration-test/binary/${COMMIT_HASH}/"
17+
18+
echo "Collecting binary sizes from S3 (${COMMIT_HASH:0:12})..."
19+
20+
ITEM_JSON=$(
21+
aws s3 ls "s3://${S3_BUCKET}/${S3_PREFIX}" --recursive --region "$REGION" |
22+
awk '{print $3, $4}' |
23+
python3 - "$S3_PREFIX" "$COMMIT_HASH" "$COMMIT_DATE" "$TAG" <<'PYEOF'
24+
import sys, json
25+
26+
prefix = sys.argv[1]
27+
commit_hash = sys.argv[2]
28+
commit_date = sys.argv[3]
29+
tag = sys.argv[4]
30+
31+
skip_ext = ('.sig', '.jar', '.rpm', '.deb', '.pkg', '.msi', '.tar.gz', '.gz', '.zip')
32+
skip_names = ('CWAGENT_VERSION', 'buildMSI.zip')
33+
34+
binaries = {}
35+
for line in sys.stdin:
36+
line = line.strip()
37+
if not line:
38+
continue
39+
parts = line.split(' ', 1)
40+
if len(parts) != 2:
41+
continue
42+
size, key = int(parts[0]), parts[1]
43+
rel_path = key[len(prefix):] if key.startswith(prefix) else key
44+
segments = rel_path.split('/')
45+
if len(segments) != 2:
46+
continue
47+
filename = segments[1]
48+
if any(filename.endswith(ext) for ext in skip_ext):
49+
continue
50+
if filename in skip_names:
51+
continue
52+
binaries[rel_path] = {"N": str(size)}
53+
54+
if not binaries:
55+
sys.exit(1)
56+
57+
record_type = "release" if tag else "commit"
58+
item = {
59+
"CommitHash": {"S": commit_hash},
60+
"CommitDate": {"N": commit_date},
61+
"Branch": {"S": "main"},
62+
"RecordType": {"S": record_type},
63+
"Binaries": {"M": binaries},
64+
}
65+
if tag:
66+
item["Tag"] = {"S": tag}
67+
68+
print(json.dumps(item))
69+
PYEOF
70+
) || {
71+
echo "No binaries found in S3, skipping."
72+
exit 0
73+
}
74+
75+
RECORD_TYPE=$(echo "$ITEM_JSON" | python3 -c "import json,sys; print(json.load(sys.stdin)['RecordType']['S'])")
76+
77+
if [[ "$RECORD_TYPE" == "release" ]]; then
78+
aws dynamodb put-item \
79+
--table-name "$TABLE_NAME" \
80+
--item "$ITEM_JSON" \
81+
--region "$REGION"
82+
else
83+
err=$(aws dynamodb put-item \
84+
--table-name "$TABLE_NAME" \
85+
--item "$ITEM_JSON" \
86+
--condition-expression "attribute_not_exists(CommitHash) OR RecordType <> :release" \
87+
--expression-attribute-values '{":release": {"S": "release"}}' \
88+
--region "$REGION" 2>&1) || {
89+
if echo "$err" | grep -q "ConditionalCheckFailedException"; then
90+
echo "Skipped (existing release entry)"
91+
else
92+
echo "$err" >&2
93+
exit 1
94+
fi
95+
}
96+
fi
97+
98+
echo "Recorded binary sizes for ${COMMIT_HASH:0:12} (type=${RECORD_TYPE}, tag=${TAG:-none})"

0 commit comments

Comments
 (0)