-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
227 lines (192 loc) · 7.31 KB
/
main.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
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
#########################################################################################
#########################################################################################
#########################################################################################
name: Pipeline Unity Android with play and backup
on:
push:
paths:
- 'version.txt'
pull_request:
paths:
- 'version.txt'
workflow_dispatch:
inputs:
deploy_only:
description: "Deploy to Google Play"
required: false
type: boolean
jobs:
buildForAndroid:
name: Setup and Build for Android
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch' || github.event.inputs.deploy_only != 'true'
steps:
- name: Free Disk Space for Android
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Copy version.txt to Resources
run: |
mkdir -p Assets/Resources
cp version.txt Assets/Resources/version.txt
- name: Verify version.txt file
run: cat Assets/Resources/version.txt
- name: Get version
id: get_version
run: |
cat version.txt
VERSION=$(grep 'NAME_NAME_VERSION' version.txt | cut -d'=' -f2)
echo "VERSION=$VERSION" >> $GITHUB_ENV
VERSION_CODE=$(echo $VERSION | tr -d '.' | sed 's/^0*//')
echo " - VERSION_CODE: $VERSION_CODE"
echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV
- name: Ensure Library Directory Exists
run: mkdir -p Library
- name: Cache Unity Library
uses: actions/cache@v4
with:
path: |
Library
ProjectSettings
Packages
key: Library-${{ runner.os }}-Unity-${{ env.UNITY_VERSION }}-Android
restore-keys: |
Library-${{ runner.os }}-Unity-${{ env.UNITY_VERSION }}-Android-
Library-${{ runner.os }}-Unity-${{ env.UNITY_VERSION }}-
Library-${{ runner.os }}-
Library-
- name: Verify Library Contents After Cache
run: ls -la Library
- name: Check Unity Library Cache
run: ls -la Library || echo "Library folder does not exist."
- name: Create directory for logs
run: mkdir -p build_logs
- name: Build Unity Project
id: buildStep
uses: game-ci/unity-builder@v4
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
unityVersion: 2021.3.23f1
targetPlatform: Android
buildMethod: BuildScript.BuildAndroid
androidKeystoreName: name-keystore.jks
androidKeystoreBase64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
androidKeystorePass: ${{ secrets.ANDROID_KEYSTORE_PASS }}
androidKeyaliasName: ${{ secrets.ANDROID_KEYALIAS_NAME }}
androidKeyaliasPass: ${{ secrets.ANDROID_KEYALIAS_PASS }}
androidTargetSdkVersion: AndroidApiLevel34
versioning: Custom
version: ${{ env.VERSION }}
androidVersionCode: ${{ env.VERSION_CODE }}
- name: Copy build and logs to build_logs
run: |
if [ -d "Library/Logs/Unity" ]; then
cp -r Library/Logs/Unity build_logs/
else
echo "No Unity logs found."
fi
cp -r build/* build_logs/
- name: Zip build logs and outputs
run: zip -r build_logs.zip build_logs/
- name: Upload Build Logs and Outputs (ZIP)
if: failure()
uses: actions/upload-artifact@v3
with:
name: build-logs-and-outputs
path: build_logs.zip
retention-days: 7
- name: List build files
run: ls -la build/Android
- name: Upload Build Backup
uses: actions/upload-artifact@v4
with:
name: build-backup
path: build/Android/*.aab
retention-days: 30
#########################################################################################
#########################################################################################
#########################################################################################
uploadToGoogleDrive:
name: Backup to Google Drive
runs-on: ubuntu-latest
needs: buildForAndroid
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Android Artifact
uses: actions/download-artifact@v4
with:
name: build-backup
path: build/Android
- name: List build/Android directory
run: ls -la build/Android
- name: List APK and AAB files
run: ls -la build/Android || echo "No files found"
- name: Capture AAB filename
run: |
AAB_FILE=$(ls build/Android/*.aab)
echo "AAB_FILE=$AAB_FILE" >> $GITHUB_ENV
- name: Upload Artifacts to Google Drive
uses: Jumbo810/Upload_Github_Artifacts_TO_GDrive@v2.2.2
with:
target: ${{ env.AAB_FILE }}
credentials: ${{ secrets.GDRIVE_CREDENTIALS_BASE64 }}
parent_folder_id: "${{ secrets.GDRIVE_FOLDER }}"
child_folder: "v${{ env.VERSION }}"
override: true
#########################################################################################
#########################################################################################
#########################################################################################
deployToGooglePlay:
name: Deploy to Google Play
runs-on: ubuntu-latest
needs: buildForAndroid
if: github.event.inputs.deploy_only == 'true' || github.event_name != 'workflow_dispatch'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Android Artifact
uses: actions/download-artifact@v4
with:
name: build-backup
path: build/Android
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Install Fastlane
run: sudo gem install fastlane
- name: Add Authentication
env:
GOOGLE_PLAY_KEY_FILE: ${{ secrets.GOOGLE_PLAY_KEY_FILE }}
run: echo "${GOOGLE_PLAY_KEY_FILE}" > /tmp/google_play_key.json
- name: Upload to Google Play
run: |
fastlane supply --json_key /tmp/google_play_key.json \
--package_name com.name.name \
--aab build/Android/*.aab \
--track internal \
--release_status draft \
--skip_upload_metadata true \
--skip_upload_images true \
--skip_upload_screenshots true
- name: Cleanup
run: rm /tmp/google_play_key.json
#########################################################################################
#########################################################################################
#########################################################################################