-
-
Notifications
You must be signed in to change notification settings - Fork 56
166 lines (145 loc) · 6.37 KB
/
build_beta_apk.yml
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
name: Build APK (Beta)
on:
push:
branches:
- master
paths-ignore:
- '**.md'
- '**.yml'
- '**.json'
- '**.lock'
- '**.properties'
- '**.py'
- '**.sh'
workflow_dispatch:
inputs:
message:
description: 'Message to be sent'
required: true
default: 'The beta build is ready for testing'
jobs:
validation:
name: Commit Validation
runs-on: ubuntu-latest
outputs:
CANCEL_WORKFLOW: ${{ steps.check_commit_message.outputs.CANCEL_WORKFLOW }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check commit message
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Workflow was manually dispatched. Skipping commit message check."
echo "CANCEL_WORKFLOW=false" >> $GITHUB_OUTPUT
else
commit_message=$(git log --format=%B -n 1)
if [[ ! "$commit_message" == *"build beta"* ]]; then
echo "Commit message does not contain 'build beta'. Cancelling workflow."
echo "CANCEL_WORKFLOW=true" >> $GITHUB_OUTPUT
else
echo "Commit message contains 'build beta'. Proceeding with the workflow."
echo "CANCEL_WORKFLOW=false" >> $GITHUB_OUTPUT
fi
fi
id: check_commit_message
- name: Verify Actor
run: |
encoded_actor=$(echo "SGFtemE0MTc=" | base64 --decode)
if [[ "${{ github.actor }}" != "$encoded_actor" ]]; then
exit 1
fi
build:
needs: validation
if: needs.validation.outputs.CANCEL_WORKFLOW == 'false'
name: Build APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Decode Keystore
id: decode_keystore
uses: timheuer/base64-to-file@v1
with:
fileName: 'keystore/key.jks'
encodedString: ${{ secrets.SIGN_KEY }}
- name: Extract Version Name and Version Code
run: |
VERSION_NAME=$(cat app/build.gradle | grep -oP 'versionName "\K[^"]*')
VERSION_CODE=$(cat app/build.gradle | grep -oP 'versionCode \K\d+')
VERSION_NAME=$(echo "$VERSION_NAME" | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1')
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
- name: Append Latest Commit ID to Version Name
run: |
VERSION_NAME="${{ env.VERSION_NAME }}_$(git rev-parse --short HEAD)"
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Set Current Commit Message
run: |
echo "COMMIT_MESSAGE=$(git log --format=%B -n 1 | head -n 1)" >> $GITHUB_ENV
- name: Build APK
run: |
if [[ -n "${{ env.GRADLE_PATH }}" ]]; then
chmod +x "${{ env.GRADLE_PATH }}"
${{ env.GRADLE_PATH }} clean assembleBetaRelease
else
chmod +x ./gradlew
./gradlew clean assembleBetaRelease
fi
env:
SIGNING_KEY_ALIAS: ${{ secrets.ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
SIGNING_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
- name: Find APK
id: find_apk
run: |
apk=$(find . -type f -name "*.apk")
if [ -z "$apk" ]; then
echo "No APK file found."
exit 1
else
echo "APK_PATH=$apk" >> $GITHUB_ENV
echo "${{ env.APK_PATH }}"
fi
- name: Rename APK
run: |
mv "${{ env.APK_PATH }}" "${{ env.VERSION_NAME }}.apk"
echo "APK_PATH=$(find . -type f -name "*.apk")" >> $GITHUB_ENV
echo "${{ env.APK_PATH }}"
- name: Check File Permissions
run: |
ls -l "${{ env.APK_PATH }}"
echo "File Permissions: $(stat -c '%A' "${{ env.APK_PATH }}")"
- name: Set Read Permission
run: |
chmod +r "${{ env.APK_PATH }}"
echo "File Permissions: $(stat -c '%A' "${{ env.APK_PATH }}")"
- name: Send APK to Telegram
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TG_TO }}
token: ${{ secrets.TG_BOT_KEY }}
document: ${{ env.APK_PATH }}
message: |
${{ github.event.inputs.message }}
Current Build Code: ${{ env.VERSION_CODE }}
Current Commit ID: ${{ env.COMMIT_ID }}
Commit Message: ${{ env.COMMIT_MESSAGE }}
- name: Archive APK
uses: actions/upload-artifact@v4
with:
name: Beta APK (Debug)
path: ${{ env.APK_PATH }}