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

action: add Android build test #2633

Merged
merged 2 commits into from
Jun 19, 2024
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
20 changes: 20 additions & 0 deletions .github/actions/check-rebuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check if rebuild required
description:

inputs:
mode:
description: build mode to be checked
required: false
default: build

runs:
using: composite
steps:
- run: |
tmpfile=$(mktemp)
git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} | sort | uniq | awk NF > ${tmpfile}
echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV"
rebuild=`bash .github/actions/check-rebuild/check_if_rebuild_requires.sh ${tmpfile} ${{ inputs.mode }} | grep "REBUILD=YES" | wc -l`
echo "Rebuild required: ${rebuild}"
echo "rebuild=${rebuild}" >> "$GITHUB_ENV"
shell: sh
83 changes: 83 additions & 0 deletions .github/actions/check-rebuild/check_if_rebuild_requires.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

##
# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved.
#
# @file: check_if_rebuild_requires.sh
# @brief Check if rebuild & unit-test is required with the given PR.
# @see https://github.com/nnstreamer/nnstreamer
# @author MyungJoo Ham <[email protected]>
#
# Argument 1 ($1): the file containing list of files to be checked.
# Argument 2 ($2): build mode to be checked
# gbs: check if Tizen GBS build is required
# debian: check if pdebuild is required
# android: check if jni rebuild is required
# build (default): check if general meson rebuild is required.

if [ -z $1 ]; then
echo "::error The argument (file path) is not given."
exit 1
fi

if [ -z $2 ]; then
mode="build"
else
mode=$2
fi

rebuild=0
regbs=0
redebian=0
reandroid=0

for file in `cat $1`; do
case $file in
*.md|*.png|*.webp|*.css|*.html )
;;
packaging/* )
regbs='1'
;;
debian/* )
redebian='1'
;;
jni/* )
reandroid='1'
;;
* )
rebuild='1'
regbs='1'
redebian='1'
reandroid='1'
;;
esac
done

case $mode in
gbs)
if [[ "$regbs" == "1" ]]; then
echo "REBUILD=YES"
exit 0
fi
;;
debian)
if [[ "$redebian" == "1" ]]; then
echo "REBUILD=YES"
exit 0
fi
;;
android)
if [[ "$reandroid" == "1" ]]; then
echo "REBUILD=YES"
exit 0
fi
;;
*)
if [[ "$rebuild" == "1" ]]; then
echo "REBUILD=YES"
exit 0
fi
;;
esac

echo "REBUILD=NO"
61 changes: 61 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build test/ Android NDK

on:
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-22.04
name: Android NDK build on Ubuntu for arm64-v8a
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: -${{ github.event.pull_request.commits }}
- name: Check if rebuild required
uses: ./.github/actions/check-rebuild
with:
mode: android
- if: env.rebuild == '1'
uses: nttld/setup-ndk@v1
with:
ndk-version: r26d
link-to-sdk: true
## @todo Make cache works (daily update cache on main branch / restore the cache on each PR (w/o saving))
- name: Prepare Build
if: env.rebuild == '1'
run: |
echo "::group::Install required packages"
sudo apt-get update
sudo apt-get install tar wget gzip libglib2.0-dev libjson-glib-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libunwind-dev googletest liborc-0.4-dev flex bison libopencv-dev pkg-config python3-dev python3-numpy python3 meson ninja-build libflatbuffers-dev flatbuffers-compiler protobuf-compiler
echo "::endgroup::"
- name: NDK Build
if: env.rebuild == '1'
run: |
echo "::group::Run package_android.sh"
./tools/package_android.sh
echo "::endgroup::"
echo "::group::Meson build"
meson build -Dplatform=android
ninja -C build
echo "::endgroup::"
echo "::group::NDK build"
pushd build/jni
ndk-build NDK_PROJECT_PATH=./ APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
popd
echo "::endgroup::"
- name: Install built binaries for application build
if: env.rebuild == '1'
run: |
echo "Installing build bianries for application build"
mkdir -p libs/arm64-v8a
cp -R build/jni/libs/arm64-v8a/* libs/arm64-v8a
- name: Android NNTrainer Application Build
if: env.rebuild == '1'
run: |
echo "::group::LogisticRegression"
pushd Applications/LogisticRegression/jni
ndk-build NDK_PROJECT_PATH=./ APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
popd
echo "::endgroup::"