-
-
Notifications
You must be signed in to change notification settings - Fork 15
162 lines (138 loc) · 5.16 KB
/
android.yml
File metadata and controls
162 lines (138 loc) · 5.16 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
name: Build PR Debug APK
on:
pull_request:
branches: [ "main" ]
paths-ignore:
- '**.md'
- 'fastlane/**'
workflow_dispatch:
inputs:
pr_number:
description: 'PR Number'
required: true
# We need permission to write comments on the PR
permissions:
contents: read
pull-requests: write
jobs:
build-and-comment:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Determine PR Number
id: pr_context
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV
else
echo "PR_NUMBER=${{ inputs.pr_number }}" >> $GITHUB_ENV
fi
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 1. FIND OR CREATE THE INITIAL COMMENT
- name: Post "Building" Comment
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const marker = '<!-- bot-pr-build-comment -->';
const { owner, repo } = context.repo;
const issue_number = parseInt(process.env.PR_NUMBER);
// Find existing comment
const comments = await github.rest.issues.listComments({
owner, repo, issue_number
});
const botComment = comments.data.find(c => c.body.includes(marker));
const body = `${marker}
### 🔨 Building Debug APK...
<details>
<summary>View Status</summary>
Building on GitHub Actions...
</details>`;
if (botComment) {
await github.rest.issues.updateComment({
owner, repo, comment_id: botComment.id, body
});
} else {
await github.rest.issues.createComment({
owner, repo, issue_number, body
});
}
# 2. RUN THE BUILD (And capture logs)
# We pipe output to a file (build.log) AND to console (tee) so we can read it later
- name: Build Debug APK
id: build_apk
shell: bash
run: |
set -o pipefail
./gradlew assembleDebug --stacktrace | tee build.log
# 3. UPLOAD THE APK ARTIFACT
- name: Upload APK
if: success()
uses: actions/upload-artifact@v4
with:
name: compressor-debug-pr-${{ env.PR_NUMBER }}
path: app/build/outputs/apk/debug/app-debug.apk
retention-days: 5
# 4. READ LOGS (Truncate to last 100 lines to fit in comment)
- name: Process Logs
if: always() # Run even if build failed
id: process_logs
run: |
# Get the last 150 lines of the log to avoid comment size limits
tail -n 150 build.log > trimmed_log.txt
# Read file into variable
echo "LOG_CONTENT<<EOF" >> $GITHUB_OUTPUT
cat trimmed_log.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# 5. UPDATE COMMENT WITH RESULT (Success or Failure)
- name: Update Comment with Result
if: always()
uses: actions/github-script@v7
env:
LOGS: ${{ steps.process_logs.outputs.LOG_CONTENT }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
STATUS: ${{ job.status }}
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const marker = '<!-- bot-pr-build-comment -->';
const { owner, repo } = context.repo;
const issue_number = parseInt(process.env.PR_NUMBER);
const logs = process.env.LOGS;
const runUrl = process.env.RUN_URL;
const status = process.env.STATUS;
// Find existing comment again
const comments = await github.rest.issues.listComments({
owner, repo, issue_number
});
const botComment = comments.data.find(c => c.body.includes(marker));
let title = status === 'success' ? '## ✅ Build Successful' : '## ❌ Build Failed';
let downloadSection = status === 'success'
? `**Debug APK Ready**
[Download from Artifacts](${runUrl})
**Note:** You may need to uninstall the existing version before installing this debug build.`
: `**The build encountered errors.** See the logs below for details.`;
const body = `${marker}
${title}
${downloadSection}
<details>
<summary>Build Logs</summary>
\`\`\`text
${logs}
\`\`\`
</details>
`;
if (botComment) {
await github.rest.issues.updateComment({
owner, repo, comment_id: botComment.id, body
});
}