-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (149 loc) · 6.22 KB
/
Copy pathandroid.yml
File metadata and controls
202 lines (149 loc) · 6.22 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
name: Android CI/CD via Bitrise
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
release:
types: [published]
jobs:
validate:
name: Validate Code
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Grant Permission to Execute Gradle
run: chmod +x ./gradlew
#- name: Run Lint Checks
# run: ./gradlew lint
# continue-on-error: true
# - name: Run Unit Tests
# run: ./gradlew test
trigger-bitrise-build:
name: Trigger Bitrise Build
needs: validate
runs-on: ubuntu-latest
steps:
- name: Debug API Token & App Slug
run: |
echo "Checking API ....Token Length: ${#BITRISE_API_TOKEN}"
echo "Checking App Slug....Length: ${#BITRISE_APP_SLUG}"
env:
BITRISE_API_TOKEN: ${{ secrets.BITRISE_API_TOKEN }}
BITRISE_APP_SLUG: ${{ secrets.BITRISE_APP_SLUG }}
- name: Trigger Bitrise Build
run: |
BITRISE_BUILD_URL="https://api.bitrise.io/v0.1/apps/${{ secrets.BITRISE_APP_SLUG }}/builds"
RESPONSE=$(curl -s -X POST "$BITRISE_BUILD_URL" \
-H "Authorization: ${{ secrets.BITRISE_API_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{
"hook_info": { "type": "bitrise" },
"build_params": {
"branch": "main",
"workflow_id": "build_apk"
},
"triggered_by": "GitHub Actions"
}')
echo "Raw API Response: $RESPONSE"
if ! echo "$RESPONSE" | jq empty; then
echo "Error: API Response is not a valid JSON"
exit 1
fi
BUILD_ID=$(echo "$RESPONSE" | jq -r '.results[0].build_slug')
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then
echo "Error: Failed to trigger build.. API Response: $RESPONSE"
exit 1
fi
echo "Triggered Bitrise Build ID: $BUILD_ID"
# Output build ID for next steps
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV
- name: Wait for Bitrise Build to Complete
run: |
# Wait for Bitrise build to complete
BITRISE_BUILD_STATUS_URL="https://api.bitrise.io/v0.1/apps/${{ secrets.BITRISE_APP_SLUG }}/builds/$BUILD_ID"
while true; do
RESPONSE=$(curl -s -X GET "$BITRISE_BUILD_STATUS_URL" \
-H "Authorization: ${{ secrets.BITRISE_API_TOKEN }}")
echo "Raw Build Status - API Response: $RESPONSE"
if ! echo "$RESPONSE" | jq empty; then
echo "Error: Invalid JSON response from Bitrise API"
exit 1
fi
BUILD_STATUS=$(echo "$RESPONSE" | jq -r '.data.status')
if [[ "$BUILD_STATUS" == "1" ]]; then
echo "Build succeeded!"
break
elif [[ "$BUILD_STATUS" == "2" ]]; then
echo "Build failed!"
exit 1
else
echo "Build is still in progress..."
sleep 30 # Wait before checking again
fi
done
release:
name: Deploy Release (Firebase App Distribution)
needs: trigger-bitrise-build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Firebase CLI
run: npm install -g firebase-tools
- name: Set Up Firebase Authentication
run: |
echo '${{ secrets.BITRISE_FIREBASE_SERVICE_ACCOUNT }}' > firebase.json
export GOOGLE_APPLICATION_CREDENTIALS=firebase.json
- name: Get Bitrise Build Slug
run: |
BITRISE_BUILD_URL="https://api.bitrise.io/v0.1/apps/${{ secrets.BITRISE_APP_SLUG }}/builds"
RESPONSE=$(curl -s -L -X POST "$BITRISE_BUILD_URL" \
-H "Authorization: ${{ secrets.BITRISE_API_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{
"hook_info": { "type": "bitrise" },
"build_params": {
"branch": "main",
"workflow_id": "build_apk"
},
"triggered_by": "GitHub Actions"
}')
echo "Raw API Response: $RESPONSE"
# Validate JSON format
if ! echo "$RESPONSE" | jq empty; then
echo "Error: API Response is not valid JSON"
exit 1
fi
# Correctly extract build_slug from the results array
BUILD_ID=$(echo "$RESPONSE" | jq -r '.results[0].build_slug')
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then
echo "Error: Failed to retrieve build ID. API Response: $RESPONSE"
exit 1
fi
echo "Triggered Bitrise Build ID: $BUILD_ID"
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_ENV
- name: Download APK Info
run: |
curl -s -X GET "https://api.bitrise.io/v0.1/apps/f4fdd47e-5869-4405-9921-42565a3012e6/builds/9a4fe954-36c1-41cf-85f1-4b37e9080ae1/artifacts/bcb800d40c364f7d" \
-H "Authorization: 8uWxYQq3CSWRycLeGUNlIrDhmoNK8KN1f74Xt0rLUK4ZB6VnXE2eXfVvGZPSZRH1h1-o8Lzw8WciczVkUWo7iA" \
-H "Content-Type: application/json" > apk_info.json
- name: Extract Download URL & Download APK
run: |
DOWNLOAD_URL=$(grep -o '"expiring_download_url":"[^"]*' apk_info.json | sed -E 's/.*"expiring_download_url":"([^"]*)/\1/')
echo "APK Download URL: $DOWNLOAD_URL"
curl -o app-release-unsigned.apk "$DOWNLOAD_URL"
- name: Deploy APK to Firebase App Distribution
run: |
firebase appdistribution:distribute app-release-unsigned.apk \
--app ${{ secrets.FIREBASE_APP_ID }} \
--groups testers \
--token "${{ secrets.FIREBASE_TOKEN }}" \
--release-notes "New release from GitHub Actions"