-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpush-bundle-size.sh
executable file
·64 lines (52 loc) · 1.69 KB
/
push-bundle-size.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -euo pipefail
# Function to log messages
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Check if running in GitHub Actions
if [[ "${GITHUB_ACTIONS:-}" != 'true' ]]; then
log "Error: This script must be run in a GitHub Actions environment"
exit 1
fi
if [[ -z "${GITHUB_ACTOR:-}" ]]; then
log "Error: GITHUB_ACTOR environment variable must be set"
exit 1
fi
# Check for GITHUB_TOKEN
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
log "Error: GITHUB_TOKEN environment variable must be set"
exit 1
fi
# Set up git configuration
git config --global user.email "[email protected]"
git config --global user.name "MetaMask Bot"
# Create a temporary directory
temp_dir="$(mktemp -d)"
trap 'rm -rf "$temp_dir"' EXIT
# Clone the repository
repo_url="https://$GITHUB_ACTOR:[email protected]/metamask/mobile_bundlesize_stats.git"
if ! git clone "$repo_url" "$temp_dir"; then
log "Error: Failed to clone repository"
exit 1
fi
# Get commit ID and bundle size
commit_id="$(git rev-parse HEAD)"
bundle_size="$(stat -f%z 'ios/main.jsbundle' 2>/dev/null || stat -c%s 'ios/main.jsbundle')"
timestamp="$(date +%s%3N)"
output_file="$temp_dir/stats/bundle_size_data.js"
./scripts/update_bundle_size.py "$output_file" "$commit_id" "$bundle_size" "$timestamp"
cd "$temp_dir"
# Commit and push changes
git add "$output_file"
if git commit -m "Add bundle size for commit: ${commit_id}"; then
if git push origin HEAD:main; then
log "Success: Bundle size data updated and pushed to main branch"
else
log "Error: Failed to push changes"
exit 1
fi
else
log "Info: No changes to commit"
fi
log "Script completed successfully"