-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (142 loc) · 6.06 KB
/
Copy pathbranch-apk.yml
File metadata and controls
162 lines (142 loc) · 6.06 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: Branch APK
# On every push to a non-main branch, build a debug APK and replace the
# rolling pre-release tagged `branch-<name>` with the freshly built artifact.
# Testers always get the latest commit by visiting the same release URL.
#
# Pull-request runs build the APK as a workflow artifact (downloadable from
# the Actions tab for ~90 days) but do not touch the release list, so PRs
# from forks can't push tags.
on:
push:
branches-ignore:
- main
tags-ignore:
- "**"
pull_request:
branches:
- "**"
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # full history so we can produce a "since main" log
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build debug APKs
# Build the phone APK on every branch. Build the wear APK too when
# the branch has a wear/ module (currently only wear-os-watch-ultra),
# so testers can grab both halves from the same rolling release.
run: |
targets=":app:assembleDebug"
if [ -f wear/build.gradle.kts ]; then
targets="$targets :wear:assembleDebug"
fi
./gradlew $targets --no-daemon --stacktrace
env:
GRADLE_OPTS: -Xmx4g -Dorg.gradle.jvmargs=-Xmx4g
- name: Compute build metadata
id: meta
if: github.event_name != 'pull_request'
run: |
BRANCH="${GITHUB_REF##*/}"
SHORT_SHA="$(git rev-parse --short HEAD)"
TAG="branch-${BRANCH}"
APK_NAME="EUC-Planet-${BRANCH}-${SHORT_SHA}-phone.apk"
WEAR_APK_NAME="EUC-Planet-${BRANCH}-${SHORT_SHA}-wear_os.apk"
# Pull the per-branch description if BRANCH.md exists, otherwise
# fall back to a generic notice. This becomes the release body header.
if [ -f BRANCH.md ]; then
cp BRANCH.md /tmp/branch-notes.md
else
cat > /tmp/branch-notes.md <<EOF
# ${BRANCH}
No \`BRANCH.md\` found at repo root. Add one to describe what this
branch is for and who should test it.
EOF
fi
# Recent commits since branching from main, capped to keep the
# release body readable on big branches.
git log --pretty=format:'- %h %s' main..HEAD | head -50 > /tmp/commit-log.md || true
{
echo "**Pre-release from branch \`${BRANCH}\`** — automatic build at \`${SHORT_SHA}\`."
echo
echo "This is a CI-built debug APK. It can't update an existing Play Store install in place — uninstall the Play version first to install this build."
echo
cat /tmp/branch-notes.md
echo
echo "## Recent commits"
echo
cat /tmp/commit-log.md
} > /tmp/release-body.md
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "apk_name=${APK_NAME}" >> "$GITHUB_OUTPUT"
echo "wear_apk_name=${WEAR_APK_NAME}" >> "$GITHUB_OUTPUT"
- name: Rename APKs for release
if: github.event_name != 'pull_request'
run: |
cp app/build/outputs/apk/debug/app-debug.apk \
"/tmp/${{ steps.meta.outputs.apk_name }}"
# Wear APK only exists on branches that have a wear/ module.
if [ -f wear/build/outputs/apk/debug/wear-debug.apk ]; then
cp wear/build/outputs/apk/debug/wear-debug.apk \
"/tmp/${{ steps.meta.outputs.wear_apk_name }}"
fi
- name: Upload phone APK as workflow artifact
uses: actions/upload-artifact@v4
with:
name: app-debug-${{ github.run_id }}
path: app/build/outputs/apk/debug/app-debug.apk
retention-days: 90
- name: Upload wear APK as workflow artifact
if: hashFiles('wear/build/outputs/apk/debug/wear-debug.apk') != ''
uses: actions/upload-artifact@v4
with:
name: wear-debug-${{ github.run_id }}
path: wear/build/outputs/apk/debug/wear-debug.apk
retention-days: 90
- name: Strip prior APKs from rolling release
if: github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# action-gh-release attaches new files but doesn't remove the previous
# commit's APK; without this step the rolling pre-release accumulates
# one APK per push. Delete every existing .apk on the tag before the
# next step uploads the freshly built one. Tolerate the tag not
# existing yet (first run on a brand-new branch).
tag="${{ steps.meta.outputs.tag }}"
if gh release view "$tag" >/dev/null 2>&1; then
gh release view "$tag" --json assets \
--jq '.assets[] | select(.name | endswith(".apk")) | .name' \
| while read -r asset; do
[ -n "$asset" ] && gh release delete-asset "$tag" "$asset" --yes || true
done
fi
- name: Replace rolling pre-release with new APK
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.tag }}
name: ${{ steps.meta.outputs.tag }} (${{ steps.meta.outputs.short_sha }})
body_path: /tmp/release-body.md
prerelease: true
# Replace the existing tag/release on every push so testers can
# always find the latest at the same URL. The glob picks up both
# the phone APK and (if the branch has wear/) the watch APK.
make_latest: "false"
files: /tmp/EUC-Planet-${{ steps.meta.outputs.branch }}-${{ steps.meta.outputs.short_sha }}*.apk