Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Screenshot ci #2

Merged
merged 21 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 194 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
name: ${{ matrix.os }}, java-${{ matrix.java_version }}, node-${{ matrix.node_version }}
name: Build ${{ matrix.os }}, java-${{ matrix.java_version }}, node-${{ matrix.node_version }}
runs-on: ${{ matrix.os }}
env:
SUPPLY_TRACK: production # used by fastlane to determine track to publish to
Expand Down Expand Up @@ -101,7 +101,8 @@ jobs:
# Set up Rust toolchain
- name: Set up Rust toolchain for Android NDK
run: |
ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk-bundle ./aw-server-rust/install-ndk.sh
ANDROID_NDK_HOME=
./aw-server-rust/install-ndk.sh

# Test
- name: Test
Expand Down Expand Up @@ -153,6 +154,7 @@ jobs:
bundle exec fastlane update_version

- name: Load secrets
if: env.KEY_ANDROID_JKS != null
env:
KEY_ANDROID_JKS: ${{ secrets.KEY_ANDROID_JKS }}
run: |
Expand All @@ -175,6 +177,196 @@ jobs:
name: aw-android
path: dist/aw-android*.apk

test:
name: Test api-${{ matrix.android_emu_version }}, java-${{ matrix.java_version }}, node-${{ matrix.node_version }}
runs-on: ${{ matrix.os }}
env:
SUPPLY_TRACK: production # used by fastlane to determine track to publish to
strategy:
fail-fast: false
matrix:
os: [macOS-latest]
android_emu_version: [29]
java_version: [1.8]
node_version: [16]
ruby_version: ['3.0']
rust_build: [false] # if true, will build aw-server-rust, otherwise will fetch artifact from recent CI run
skip_webui: [true]
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

# Build in release mode if: (longer build times)
# - on a tag (release)
# - on the master branch (nightly)
- name: Set RELEASE
run: |
echo "RELEASE=${{ startsWith(github.ref_name, 'v') || github.ref_name == 'master' }}" >> $GITHUB_ENV

# - name: Set up JDK
# uses: actions/setup-java@v1
# with:
# java-version: ${{ matrix.java_version }}

# Android SDK & NDK
- name: Set up Android SDK
uses: android-actions/setup-android@v2
- name: Install NDK
run: sdkmanager "ndk;25.0.8775105"

- name: Set up Node
uses: actions/setup-node@v1
if: ${{ !matrix.skip_webui }}
with:
node-version: ${{ matrix.node_version }}
- name: Set up Rust nightly
uses: actions-rs/toolchain@v1
if: ${{ matrix.rust_build }}
with:
profile: minimal
toolchain: nightly
override: true
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}

- uses: adnsio/setup-age-action@v1.2.0

# Set up caches
- name: Get npm cache dir
id: npm-cache-dir
if: ${{ !matrix.skip_webui }}
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v1
name: Cache npm
if: ${{ !matrix.skip_webui }}
env:
cache-name: node
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-

- name: Cache cargo build
uses: actions/cache@v1
if: ${{ matrix.rust_build }}
env:
cache-name: cargo-build-target
with:
path: aw-server-rust/target
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-

# Install fastlane
- name: Install fastlane
run: |
gem install bundler
bundle install

# Set up Rust toolchain
- name: Set up Rust toolchain for Android NDK
if: ${{ matrix.rust_build }}
run: |
ANDROID_NDK_HOME=
./aw-server-rust/install-ndk.sh

# Build webui
- name: Build webui
if: ${{ !matrix.skip_webui }}
run: |
make aw-webui

# Build or fetch aw-server-rust artifacts
- name: Build aw-server-rust
if: ${{ matrix.rust_build }}
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
make aw-server-rust

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
if: ${{ !matrix.rust_build }}
with:
repo: ActivityWatch/aw-server-rust
branch: master
workflow: build.yml
# Optional, uploaded artifact name,
# will download all artifacts if not specified
# and extract them in respective subdirectories
# https://github.com/actions/download-artifact#download-all-artifacts
name: binaries-android
path: aw-server-rust/target/
# Optional, the status or conclusion of a completed workflow to search for
# Can be one of a workflow conculsion::
# "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
# Or a workflow status:
# "completed", "in_progress", "queued"
# Default: "completed"
workflow_conclusion: success

- name: Install aw-server-rust binaries
if: ${{ !matrix.rust_build }}
# TODO: These are only debug, make something like "make install" for below
run: |
mkdir -p mobile/src/main/jniLibs/arm64-v8a/
cp -f ./aw-server-rust/target/aarch64-linux-android/debug/libaw_server.so mobile/src/main/jniLibs/arm64-v8a/libaw_server.so
mkdir -p mobile/src/main/jniLibs/armeabi-v7a/
cp -f ./aw-server-rust/target/armv7-linux-androideabi/debug/libaw_server.so mobile/src/main/jniLibs/armeabi-v7a/libaw_server.so
mkdir -p mobile/src/main/jniLibs/x86/
cp -f ./aw-server-rust/target/i686-linux-android/debug/libaw_server.so mobile/src/main/jniLibs/x86/libaw_server.so
mkdir -p mobile/src/main/jniLibs/x86_64/
cp -f ./aw-server-rust/target/x86_64-linux-android/debug/libaw_server.so mobile/src/main/jniLibs/x86_64/libaw_server.so

- name: Set version
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
run: |
# Sets versionName, tail used to skip "v" at start of tag name
SHORT_VERSION=$(echo "${{ github.ref_name }}" | tail -c +2 -)
sed -i "s/versionName \".*\"/versionName \"$SHORT_VERSION\"/g" \
mobile/build.gradle
bundle exec fastlane update_version

# - name: Load secrets
# if: env.KEY_ANDROID_JKS != null
# env:
# KEY_ANDROID_JKS: ${{ secrets.KEY_ANDROID_JKS }}
# run: |
# printf "$KEY_ANDROID_JKS" > android.jks.key
# cat android.jks.age | age -d -i android.jks.key -o android.jks
# rm android.jks.key

# - name: Assemble APK
# env:
# JKS_STOREPASS: ${{ secrets.KEY_ANDROID_JKS_STOREPASS }}
# JKS_KEYPASS: ${{ secrets.KEY_ANDROID_JKS_KEYPASS }}
# run: |
# # TODO: Add related stuff in .travis.yml
# # TODO: Allow building even if secrets not set
# make dist/aw-android.apk

# Test
- name: Test
id: test
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.android_emu_version }}
# Only running specific Instrumentation tests cause others are failing right now. TODO: Fix others
script: ./gradlew connectedCheck -Pandroid.testInstrumentationRunnerArguments.class=net.activitywatch.android.ScreenshotTest --stacktrace

- name: Upload artifact
if: ${{ success() || steps.test.conclusion == 'failure'}}
uses: actions/upload-artifact@v3
with:
name: screenshots
# mobile\build\outputs\connected_android_test_additional_output\debugAndroidTest\connected\Pixel_XL_API_32(AVD) - 12\ScreenshotTest_saveDeviceScreenBitmap.png
path: mobile/build/outputs/connected_android_test_additional_output/*

release-fastlane:
needs: [build]
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ clean:

test:
bundle exec fastlane test
#- ./gradlew clean lint test
#- ./gradlew connectedAndroidTest || true
# ./gradlew clean lint test
# ./gradlew connectedAndroidTest # || true

Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("net.activitywatch.android", appContext.packageName)
}

@Test
fun getBuckets() {
// TODO: Clear test buckets before test
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
val ri = RustInterface(appContext)
val bucketId = "test-${Math.random()}"
val oldLen = ri.getBucketsJSON().length()
Expand All @@ -38,7 +38,7 @@ class ExampleInstrumentedTest {

@Test
fun createHeartbeat() {
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
val ri = RustInterface(appContext)
val bucketId = "test-${Math.random()}"
ri.createBucket("""{"id": "$bucketId", "type": "test", "hostname": "test", "client": "test"}""")
Expand Down