Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / pass-extension / tools / build-all.sh
blobe51f8fc1253080b67a8f64b95256025aa36190c7
1 #!/usr/bin/env bash
2 set -euo pipefail
4 REPODIR="$(git rev-parse --show-toplevel)"
5 PASSDIR="$REPODIR/applications/pass-extension"
6 VERSION="$(jq -r .version <"$PASSDIR/manifest-chrome.json")"
7 ARTEFACTSDIR="$REPODIR/build"
8 OUTDIR="$(mktemp -d)"
9 COMMIT="$(git rev-parse --short HEAD)"
10 BUILD_ID="ProtonPass-${VERSION}-${COMMIT}"
12 function on_enter {
13 echo "Building $1..."
14 cd "$PASSDIR" && rm -rf dist
17 function on_leave {
18 rm -rf "${OUTDIR:-}/*"
19 for arg in "$@"; do
20 printf "\t✅ %s\n" "$arg"
21 done
24 function set_manifest_key {
25 local key=$(jq -r ".[\"$2\"]" "$PASSDIR/manifest-keys.json")
26 jq --indent 4 --arg key "$key" '. + {"key": $key}' "$1" >manifest.json.tmp && mv manifest.json.tmp "$1"
29 function build_chromium_black {
30 on_enter "Chromium (Black)"
31 BUILD_TARGET=chrome MANIFEST_KEY="" yarn run build:extension:dev >/dev/null
33 cd dist
35 # QA Black Chrome Build
36 set_manifest_key "./manifest.json" "chrome:production"
37 zip -rqX "$ARTEFACTSDIR/chrome/$BUILD_ID.black.zip" "."
39 # QA Black Edge Build
40 set_manifest_key "./manifest.json" "edge:production"
41 zip -rqX "$ARTEFACTSDIR/edge/$BUILD_ID.black.zip" "."
43 on_leave "chrome/$BUILD_ID.black.zip" "edge/$BUILD_ID.black.zip"
46 function build_chromium_prod {
47 on_enter "Chromium (Prod)"
49 # store versions should not have a `key` in the manifest
50 RELEASE=true BUILD_TARGET=chrome MANIFEST_KEY="" yarn run build:extension >/dev/null
52 cd dist
54 # Chromium store version for release
55 zip -rqX "$ARTEFACTSDIR/release/$BUILD_ID-chromium.zip" "."
57 # QA Production Chrome build
58 set_manifest_key "./manifest.json" "chrome:production"
59 zip -rqX "$ARTEFACTSDIR/chrome/$BUILD_ID.zip" "."
61 # QA Production Edge build
62 set_manifest_key "./manifest.json" "edge:production"
63 zip -rqX "$ARTEFACTSDIR/edge/$BUILD_ID.zip" "."
65 on_leave "release/$BUILD_ID-chromium.zip" "chrome/$BUILD_ID.zip" "edge/$BUILD_ID.zip"
68 function build_firefox_black {
69 on_enter "Firefox (Black)"
70 BUILD_TARGET=firefox yarn run build:extension:dev >/dev/null
71 cd dist
72 zip -rqX "$ARTEFACTSDIR/firefox/$BUILD_ID.black.zip" "."
74 on_leave "firefox/$BUILD_ID.black.zip"
77 function build_firefox_prod {
78 on_enter "Firefox (Sources)"
79 BUILD_TARGET=firefox NODE_ENV=production yarn run config
80 # Preserve config.ts because the `yarn` postinstall script will overwrite it
81 cp src/app/config.ts src/app/config.ff-release.ts
82 cd ../../
84 zip -rqX "$OUTDIR/$BUILD_ID-FF-sources.zip" \
85 "applications/pass-extension" \
86 "packages" \
87 "utilities" \
88 "yarn.lock" \
89 ".yarn" \
90 ".yarnrc.yml" \
91 ./*.js \
92 ./*.json \
93 ./*.mjs \
94 -x "*/.DS_Store" \
95 -x "*/node_modules/*" \
96 -x "packages/config/*" \
97 -x "applications/pass-extension/dist/*" \
98 -x "applications/pass-extension/*.md" \
99 -x ".yarn/install-state.gz" \
100 -x ".yarn/cache/*"
102 cd "$PASSDIR"
103 zip -uqX "$OUTDIR/$BUILD_ID-FF-sources.zip" "FIREFOX_REVIEWERS.md"
104 mv "$OUTDIR/$BUILD_ID-FF-sources.zip" "$ARTEFACTSDIR/release"
105 on_leave "release/$BUILD_ID-FF-sources.zip"
107 on_enter "Firefox (Prod)"
108 mkdir -p "$OUTDIR/$BUILD_ID-FF-sources"
109 cd "$OUTDIR/$BUILD_ID-FF-sources"
110 unzip -q "$ARTEFACTSDIR/release/$BUILD_ID-FF-sources.zip"
111 yarn install --no-immutable >/dev/null
112 cd applications/pass-extension
113 RELEASE=true yarn run build:extension:ff >/dev/null
114 cd dist
115 zip -rqX "$ARTEFACTSDIR/release/$BUILD_ID-FF.zip" "."
116 on_leave "release/$BUILD_ID-FF.zip"
119 # Print debug vars
120 echo "Building for all platforms... This may take a while."
121 printf "\tNode\t%s (%s)\n" "$(node --version)" "$(which node)"
122 printf "\tnpm\tv%s (%s)\n" "$(npm --version)" "$(which npm)"
123 printf "\tYarn\tv%s (%s)\n" "$(yarn --version)" "$(which yarn)"
124 for var in "REPODIR" "PASSDIR" "VERSION" "ARTEFACTSDIR" "OUTDIR" "COMMIT" "BUILD_ID"; do
125 printf "\t%s = %s\n" "${var}" "${!var}"
126 done
128 # Validate dependencies
129 echo "Validating yarn.lock..."
130 if [ -z ${CI+n} ]; then
131 cd "$REPODIR"
132 yarn install --immutable --immutable-cache >/dev/null
133 printf "\t✅ %s\n" "OK"
134 else
135 printf "\t⚠️ Skipped, \$CI var is already set\n"
138 # Set up clean artefacts location
139 rm -rf "${ARTEFACTSDIR:-}" && mkdir -p "$ARTEFACTSDIR"
140 mkdir -p "$ARTEFACTSDIR/chrome"
141 mkdir -p "$ARTEFACTSDIR/edge"
142 mkdir -p "$ARTEFACTSDIR/firefox"
143 mkdir -p "$ARTEFACTSDIR/safari"
144 mkdir -p "$ARTEFACTSDIR/release"
146 # Execute individual builds
147 build_firefox_black
148 build_firefox_prod
150 build_chromium_prod
151 build_chromium_black