-
Notifications
You must be signed in to change notification settings - Fork 1
439 lines (388 loc) · 18.5 KB
/
Copy pathdev-pipeline.yml
File metadata and controls
439 lines (388 loc) · 18.5 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
name: DEV Pipeline - Build and Upload to NativeBridge
# ============================================================================
# DEV PIPELINE
# ============================================================================
# Purpose: Build app and upload to NativeBridge
#
# Triggers:
# 1. Push to 'main' or 'develop' branch (if commit message contains "nativebridge")
# 2. Manual workflow dispatch (can configure parameters)
#
# Outputs:
# - app_id: NativeBridge app ID
# - nb_version: NativeBridge version
# - magic_link: App installation link
#
# Next Step:
# - Automatically triggers QA Pipeline if upload succeeds
# ============================================================================
on:
# Trigger 1: Push to specific branches
push:
branches:
# - main
- develop
- staging
# Trigger 2: Manual trigger with configurable parameters
workflow_dispatch:
inputs:
upload_to_nativebridge:
description: 'Upload to NativeBridge? (If false, just builds)'
required: true
default: 'true'
type: choice
options:
- 'true'
- 'false'
trigger_qa_pipeline:
description: 'Trigger QA Pipeline after upload?'
required: true
default: 'true'
type: choice
options:
- 'true'
- 'false'
device_name:
description: 'Device for QA tests (default: Samsung Galaxy S22 Ultra)'
required: false
default: 'Samsung Galaxy S22 Ultra'
env:
DEFAULT_DEVICE: 'Samsung Galaxy S22 Ultra'
DEFAULT_REGION: 'ind'
# Permissions required for workflow to trigger other workflows
permissions:
contents: read
actions: write
jobs:
# ==========================================================================
# Job 1: Check if we should upload to NativeBridge
# For push triggers: Check if commit message contains "nativebridge"
# For manual triggers: Use the input parameter
# ==========================================================================
check-trigger:
name: Check Upload Trigger
runs-on: ubuntu-latest
outputs:
should_upload: ${{ steps.check.outputs.should_upload }}
trigger_reason: ${{ steps.check.outputs.trigger_reason }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # Need last 2 commits to get commit message
- name: Check if upload should happen
id: check
run: |
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ DEV Pipeline - Upload Check ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
# Check if this is a manual trigger
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
SHOULD_UPLOAD="${{ github.event.inputs.upload_to_nativebridge }}"
REASON="Manual trigger (upload_to_nativebridge: $SHOULD_UPLOAD)"
echo "✓ Trigger: Manual workflow dispatch"
echo "✓ Upload to NativeBridge: $SHOULD_UPLOAD"
else
# This is a push trigger - check commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "✓ Trigger: Push to ${{ github.ref_name }}"
echo "✓ Commit message: $COMMIT_MSG"
if echo "$COMMIT_MSG" | grep -qi "nativebridge"; then
SHOULD_UPLOAD="true"
REASON="Push trigger (commit contains 'nativebridge')"
echo "✓ Commit message contains 'nativebridge' - will upload"
else
SHOULD_UPLOAD="false"
REASON="Push trigger (commit does not contain 'nativebridge')"
echo "✓ Commit message does not contain 'nativebridge' - skip upload"
fi
fi
echo ""
echo "should_upload=$SHOULD_UPLOAD" >> $GITHUB_OUTPUT
echo "trigger_reason=$REASON" >> $GITHUB_OUTPUT
echo "Decision: SHOULD_UPLOAD=$SHOULD_UPLOAD"
echo "Reason: $REASON"
# ==========================================================================
# Job 2: Build Application
# TODO: Replace this with your actual build steps
# For now, using pre-built APK from builds/ folder
# ==========================================================================
build-app:
name: Build Application
needs: [check-trigger]
runs-on: ubuntu-latest
outputs:
apk_path: ${{ steps.prepare.outputs.apk_path }}
apk_size: ${{ steps.prepare.outputs.apk_size }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Display Build Info
run: |
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ Building Application ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo "Branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
echo "Upload to NativeBridge: ${{ needs.check-trigger.outputs.should_upload }}"
echo ""
# ========================================================================
# TODO: Add your actual build steps here
# ========================================================================
# Example Android build steps:
#
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# distribution: 'temurin'
# java-version: '17'
#
# - name: Setup Android SDK
# uses: android-actions/setup-android@v3
#
# - name: Build APK
# run: |
# cd android
# ./gradlew assembleRelease
#
# - name: Sign APK
# run: |
# # Add signing steps here
#
# - name: Copy APK to builds folder
# run: |
# mkdir -p builds/
# cp android/app/build/outputs/apk/release/app-release.apk \
# builds/NativeBridge-Production.apk
# ========================================================================
- name: Prepare APK (Using Pre-built)
id: prepare
run: |
echo "📦 Using pre-built APK from builds/ folder"
echo " (Replace this step with actual build steps in production)"
echo ""
# Check if APK exists
if [ ! -f "builds/NativeBridge-Production.apk" ]; then
echo "❌ ERROR: Pre-built APK not found at builds/NativeBridge-Production.apk"
echo ""
echo "Please either:"
echo "1. Add your APK to builds/NativeBridge-Production.apk, OR"
echo "2. Replace this step with actual build steps (see TODO above)"
exit 1
fi
APK_PATH="builds/NativeBridge-Production.apk"
APK_SIZE=$(ls -lh "$APK_PATH" | awk '{print $5}')
echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT
echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT
echo "✓ APK ready: $APK_PATH ($APK_SIZE)"
- name: Upload APK as Build Artifact
uses: actions/upload-artifact@v4
with:
name: app-build-${{ github.sha }}
path: ${{ steps.prepare.outputs.apk_path }}
retention-days: 30
- name: Build Summary
run: |
echo "### Build Complete ✅" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**APK Size:** ${{ steps.prepare.outputs.apk_size }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Next:** Upload to NativeBridge = ${{ needs.check-trigger.outputs.should_upload }}" >> $GITHUB_STEP_SUMMARY
# ==========================================================================
# Job 3: Upload to NativeBridge
# Only runs if should_upload is true
# ==========================================================================
upload-to-nativebridge:
name: Upload to NativeBridge
needs: [check-trigger, build-app]
if: needs.check-trigger.outputs.should_upload == 'true'
runs-on: ubuntu-latest
outputs:
app_id: ${{ steps.upload.outputs.app_id }}
nb_version: ${{ steps.upload.outputs.nb_version }}
magic_link: ${{ steps.upload.outputs.magic_link }}
upload_success: ${{ steps.upload.outputs.success }}
steps:
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: app-build-${{ github.sha }}
path: apk-to-upload
- name: Upload APK to NativeBridge
id: upload
env:
NATIVEBRIDGE_API_KEY: ${{ secrets.NATIVEBRIDGE_API_KEY }}
run: |
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ Uploading to NativeBridge ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
APK_PATH=$(find apk-to-upload -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
echo "❌ ERROR: APK not found"
exit 1
fi
if [ -z "$NATIVEBRIDGE_API_KEY" ]; then
echo "❌ ERROR: NATIVEBRIDGE_API_KEY not configured"
exit 1
fi
echo "📦 APK: $APK_PATH"
echo "🔑 API Key: ${NATIVEBRIDGE_API_KEY:0:15}..."
echo ""
echo "Uploading..."
# Upload to NativeBridge
RESPONSE=$(curl -X POST https://api.nativebridge.io/v1/application \
-H "X-Api-Key: $NATIVEBRIDGE_API_KEY" \
-F "file=@$APK_PATH" \
-F "accessType=public" \
-F "versionAction=create_new_version" \
-F "sendNotification=true" \
-w "\n%{http_code}" \
-s)
# Parse response
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
echo "✅ SUCCESS! APK uploaded to NativeBridge"
echo ""
# Extract app_id
APP_ID=$(echo "$BODY" | grep -o '"id":"[^"]*"' | sed 's/"id":"//;s/"//')
# Extract nb_version (NativeBridge version)
NB_VERSION=$(echo "$BODY" | grep -o '"version":"[^"]*"' | sed 's/"version":"//;s/"//')
# Extract magic_link
MAGIC_LINK=$(echo "$BODY" | grep -o '"magicLink":"[^"]*"' | sed 's/"magicLink":"//;s/"//')
# Validate extractions
if [ -z "$APP_ID" ]; then
echo "❌ ERROR: Could not extract app_id from response"
echo "Response: $BODY"
exit 1
fi
if [ -z "$NB_VERSION" ]; then
echo "⚠️ WARNING: Could not extract nb_version, using 'latest'"
NB_VERSION="latest"
fi
if [ -z "$MAGIC_LINK" ]; then
echo "⚠️ WARNING: Could not extract magic_link"
MAGIC_LINK="N/A"
fi
# Set outputs
echo "app_id=$APP_ID" >> $GITHUB_OUTPUT
echo "nb_version=$NB_VERSION" >> $GITHUB_OUTPUT
echo "magic_link=$MAGIC_LINK" >> $GITHUB_OUTPUT
echo "success=true" >> $GITHUB_OUTPUT
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ Upload Complete! ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo " App ID: $APP_ID"
echo " NB Version: $NB_VERSION"
echo " Magic Link: $MAGIC_LINK"
echo ""
else
echo "❌ Upload failed (HTTP $HTTP_CODE)"
echo "Response: $BODY"
echo "success=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Upload Summary
run: |
echo "### Upload to NativeBridge ✅" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**App ID:** \`${{ steps.upload.outputs.app_id }}\`" >> $GITHUB_STEP_SUMMARY
echo "**NB Version:** \`${{ steps.upload.outputs.nb_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Magic Link:** [${{ steps.upload.outputs.magic_link }}](${{ steps.upload.outputs.magic_link }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Trigger Reason:** ${{ needs.check-trigger.outputs.trigger_reason }}" >> $GITHUB_STEP_SUMMARY
# ==========================================================================
# Job 4: Trigger QA Pipeline
# Only runs if upload succeeded and trigger_qa_pipeline is true
# ==========================================================================
trigger-qa-pipeline:
name: Trigger QA Pipeline
needs: [check-trigger, upload-to-nativebridge]
if: |
needs.upload-to-nativebridge.outputs.upload_success == 'true' &&
(github.event.inputs.trigger_qa_pipeline != 'false')
runs-on: ubuntu-latest
steps:
- name: Trigger QA Pipeline
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const deviceName = '${{ github.event.inputs.device_name }}' || '${{ env.DEFAULT_DEVICE }}';
const region = '${{ github.event.inputs.region }}' || '${{ env.DEFAULT_REGION }}';
console.log('╔══════════════════════════════════════════════════════════╗');
console.log('║ Triggering QA Pipeline ║');
console.log('╚══════════════════════════════════════════════════════════╝');
console.log('');
console.log('App ID:', '${{ needs.upload-to-nativebridge.outputs.app_id }}');
console.log('NB Version:', '${{ needs.upload-to-nativebridge.outputs.nb_version }}');
console.log('Device:', deviceName);
console.log('Region:', region);
console.log('');
const result = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'qa-pipeline.yml',
ref: context.ref,
inputs: {
app_id: '${{ needs.upload-to-nativebridge.outputs.app_id }}',
nb_version: '${{ needs.upload-to-nativebridge.outputs.nb_version }}',
device_name: deviceName,
region: region,
triggered_by: 'dev-pipeline'
}
});
console.log('✅ QA Pipeline triggered successfully!');
console.log('');
- name: Summary
run: |
echo "### QA Pipeline Triggered ✅" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The QA Pipeline has been automatically triggered with:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **App ID:** \`${{ needs.upload-to-nativebridge.outputs.app_id }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **NB Version:** \`${{ needs.upload-to-nativebridge.outputs.nb_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Device:** ${{ github.event.inputs.device_name || env.DEFAULT_DEVICE }}" >> $GITHUB_STEP_SUMMARY
echo "- **Region:** ${{ github.event.inputs.region || env.DEFAULT_REGION }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the **Actions** tab to see the QA Pipeline run." >> $GITHUB_STEP_SUMMARY
# ==========================================================================
# Job 5: Final Summary
# ==========================================================================
final-summary:
name: Pipeline Summary
needs: [check-trigger, build-app, upload-to-nativebridge, trigger-qa-pipeline]
if: always()
runs-on: ubuntu-latest
steps:
- name: Generate Summary
run: |
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ DEV Pipeline Complete ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo "Trigger: ${{ needs.check-trigger.outputs.trigger_reason }}"
echo "Build: ${{ needs.build-app.result }}"
echo "Upload: ${{ needs.upload-to-nativebridge.result }}"
echo "QA Trigger: ${{ needs.trigger-qa-pipeline.result }}"
echo ""
if [ "${{ needs.upload-to-nativebridge.result }}" == "success" ]; then
echo "✅ App uploaded to NativeBridge"
echo " App ID: ${{ needs.upload-to-nativebridge.outputs.app_id }}"
echo " NB Version: ${{ needs.upload-to-nativebridge.outputs.nb_version }}"
else
echo "⏭️ Upload skipped or failed"
fi
if [ "${{ needs.trigger-qa-pipeline.result }}" == "success" ]; then
echo "✅ QA Pipeline triggered"
elif [ "${{ needs.trigger-qa-pipeline.result }}" == "skipped" ]; then
echo "⏭️ QA Pipeline not triggered"
else
echo "❌ QA Pipeline trigger failed"
fi