feat(ci): refactor and separate push to master / PR workflows #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Push to default, build, test, lint, and publish to internal track | |
"on": | |
push: | |
branches: | |
- master | |
paths: | |
- ".github/workflows/build-and-test.yaml" | |
- "project/app/src/**" | |
- "project/app/*.pro" | |
- "project/buildSrc/src/**" | |
- "project/*.gradle.kts" | |
- "project/app/*.gradle.kts" | |
- "project/gradle.properties" | |
- "project/gradle/wrapper/gradle-wrapper.properties" | |
- "project/gradle/libs.versions.toml" | |
env: | |
GRADLE_OPTS: "-Dorg.gradle.daemon=true -Dorg.gradle.configuration-cache=true -Dorg.gradle.parallel=true -Dorg.gradle.caching=true -Dorg.gradle.jvmargs='-Xmx3096M -Dkotlin.daemon.jvm.options=-Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC'" | |
jobs: | |
ktfmt: | |
name: ktfmt | |
runs-on: ubuntu-latest | |
steps: | |
- uses: ./.github/actions/ktfmt | |
build-test-lint: | |
name: Build, test & lint | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
checks: write | |
steps: | |
- uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4 | |
with: | |
distribution: "temurin" | |
java-version: "17" | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- name: Gradle setup | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
dependency-graph: generate-and-submit | |
cache-read-only: false | |
cache-encryption-key: ${{ secrets.GradleEncryptionKey }} | |
- name: Build | |
run: | | |
./project/gradlew -p project assembleDebug lint app:createGmsDebugUnitTestCoverageReport --scan | |
- name: JUnit Report Action | |
uses: mikepenz/action-junit-report@v4 | |
with: | |
report_paths: "**/TEST-*.xml" | |
detailed_summary: true | |
include_passed: false # Lots of test, much output. | |
- name: Upload coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
files: ./project/app/build/reports/coverage/test/gms/debug/report.xml | |
flags: unittests | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload lint report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: lint-report | |
path: project/app/build/reports/lint-results-gmsDebug.html | |
espresso-test: | |
name: "Espresso test" | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
checks: write | |
needs: build-test-lint | |
strategy: | |
fail-fast: false | |
matrix: | |
android-api: [31] | |
flavour: [Gms, Oss] | |
shard: [1, 2, 3, 4, 5, 6] | |
steps: | |
- name: Enable KVM group perms | |
run: | | |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | |
sudo udevadm control --reload-rules | |
sudo udevadm trigger --name-match=kvm | |
- name: Remove unused things | |
run: | | |
sudo rm -rf /opt/ghc # Haskell | |
sudo rm -rf /opt/hostedtoolcache/CodeQL | |
sudo rm -rf /usr/share/dotnet | |
sudo docker image prune --all --force | |
sudo df -h | |
# Github charges us for LFS bandwidth, so let's use the cache | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
lfs: false | |
- name: Create LFS file list | |
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id | |
- name: Restore LFS cache | |
uses: actions/cache@v4 | |
id: lfs-cache | |
with: | |
path: .git/lfs | |
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1 | |
- name: Git LFS Pull | |
run: git lfs pull | |
- uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4 | |
with: | |
distribution: "temurin" # See 'Supported distributions' for available options | |
java-version: "17" | |
- name: Gradle setup | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
dependency-graph: generate | |
cache-encryption-key: ${{ secrets.GradleEncryptionKey }} | |
- name: AVD cache | |
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 | |
id: avd-cache | |
with: | |
path: | | |
~/.android/avd/* | |
~/.android/adb* | |
key: owntracks-test-${{ matrix.android-api }}-${{ matrix.flavour }} | |
- name: Create AVD and generate snapshot for caching | |
timeout-minutes: 10 | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
api-level: ${{ matrix.android-api }} | |
force-avd-creation: false | |
emulator-options: -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -camera-front none -memory 6000 | |
profile: pixel_3a | |
target: ${{ matrix.flavour == 'Gms' && 'google_apis' || 'default' }} | |
ram-size: 6000M | |
avd-name: owntracks-test-${{ matrix.android-api }}-${{ matrix.flavour }} | |
disable-animations: true | |
arch: x86_64 | |
cores: 2 | |
sdcard-path-or-size: 1000M | |
script: | | |
echo "Created AVD snapshot" | |
- name: Espresso Test | |
uses: reactivecircus/android-emulator-runner@v2 | |
timeout-minutes: 30 | |
env: | |
FLAVOUR: ${{ matrix.flavour }} | |
SHARD_COUNT: 6 | |
SHARD_INDEX: ${{ matrix.shard }} | |
with: | |
api-level: ${{ matrix.android-api }} | |
force-avd-creation: false | |
emulator-options: -no-snapshot-save -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -camera-front none -memory 6000 | |
profile: pixel_3a | |
target: ${{ matrix.flavour == 'Gms' && 'google_apis' || 'default' }} | |
ram-size: 6000M | |
disable-animations: true | |
avd-name: owntracks-test-${{ matrix.android-api }}-${{ matrix.flavour }} | |
arch: x86_64 | |
cores: 2 | |
sdcard-path-or-size: 1000M | |
script: | | |
adb shell settings put global bluetooth_on 0 | |
adb shell settings put secure long_press_timeout 1000 | |
adb shell rm -rf /sdcard/googletest || echo "Couldn't delete googletest folder" | |
adb uninstall org.owntracks.android.debug || echo "org.owntracks.android not installed" | |
adb uninstall org.owntracks.android.debug.test || echo "org.owntracks.android.test not installed" | |
./project/gradlew -p project :app:create${FLAVOUR}DebugAndroidTestCoverageReport -Pandroid.testInstrumentationRunnerArguments.numShards=${SHARD_COUNT} -Pandroid.testInstrumentationRunnerArguments.shardIndex=${SHARD_INDEX} --max-workers=1 --scan | |
- name: Upload connected test result artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: espresso-test-reports-${{ matrix.android-api }}-${{ matrix.flavour }}-${{ matrix.shard }} | |
path: ./project/app/build/reports/androidTests/connected/ | |
- name: Espresso JUnit Report | |
uses: mikepenz/action-junit-report@v4 | |
with: | |
report_paths: "**/TEST-*.xml" | |
detailed_summary: true | |
include_passed: false | |
- name: Upload connected test coverage artifact | |
uses: ./.github/actions/upload-artifact | |
with: | |
name: espresso-test-coverage-${{ matrix.android-api }}-${{ matrix.flavour }}-${{ matrix.shard }} | |
path: ./project/app/build/reports/coverage/androidTest/ | |
- name: Upload coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
files: ./project/app/build/reports/coverage/androidTest/${{ matrix.flavour == 'Gms' && 'gms' || 'oss' }}/debug/connected/report.xml | |
flags: uitests | |
token: ${{ secrets.CODECOV_TOKEN }} | |
publish-to-play-store: | |
name: "Publish to Play Store" | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
checks: write | |
needs: espresso-test | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: "17" | |
- name: Create keystore | |
run: | | |
echo -n "${KEYSTORE_BASE64}" | base64 -d > project/owntracks.release.keystore.jks | |
env: | |
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
- name: Setup gradle | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
build-root-directory: project | |
cache-encryption-key: ${{ secrets.GradleEncryptionKey }} | |
- name: Process version codes from play store | |
run: | | |
./project/gradlew -p project clean processGmsVersionCodes | |
cat ./project/app/build/intermediates/gpp/gmsRelease/available-version-codes.txt | |
env: | |
ANDROID_PUBLISHER_CREDENTIALS: ${{ secrets.GOOGLE_CLOUD_SERVICE_ACCOUNT_CREDENTIALS }} | |
- name: Publish Release | |
run: | | |
./project/gradlew -p project publishGmsReleaseBundle --stacktrace --scan | |
env: | |
KEYSTORE_PASSPHRASE: ${{ secrets.KEYSTORE_PASSPHRASE }} | |
ANDROID_PUBLISHER_CREDENTIALS: ${{ secrets.GOOGLE_CLOUD_SERVICE_ACCOUNT_CREDENTIALS }} | |
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }} |