Repository navigation
205 lines (173 loc) · 7.72 KB
/
Copy pathpreview.yml
File metadata and controls
205 lines (173 loc) · 7.72 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
name: Preview Build & Deploy
# Triggering fresh validation
permissions:
contents: write
pages: write
id-token: write
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
outputs:
commit_count: ${{ steps.set_commit.outputs.commit_count }}
build_time: ${{ steps.set_commit.outputs.build_time }}
changelog: ${{ steps.changelog.outputs.changelog }}
universal_size: ${{ steps.set_commit.outputs.universal_size }}
arm64-v8a_size: ${{ steps.set_commit.outputs.arm64-v8a_size }}
armeabi-v7a_size: ${{ steps.set_commit.outputs.armeabi-v7a_size }}
x86_size: ${{ steps.set_commit.outputs.x86_size }}
x86_64_size: ${{ steps.set_commit.outputs.x86_64_size }}
universal_bytes: ${{ steps.set_commit.outputs.universal_bytes }}
arm64-v8a_bytes: ${{ steps.set_commit.outputs.arm64-v8a_bytes }}
armeabi-v7a_bytes: ${{ steps.set_commit.outputs.armeabi-v7a_bytes }}
x86_bytes: ${{ steps.set_commit.outputs.x86_bytes }}
x86_64_bytes: ${{ steps.set_commit.outputs.x86_64_bytes }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate preview changelog (last 20 commits)
id: changelog
run: |
set -e
LIMIT=20
CHANGELOG_JSON="["
i=0
while IFS=$'\t' read -r sha msg; do
[ -z "$sha" ] && continue
serial=$(git rev-list --count "$sha")
esc=$(printf '%s' "$msg" | jq -Rs .)
if [ "$i" -gt 0 ]; then CHANGELOG_JSON+=","; fi
CHANGELOG_JSON+="{\"serial\":$serial,\"message\":$esc,\"sha\":\"$sha\"}"
i=$((i+1))
done < <(git log --no-merges -${LIMIT} --format='%H%x09%s')
CHANGELOG_JSON+="]"
# Must be a valid JSON array of at most LIMIT entries before it can be shipped
jq -e "type == \"array\" and length <= ${LIMIT}" >/dev/null <<<"$CHANGELOG_JSON"
echo "changelog=$CHANGELOG_JSON" >> $GITHUB_OUTPUT
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 17
cache: 'gradle'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew assemblePreview
- name: Sign APKs
run: |
set -e
RELEASE_DIR="app/build/outputs/apk/preview"
echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 -d > release.keystore
# Find all unsigned APKs
APK_COUNT=$(find "$RELEASE_DIR" -name "app-*-preview-unsigned.apk" -type f | wc -l)
if [ "$APK_COUNT" -eq 0 ]; then
echo "No unsigned APK files found"
ls -lah "$RELEASE_DIR"
rm release.keystore
exit 1
fi
find "$RELEASE_DIR" -name "app-*-preview-unsigned.apk" -type f | while read -r apk; do
# Rename output to remove -unsigned suffix
signed_apk="${apk/-unsigned/}"
$ANDROID_HOME/build-tools/35.0.0/apksigner sign \
--ks release.keystore \
--ks-key-alias "${{ secrets.SIGNING_KEY_ALIAS }}" \
--ks-pass "pass:${{ secrets.SIGNING_STORE_PASSWORD }}" \
--key-pass "pass:${{ secrets.KEY_PASSWORD }}" \
--out "$signed_apk" \
"$apk"
$ANDROID_HOME/build-tools/35.0.0/apksigner verify "$signed_apk"
rm "$apk"
done
rm release.keystore
ls -lh "$RELEASE_DIR"/app-*-preview.apk
- name: Copy build artifacts
id: set_commit
run: |
set -e
commit_count=$(git rev-list --count HEAD)
build_time=$(date -u +"%Y-%m-%d %H:%M UTC")
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
echo "build_time=$build_time" >> $GITHUB_OUTPUT
declare -a apks=("universal" "arm64-v8a" "armeabi-v7a" "x86" "x86_64")
mkdir -p output
for arch in "${apks[@]}"; do
src="app/build/outputs/apk/preview/app-${arch}-preview.apk"
dest="output/REX-Player-preview-r${commit_count}-${arch}.apk"
if [ ! -f "$src" ]; then
echo "::error file=$src::Signed APK for $arch was not found"
exit 1
fi
cp "$src" "$dest"
# Get file size in human-readable format and bytes
size=$(du -h "$dest" | cut -f1)
bytes=$(stat -c%s "$dest")
echo "${arch}_size=$size" >> $GITHUB_OUTPUT
echo "${arch}_bytes=$bytes" >> $GITHUB_OUTPUT
done
- name: Upload all artifacts
uses: actions/upload-artifact@v4
with:
name: preview-apks
path: output/
publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: preview-apks
path: ./public
- name: Generate download page
run: |
export COMMIT_COUNT=${{ needs.build.outputs.commit_count }}
export BUILD_TIME="${{ needs.build.outputs.build_time }}"
export UNIVERSAL_SIZE="${{ needs.build.outputs.universal_size }}"
export ARM64_SIZE="${{ needs.build.outputs.arm64-v8a_size }}"
export ARMV7_SIZE="${{ needs.build.outputs.armeabi-v7a_size }}"
export X86_SIZE="${{ needs.build.outputs.x86_size }}"
export X86_64_SIZE="${{ needs.build.outputs.x86_64_size }}"
export UNIVERSAL_BYTES=$(stat -c%s ./public/REX-Player-preview-r${COMMIT_COUNT}-universal.apk 2>/dev/null || echo "${{ needs.build.outputs.universal_bytes }}")
export ARM64_BYTES=$(stat -c%s ./public/REX-Player-preview-r${COMMIT_COUNT}-arm64-v8a.apk 2>/dev/null || echo "${{ needs.build.outputs.arm64-v8a_bytes }}")
export ARMV7_BYTES=$(stat -c%s ./public/REX-Player-preview-r${COMMIT_COUNT}-armeabi-v7a.apk 2>/dev/null || echo "${{ needs.build.outputs.armeabi-v7a_bytes }}")
export X86_BYTES=$(stat -c%s ./public/REX-Player-preview-r${COMMIT_COUNT}-x86.apk 2>/dev/null || echo "${{ needs.build.outputs.x86_bytes }}")
export X86_64_BYTES=$(stat -c%s ./public/REX-Player-preview-r${COMMIT_COUNT}-x86_64.apk 2>/dev/null || echo "${{ needs.build.outputs.x86_64_bytes }}")
export UNIVERSAL_BYTES=${UNIVERSAL_BYTES:-0}
export ARM64_BYTES=${ARM64_BYTES:-0}
export ARMV7_BYTES=${ARMV7_BYTES:-0}
export X86_BYTES=${X86_BYTES:-0}
export X86_64_BYTES=${X86_64_BYTES:-0}
envsubst < .github/workflows/preview.template.html > ./public/index.html
envsubst < .github/workflows/preview.template.json > ./public/version.json
- name: Inject changelog into version.json
env:
CHANGELOG_JSON: ${{ needs.build.outputs.changelog }}
run: |
set -e
if jq -e . >/dev/null 2>&1 <<<"$CHANGELOG_JSON"; then
jq --argjson changelog "$CHANGELOG_JSON" '.changelog = $changelog' \
./public/version.json > ./public/version.json.tmp
mv ./public/version.json.tmp ./public/version.json
else
echo "::warning::Changelog payload missing or invalid; version.json will not include changelog"
fi
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
needs: publish
runs-on: ubuntu-latest
environment:
name: github-pages
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4