Skip to content

Commit 211ed65

Browse files
committed
ci: create build-only action for testing in forks
1 parent 290ac3d commit 211ed65

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

.github/workflows/build-only.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: "Build only"
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags:
7+
- v*
8+
pull_request:
9+
branches: [master]
10+
11+
env:
12+
NDK_VERSION: "25.2.9519653"
13+
NODE_VERSION: "16"
14+
JAVA_VERSION: "17"
15+
16+
jobs:
17+
build-rust:
18+
name: Build aw-server-rust
19+
# runs-on: ubuntu-latest
20+
runs-on: macos-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
submodules: "recursive"
25+
- name: Set RELEASE
26+
run: |
27+
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
28+
29+
- name: Get aw-server-rust submodule commit
30+
id: submodule-commit
31+
run: |
32+
echo "commit=$(git rev-parse HEAD:aw-server-rust)" >> $GITHUB_OUTPUT
33+
34+
- name: Cache JNI libs
35+
uses: actions/cache@v3
36+
id: cache-jniLibs
37+
env:
38+
cache-name: jniLibs
39+
with:
40+
path: mobile/src/main/jniLibs/
41+
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ steps.submodule-commit.outputs.commit }}
42+
43+
- name: Display structure of downloaded files
44+
if: steps.cache-jniLibs.outputs.cache-hit == 'true'
45+
run: |
46+
pushd mobile/src/main/jniLibs && ls -R && popd
47+
48+
# Android SDK & NDK
49+
- name: Set up Android SDK
50+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
51+
uses: android-actions/setup-android@v2
52+
- name: Set up Android NDK
53+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
54+
run: |
55+
sdkmanager "ndk;${{ env.NDK_VERSION }}"
56+
ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}"
57+
ls $ANDROID_NDK_HOME
58+
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
59+
60+
# Rust
61+
- name: Set up Rust
62+
id: toolchain
63+
uses: dtolnay/rust-toolchain@stable
64+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
65+
66+
- name: Set up Rust toolchain for Android NDK
67+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
68+
run: |
69+
./aw-server-rust/install-ndk.sh
70+
71+
- name: Cache cargo build
72+
uses: actions/cache@v3
73+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
74+
env:
75+
cache-name: cargo-build-target
76+
with:
77+
path: aw-server-rust/target
78+
# key needs to contain cachekey due to https://github.com/ActivityWatch/aw-server-rust/issues/180
79+
key: ${{ env.cache-name }}-${{ runner.os }}-release-${{ env.RELEASE }}-${{ steps.toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}
80+
restore-keys: |
81+
${{ env.cache-name }}-${{ runner.os }}-release-${{ env.RELEASE }}-${{ steps.toolchain.outputs.cachekey }}-
82+
83+
- name: Build aw-server-rust
84+
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
85+
run: |
86+
make aw-server-rust
87+
88+
- name: Check that jniLibs present
89+
run: |
90+
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
91+
92+
# This needs to be a seperate job since fastlane update_version,
93+
# fails if run concurrently (such as in build apk/aab matrix),
94+
# thus we need to run it once and and reuse the results.
95+
# https://github.com/fastlane/fastlane/issues/13689#issuecomment-439217502
96+
get-versionCode:
97+
name: Get latest versionCode
98+
runs-on: ubuntu-latest
99+
outputs:
100+
versionCode: ${{ steps.versionCode.outputs.versionCode }}
101+
102+
steps:
103+
- uses: actions/checkout@v2
104+
with:
105+
submodules: "recursive"
106+
107+
- name: Output versionCode
108+
id: versionCode
109+
run: |
110+
cat mobile/build.gradle | grep versionCode | sed 's/.*\s\([0-9]*\)$/versionCode=\1/' >> "$GITHUB_OUTPUT"
111+
112+
build-apk:
113+
name: Build ${{ matrix.type }}
114+
runs-on: ubuntu-latest
115+
needs: [build-rust, get-versionCode]
116+
strategy:
117+
fail-fast: true
118+
matrix:
119+
type: ["apk", "aab"]
120+
121+
steps:
122+
- uses: actions/checkout@v2
123+
with:
124+
submodules: "recursive"
125+
126+
- uses: ActivityWatch/check-version-format-action@v2
127+
id: version
128+
with:
129+
prefix: "v"
130+
131+
- name: Echo version
132+
run: |
133+
echo "${{ steps.version.outputs.full }} (stable: ${{ steps.version.outputs.is_stable }})"
134+
135+
- name: Set RELEASE
136+
run: |
137+
# Build in release mode if on a tag/release (longer build times)
138+
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
139+
140+
- name: Set up JDK
141+
uses: actions/setup-java@v1
142+
with:
143+
java-version: ${{ env.JAVA_VERSION }}
144+
145+
# Android SDK & NDK
146+
- name: Set up Android SDK
147+
uses: android-actions/setup-android@v2
148+
- name: Set up Android NDK
149+
run: |
150+
sdkmanager "ndk;${{ env.NDK_VERSION }}"
151+
ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}"
152+
ls $ANDROID_NDK_HOME
153+
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
154+
155+
- name: Get aw-server-rust submodule commit
156+
id: submodule-commit
157+
run: |
158+
echo "commit=$(git rev-parse HEAD:aw-server-rust)" >> $GITHUB_OUTPUT
159+
160+
# Restores jniLibs from cache
161+
# `actions/cache/restore` only restores, without saving back in a post-hook
162+
- uses: actions/cache/restore@v3
163+
id: cache-jniLibs
164+
env:
165+
cache-name: jniLibs
166+
with:
167+
path: mobile/src/main/jniLibs/
168+
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ steps.submodule-commit.outputs.commit }}
169+
fail-on-cache-miss: true
170+
171+
- name: Check that jniLibs present
172+
run: |
173+
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
174+
175+
- name: Set versionName
176+
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
177+
run: |
178+
# Sets versionName, tail used to skip "v" at start of tag name
179+
SHORT_VERSION=$(echo "${{ github.ref_name }}" | tail -c +2 -)
180+
sed -i "s/versionName \".*\"/versionName \"$SHORT_VERSION\"/g" \
181+
mobile/build.gradle
182+
183+
- name: Set versionCode
184+
run: |
185+
# Sets versionCode
186+
sed -i "s/versionCode .*/versionCode ${{needs.get-versionCode.outputs.versionCode}}/" \
187+
mobile/build.gradle
188+
189+
- uses: adnsio/[email protected]
190+
- name: Load Android secrets
191+
if: env.KEY_ANDROID_JKS != null
192+
env:
193+
KEY_ANDROID_JKS: ${{ secrets.KEY_ANDROID_JKS }}
194+
run: |
195+
printf "$KEY_ANDROID_JKS" > android.jks.key
196+
cat android.jks.age | age -d -i android.jks.key -o android.jks
197+
rm android.jks.key
198+
199+
- name: Assemble
200+
env:
201+
JKS_STOREPASS: ${{ secrets.KEY_ANDROID_JKS_STOREPASS }}
202+
JKS_KEYPASS: ${{ secrets.KEY_ANDROID_JKS_KEYPASS }}
203+
run: |
204+
make dist/aw-android.${{ matrix.type }}
205+
206+
- name: Upload
207+
uses: actions/upload-artifact@v4
208+
with:
209+
name: aw-android.${{ matrix.type }}
210+
path: dist/aw-android*.${{ matrix.type }}

0 commit comments

Comments
 (0)