mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
GitHub Actions: Use self-hosted runner
This commit is contained in:
69
.github/workflows/main.yml
vendored
69
.github/workflows/main.yml
vendored
@@ -7,71 +7,24 @@ on:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
jobs:
|
||||
Build:
|
||||
runs-on: ubuntu-latest
|
||||
Test:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Java Development Kit 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
|
||||
- name: Build Project
|
||||
- name: Build project
|
||||
run: ./build.sh build
|
||||
|
||||
- name: Upload Build Artifacts
|
||||
- name: Run Android tests
|
||||
run: ./build.sh android-tests-parallel 23 24 25 26 27 28 30 31
|
||||
|
||||
- name: Upload artifacts
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: uhabits-android
|
||||
path: uhabits-android/build/outputs/
|
||||
|
||||
AndroidTest:
|
||||
needs: Build
|
||||
runs-on: macOS-10.15
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
matrix:
|
||||
api: [
|
||||
25,
|
||||
27,
|
||||
28,
|
||||
30,
|
||||
31,
|
||||
]
|
||||
|
||||
steps:
|
||||
- name: Check out source code
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Download Previously Built APK
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: uhabits-android
|
||||
path: uhabits-android/build/outputs/
|
||||
|
||||
- name: Install Linux utils
|
||||
run: |
|
||||
brew unlink parallel
|
||||
brew install util-linux moreutils coreutils
|
||||
echo "/usr/local/opt/util-linux/bin" >> $GITHUB_PATH
|
||||
echo "/usr/local/opt/moreutils/bin" >> $GITHUB_PATH
|
||||
echo "/usr/local/opt/coreutils/libexec/gnubin" >> $GITHUB_PATH
|
||||
|
||||
- name: AVD cache
|
||||
uses: actions/cache@v3
|
||||
id: avd-cache
|
||||
with:
|
||||
name: build
|
||||
path: |
|
||||
~/.android/avd/*
|
||||
~/.android/adb*
|
||||
key: avd-${{ matrix.api }}
|
||||
|
||||
- name: Setup AVD
|
||||
if: steps.avd-cache.outputs.cache-hit != 'true'
|
||||
run: ./build.sh android-setup ${{ matrix.api }}
|
||||
|
||||
- name: Run Android Tests
|
||||
run: ./build.sh android-tests ${{ matrix.api }}
|
||||
build/*log
|
||||
uhabits-android/build/outputs
|
||||
|
||||
|
||||
50
build.sh
50
build.sh
@@ -15,7 +15,6 @@
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -o xtrace
|
||||
cd "$(dirname "$0")" || exit
|
||||
|
||||
ADB="${ANDROID_HOME}/platform-tools/adb"
|
||||
@@ -99,11 +98,6 @@ android_setup() {
|
||||
$EMULATOR \
|
||||
-avd $AVDNAME \
|
||||
-port 6${API}0 \
|
||||
-no-window \
|
||||
-gpu swiftshader_indirect \
|
||||
-noaudio \
|
||||
-no-boot-anim \
|
||||
-camera-back none \
|
||||
1>/dev/null 2>&1 &
|
||||
|
||||
log_info "Waiting for emulator to boot..."
|
||||
@@ -114,16 +108,6 @@ android_setup() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Disabling animations..."
|
||||
$ADB root || return 1
|
||||
sleep 5
|
||||
$ADB shell settings put global window_animation_scale 0 || return 1
|
||||
$ADB shell settings put global transition_animation_scale 0 || return 1
|
||||
$ADB shell settings put global animator_duration_scale 0 || return 1
|
||||
|
||||
log_info "Acquiring wake lock..."
|
||||
$ADB shell 'echo android-test > /sys/power/wake_lock' || return 1
|
||||
|
||||
log_info "Saving snapshot..."
|
||||
$ADB emu avd snapshot save fresh-install
|
||||
}
|
||||
@@ -154,6 +138,17 @@ android_boot_attempt() {
|
||||
log_error "Emulator failed to boot after $BOOT_TIMEOUT seconds."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Disabling animations..."
|
||||
$ADB root || return 1
|
||||
sleep 5
|
||||
$ADB shell settings put global window_animation_scale 0 || return 1
|
||||
$ADB shell settings put global transition_animation_scale 0 || return 1
|
||||
$ADB shell settings put global animator_duration_scale 0 || return 1
|
||||
|
||||
log_info "Acquiring wake lock..."
|
||||
$ADB shell 'echo android-test > /sys/power/wake_lock' || return 1
|
||||
|
||||
}
|
||||
|
||||
android_boot() {
|
||||
@@ -216,6 +211,8 @@ android_test() {
|
||||
}
|
||||
|
||||
android_test_parallel() {
|
||||
# Launch background processes
|
||||
PIDS=""
|
||||
for API in $*; do
|
||||
(
|
||||
LOG=build/android-test-$API.log
|
||||
@@ -223,12 +220,27 @@ android_test_parallel() {
|
||||
if android_test $API 1>$LOG 2>&1; then
|
||||
log_info "API $API: Passed"
|
||||
else
|
||||
log_error "API $API: Failed. See $LOG for more details."
|
||||
log_error "API $API: Failed"
|
||||
fi
|
||||
pkill -9 -f ${AVD_PREFIX}${API}
|
||||
)&
|
||||
PIDS+=" $!"
|
||||
done
|
||||
wait
|
||||
|
||||
# Check exit codes
|
||||
RET_CODE=0
|
||||
for pid in $PIDS; do
|
||||
wait $pid || RET_CODE=1
|
||||
done
|
||||
|
||||
# Print all logs
|
||||
for API in $*; do
|
||||
echo "::group::Android Tests (API $API)"
|
||||
cat build/android-test-$API.log
|
||||
echo "::endgroup::"
|
||||
done
|
||||
|
||||
return $RET_CODE
|
||||
}
|
||||
|
||||
android_build() {
|
||||
@@ -300,12 +312,14 @@ CI/CD script for Loop Habit Tracker.
|
||||
|
||||
Usage:
|
||||
build.sh build [options]
|
||||
build.sh android-setup <API>
|
||||
build.sh android-tests <API> [options]
|
||||
build.sh android-tests-parallel <API> <API>... [options]
|
||||
build.sh android-accept-images [options]
|
||||
|
||||
Commands:
|
||||
build Build the app and run small tests
|
||||
android-setup Create Android virtual machine
|
||||
android-tests Run medium and large Android tests on an emulator
|
||||
android-tests-parallel Tests multiple API levels simultaneously
|
||||
android-accept-images Copy fetched images to corresponding assets folder
|
||||
|
||||
Reference in New Issue
Block a user