-
Notifications
You must be signed in to change notification settings - Fork 106
/
build_binaries.sh
82 lines (72 loc) · 2.52 KB
/
build_binaries.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Remove previously built binaries.
rm -rf dist/
# Define version based on git commit hash.
SWG_VERSION=$(git rev-parse HEAD)
# Enable these experiments by default.
# TODO: b/279620260 - Clean up flag after launch is finalized.
# TODO: b/279620593 - Clean up flag after launch is finalized.
EXPERIMENTS="disable-desktop-miniprompt,logging-audience-activity"
# Build template binaries, in parallel.
function build_template_binary() {
local -r target="$1"
local -r experiments="$2"
shift 2
local filename="swg"
if [[ $target != "classic" ]]; then
filename="$filename-$target"
fi
filename="$filename.template.js"
npx vite build -- \
"--assets=https://news.google.com/swg/js/v1" \
"--experiments=$experiments" \
"--frontend=https://FRONTEND.com" \
"--frontendCache=nocache" \
"--minifiedBasicName=$filename" \
"--minifiedGaaName=$filename" \
"--minifiedName=$filename" \
"--payEnvironment=___PAY_ENVIRONMENT___" \
"--playEnvironment=___PLAY_ENVIRONMENT___" \
"--swgVersion=$SWG_VERSION" \
"--target=$target"
}
build_template_binary basic $EXPERIMENTS &
build_template_binary classic $EXPERIMENTS &
build_template_binary gaa $EXPERIMENTS &
wait
# Create binaries for each environment, in parallel.
function create_binaries_for_environment() {
local -r target="$1"
local -r frontend="$2"
local -r pay_environment="$3"
local -r play_environment="$4"
shift 4
for variant in "" "-basic" "-gaa"; do
# Copy files.
cp dist/swg$variant.template.js dist/swg$variant$target.js
cp dist/swg$variant.template.js.map dist/swg$variant$target.js.map
# Replace values.
sed -i "s|https://FRONTEND.com|$frontend|g" dist/swg$variant$target*
sed -i "s|___PAY_ENVIRONMENT___|$pay_environment|g" dist/swg$variant$target*
sed -i "s|___PLAY_ENVIRONMENT___|$play_environment|g" dist/swg$variant$target*
sed -i "s|swg$variant.template.js.map|swg$variant$target.js.map|g" dist/swg$variant$target*
done
}
create_binaries_for_environment \
"" \
"https://news.google.com" \
"PRODUCTION" \
"PROD" &
create_binaries_for_environment \
"-autopush" \
"https://subscribe-autopush.sandbox.google.com" \
"PRODUCTION" \
"AUTOPUSH" &
create_binaries_for_environment \
"-qual" \
"https://subscribe-qual.sandbox.google.com" \
"SANDBOX" \
"STAGING" &
wait
# Remove template binaries.
rm dist/*template.js*