1+ name : Generate Assets Zips and Upload to Google Drive
2+
3+ permissions :
4+ id-token : write
5+ contents : write
6+ actions : write
7+
8+ on :
9+ workflow_dispatch :
10+
11+ jobs :
12+ generate_assets :
13+ name : Generate Assets Zips
14+ runs-on : self-hosted
15+ timeout-minutes : 30
16+
17+ steps :
18+ - name : Checkout repository
19+ uses : actions/checkout@v4
20+ with :
21+ ref : stage
22+
23+ - name : Install Git LFS
24+ run : |
25+ sudo apt-get update
26+ sudo apt-get install -y git-lfs
27+ git lfs install
28+ git lfs pull
29+
30+ - name : Check if Nix is installed
31+ id : check_nix
32+ run : |
33+ if command -v nix >/dev/null 2>&1; then
34+ echo "nix is installed"
35+ echo "nix_installed=true" >> $GITHUB_ENV
36+ else
37+ echo "nix is not installed"
38+ echo "nix_installed=false" >> $GITHUB_ENV
39+ fi
40+
41+ - name : Install Flox
42+ if : env.nix_installed == 'false'
43+ uses : flox/install-flox-action@v2
44+
45+ - name : Create google-services.json
46+ env :
47+ GOOGLE_SERVICES_JSON : ${{ secrets.GOOGLE_SERVICES_JSON }}
48+ run : |
49+ echo "$GOOGLE_SERVICES_JSON" > app/google-services.json
50+ echo "google-services.json created successfully"
51+
52+ - name : Authenticate to Google Cloud for Drive access
53+ id : auth_drive
54+ uses : google-github-actions/auth@v2
55+ with :
56+ workload_identity_provider : ${{ secrets.WIF_PROVIDER }}
57+ service_account : ${{ secrets.IDENTITY_EMAIL }}
58+ token_format : ' access_token'
59+ access_token_scopes : ' https://www.googleapis.com/auth/drive'
60+
61+ - name : Download latest documentation.db from Google Drive
62+ run : |
63+ DB_FILE_ID="${{ secrets.DOCUMENTATION_DB_FILE_ID }}"
64+ ACCESS_TOKEN="${{ steps.auth_drive.outputs.access_token }}"
65+
66+ if [ -z "DB_FILE_ID" ]; then
67+ echo "ERROR: DOCUMENTATION_DB_FILE_ID secret not set"
68+ echo "Please set the DOCUMENTATION_DB_FILE_ID secret in repository settings"
69+ exit 1
70+ fi
71+
72+ echo "Downloading documentation.db from Google Drive..."
73+
74+ mkdir -p assets
75+ curl -sL -H "Authorization: Bearer $ACCESS_TOKEN" \
76+ "https://www.googleapis.com/drive/v3/files/${DB_FILE_ID}?alt=media&supportsAllDrives=true&acknowledgeAbuse=true" \
77+ -o assets/documentation.db
78+
79+ if [ ! -f assets/documentation.db ]; then
80+ echo "ERROR: Failed to download documentation.db"
81+ exit 1
82+ fi
83+
84+ FILE_SIZE_BYTES=$(stat -c%s assets/documentation.db 2>/dev/null || stat -f%z assets/documentation.db 2>/dev/null)
85+ FILE_SIZE_HUMAN=$(du -h assets/documentation.db | cut -f1)
86+
87+ if [ "$FILE_SIZE_BYTES" -lt 1000000 ]; then
88+ echo "ERROR: Downloaded file is too small ($FILE_SIZE_HUMAN)"
89+ echo "This usually means the file was not found or service account lacks access"
90+ exit 1
91+ fi
92+
93+ echo "Successfully downloaded documentation.db ($FILE_SIZE_HUMAN)"
94+
95+ - name : Assemble Assets
96+ run : |
97+ flox activate -d flox/base -- ./gradlew :app:assembleAssets --no-daemon \
98+ -Dorg.gradle.jvmargs="-Xmx10g -XX:MaxMetaspaceSize=2g -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED" \
99+ -Dandroid.aapt2.daemonHeapSize=4096M \
100+ -Dorg.gradle.workers.max=1 \
101+ -Dorg.gradle.parallel=false
102+
103+ - name : V8 Assets Path
104+ id : assets_v8
105+ run : |
106+ assets_path="app/build/outputs/assets/assets-arm64-v8a.zip"
107+ echo "ASSETS_PATH=$assets_path" >> $GITHUB_OUTPUT
108+
109+ - name : V7 Assets Path
110+ id : assets_v7
111+ run : |
112+ assets_path="app/build/outputs/assets/assets-armeabi-v7a.zip"
113+ echo "ASSETS_PATH=$assets_path" >> $GITHUB_OUTPUT
114+
115+ - name : Upload asset zips to Google Drive
116+ run : |
117+ echo "Uploading assets v8 and v7 to Google Drive..."
118+ ls -la "${{ steps.assets_v8.outputs.ASSETS_PATH }}"
119+ ls -la "${{ steps.assets_v7.outputs.ASSETS_PATH }}"
120+
121+ ACCESS_TOKEN="${{ steps.auth_drive.outputs.access_token }}"
122+ V8_FILE_ID="${{ secrets.ASSETS_V8_FILE_ID }}"
123+ V7_FILE_ID="${{ secrets.ASSETS_V7_FILE_ID }}"
124+
125+ V8_PATH="${{ steps.assets_v8.outputs.ASSETS_PATH }}"
126+ V7_PATH="${{ steps.assets_v7.outputs.ASSETS_PATH }}"
127+
128+ # Upload v8
129+ response=$(curl -s -o /dev/null -w "%{http_code}" --fail -X PATCH \
130+ -H "Authorization: Bearer $ACCESS_TOKEN" \
131+ -F "file=@${V8_PATH};type=application/octet-stream" \
132+ "https://www.googleapis.com/upload/drive/v3/files/${V8_FILE_ID}?uploadType=media")
133+
134+ if [[ "$response" -ne 200 ]]; then
135+ echo "Upload of ${V8_PATH} failed with HTTP status $response"
136+ exit 1
137+ fi
138+
139+ # Upload v7
140+ response=$(curl -s -o /dev/null -w "%{http_code}" --fail -X PATCH \
141+ -H "Authorization: Bearer $ACCESS_TOKEN" \
142+ -F "file=@${V7_PATH};type=application/octet-stream" \
143+ "https://www.googleapis.com/upload/drive/v3/files/${V7_FILE_ID}?uploadType=media")
144+
145+ if [[ "$response" -ne 200 ]]; then
146+ echo "Upload of ${V7_PATH} failed with HTTP status $response"
147+ exit 1
148+ fi
149+
150+ echo "Upload complete."
151+
152+ - name : Send Rich Slack Notification
153+ env :
154+ SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK_URL }}
155+ run : |
156+ V8_PATH="${{ steps.assets_v8.outputs.ASSETS_PATH }}"
157+ V7_PATH="${{ steps.assets_v7.outputs.ASSETS_PATH }}"
158+
159+ jq -n \
160+ --arg v8_path "$V8_PATH" \
161+ --arg v7_path "$V7_PATH" \
162+ '{
163+ blocks: [
164+ {
165+ type: "header",
166+ text: {
167+ type: "plain_text",
168+ text: ":rocket: [Updated] New Assets Zips Available",
169+ emoji: true
170+ }
171+ },
172+ {
173+ type: "section",
174+ text: {
175+ type: "mrkdwn",
176+ text: "*V8 Path:* `$v8_path`"
177+ }
178+ },
179+ {
180+ type: "section",
181+ text: {
182+ type: "mrkdwn",
183+ text: "*V7 Path:* `$v7_path`"
184+ }
185+ }
186+ ]
187+ }' > payload.json
188+
189+ # curl -X POST -H "Content-type: application/json" --data @payload.json "$SLACK_WEBHOOK"
190+
191+ rm -f payload.json
192+ - name : Cleanup google-services.json
193+ if : always()
194+ run : |
195+ rm -f app/google-services.json
196+ echo "google-services.json cleaned up successfully"
0 commit comments