Skip to content

Commit f51848d

Browse files
committed
ci: create build-only action for testing in forks
1 parent 0aa5c2d commit f51848d

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

.github/workflows/build-only.yml

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

0 commit comments

Comments
 (0)