-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·191 lines (147 loc) · 6.86 KB
/
entrypoint.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Add Android SDK binaries to the global PATH
export PATH="$PATH":/tmp/android/sdk/cmdline-tools/latest/bin;
# Define the path to the Android SDK
export ANDROID_HOME=/tmp/android/sdk;
# Define the path to the artifacts output
export ARTIFACTS_PATH=$(pwd)/artifacts;
# Define the path to the temporary WearOS root copy
export WEAROS_TEMP_PATH=$(pwd)/wearos;
set -e; # quit on error
echo '=> Installing Yarn dependencies...';
yarn;
echo '=> Installing packages with NPM...';
npm i;
if [[ "$ACTION" == 'run' ]]; then
npx expo start --clear;
exit $?;
else
ACTION='build';
fi;
if [[ -z $MODE ]] || [[ "$MODE" == '' ]]; then
MODE='publish';
fi;
if [[ "$MODE" == 'publish' ]] && [[ "$GITHUB_TOKEN" == '' ]]; then
echo 'Cannot publish releases without a GitHub token. Provide a token or set MODE=test instead. - GITHUB_TOKEN';
exit 1;
fi;
echo 'Starting operation with ACTION = '"$ACTION"' and MODE = '"$MODE"'...';
echo '';
echo '=> Looking for keystore...';
if [[ "$RELEASE_KEYSTORE" == '' ]]; then
echo '=================================================================================';
echo 'WARNING: Missing keystore, release builds will NOT be created. - RELEASE_KEYSTORE';
echo '=================================================================================';
fi;
if [[ "$RELEASE_KEYSTORE_PASSPHRASE" == '' ]]; then
echo '=======================================================================================================';
echo 'WARNING: Missing keystore passphrase, release builds will NOT be created. - RELEASE_KEYSTORE_PASSPHRASE';
echo '=======================================================================================================';
fi;
echo '=> Looking for Gradle properties...';
if [[ "$GRADLE_PROPERTIES" == '' ]]; then
echo '===========================================================================================';
echo 'WARNING: Missing Gradle properties, release builds will NOT be created. - GRADLE_PROPERTIES';
echo '===========================================================================================';
exit 1;
fi;
if [[ "$RELEASE_KEYSTORE" != '' ]] && [[ "$RELEASE_KEYSTORE_PASSPHRASE" != '' ]] && [[ "$GRADLE_PROPERTIES" != '' ]]; then
ENABLE_RELEASE_BUILDS=true;
fi;
echo '=> Setting the current directory ('"$(pwd)"') as a safe directory for Git...';
git config --global --add safe.directory $(pwd);
echo '=> Creating artifacts directory as '"$ARTIFACTS_PATH"'...';
mkdir -p "$ARTIFACTS_PATH";
echo '=> Creating WearOS temporary path directory as '"$WEAROS_TEMP_PATH"'...';
mkdir -p "$WEAROS_TEMP_PATH";
if [[ "$ENABLE_RELEASE_BUILDS" == 'true' ]]; then
echo '=> Storing temporary '"$HOME"'/.gradle/gradle.properties file...';
mkdir -p "$HOME"/.gradle && printf -- "$GRADLE_PROPERTIES" > "$HOME"/.gradle/gradle.properties;
echo '=> Loading properties from '"$HOME"'/.gradle/gradle.properties...';
. "$HOME"/.gradle/gradle.properties;
echo '=> Storing temporary encrypted keystore to '"$MYAPP_UPLOAD_STORE_FILE"'.asc...';
printf -- "$RELEASE_KEYSTORE" > $MYAPP_UPLOAD_STORE_FILE.asc;
echo '=> Decrypting keystore...';
gpg -d --passphrase "$RELEASE_KEYSTORE_PASSPHRASE" --batch $MYAPP_UPLOAD_STORE_FILE.asc > $MYAPP_UPLOAD_STORE_FILE
fi;
echo '=> Installing the Android SDK platform and build tools...';
yes | sdkmanager 'build-tools;34.0.0';
yes | sdkmanager 'platform-tools';
echo '=> Accepting all SDK licenses...';
yes | sdkmanager --licenses;
echo '=> Compilling base debug AAB bundle and APK...';
npx react-native build-android --mode=debug;
cd android; ./gradlew assembleDebug; cd ..;
if [[ "$ENABLE_RELEASE_BUILDS" == 'true' ]]; then
echo '=> Compilling base release AAB bundle and APK...';
npx react-native build-android --mode=release;
cd android; ./gradlew assembleRelease; cd ..;
fi;
echo '=> Copying base artifacts to '"$ARTIFACTS_PATH"'...';
for file in $(find ./android/app/build/outputs -type f -regex '.*\(apk\|aab\)$'); do
FILE_NAME=$(basename "$file");
cp -v "$file" "$ARTIFACTS_PATH"'/'"$FILE_NAME";
done;
echo '=> Copying temporary files for the WearOS release and changing directory to '"$WEAROS_TEMP_PATH"'...';
rsync -r --exclude wearos . $WEAROS_TEMP_PATH;
cd $WEAROS_TEMP_PATH;
echo '=> Setting up WearOS releases...';
sed -i'' 's/<!-- WEAROS_USES_FEATURE_PLACEHOLDER -->/<uses-feature android:name="android.hardware.type.watch" \/>/' android/app/src/main/AndroidManifest.xml;
sed -i'' 's/<!-- WEAROS_META_PLACEHOLDER -->/<meta-data android:name="com.google.android.wearable.standalone" android:value="true"\/>/' android/app/src/main/AndroidManifest.xml;
VERSION_CODE=$( cat android/app/build.gradle | grep versionCode | sed 's/[^0-9]//g' );
sed -i'' 's/versionCode .*/versionCode '$(( $VERSION_CODE + 1))'/' android/app/build.gradle;
echo '=> Compilling WearOS debug AAB bundle and APK...';
npx react-native build-android --mode=debug;
cd android; ./gradlew assembleDebug; cd ..;
if [[ "$ENABLE_RELEASE_BUILDS" == 'true' ]]; then
echo '=> Compilling WearOS release AAB bundle and APK...';
npx react-native build-android --mode=release;
cd android; ./gradlew assembleRelease; cd ..;
fi;
echo '=> Copying WearOS artifacts to '"$ARTIFACTS_PATH"'...';
for file in $(find ./android/app/build/outputs -type f -regex '.*\(apk\|aab\)$'); do
FILE_NAME=$(basename "$file" | sed 's/\./-wear./');
cp -v "$file" "$ARTIFACTS_PATH"'/'"$FILE_NAME";
done;
if [[ "$MODE" != 'publish' ]]; then
exit 0;
fi;
# Collect information for the release
LAST_COMMIT_MESSAGE=$(git log -1 --pretty=%s);
LAST_COMMIT_SHA=$(git log -1 --pretty=%h);
echo '=> Creating release...';
RESPONSE=$(
curl -L \
--fail \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/releases \
-d '{
"tag_name":"'"$LAST_COMMIT_SHA"'",
"target_commitish":"master",
"name":"'"$LAST_COMMIT_SHA"'",
"body":"'"$LAST_COMMIT_MESSAGE"'",
"draft":false,
"prerelease":false,
"generate_release_notes":false
}'
);
echo '=> Parsing upload URL...';
RELEASE_ID=$(echo "$RESPONSE" | jq -cr '.id');
UPLOAD_URL=$(echo "$RESPONSE" | jq -cr '.upload_url' | cut -d'{' -f1);
echo '=> Uploading artifacts to release #'"$RELEASE_ID"' using the endpoint "'"$UPLOAD_URL"'"...';
for file in $(find "$ARTIFACTS_PATH"); do
FILE_NAME=$(basename "$file");
echo ' -> Uploading "'"$file"'" as "'"$FILE_NAME"'"...';
curl -s -L \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Content-Type: '$(file -b --mime-type "$file") \
-H 'Content-Length: '$(wc -c < "$file" | xargs) \
-T "$file" \
"$UPLOAD_URL"'?name='"$FILE_NAME";
done;
exit 0;