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

[CI] Better caching and fewer jobs run #503

Merged
merged 3 commits into from
Nov 11, 2023
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
115 changes: 48 additions & 67 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ concurrency:
cancel-in-progress: true

jobs:
build:
test_and_apk:
name: "Local tests and APKs"
runs-on: self-hosted
timeout-minutes: 120

permissions:
contents: write

timeout-minutes: 60

steps:
- name: Checkout
Expand All @@ -42,9 +47,6 @@ jobs:
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Write sign info
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'lihenggui/Blocker'
run: |
Expand All @@ -56,6 +58,9 @@ jobs:
echo ${{ secrets.KEYSTORE }} | base64 --decode > ${{ github.workspace }}/key.jks
fi

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -71,6 +76,38 @@ jobs:
- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache

- name: Run all local screenshot tests (Roborazzi)
id: screenshotsverify
continue-on-error: true
run: ./gradlew verifyRoborazziFossDebug

- name: Prevent pushing new screenshots if this is a fork
id: checkfork
continue-on-error: false
if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository
run: |
echo "::error::Screenshot tests failed, please create a PR in your fork first." && exit 1

# Runs if previous job failed
- name: Generate new screenshots if verification failed and it's a PR
id: screenshotsrecord
if: steps.screenshotsverify.outcome == 'failure' && github.event_name == 'pull_request'
run: |
./gradlew recordRoborazziFossDebug

- name: Push new screenshots if available
uses: stefanzweifel/git-auto-commit-action@v5
if: steps.screenshotsrecord.outcome == 'success'
with:
file_pattern: '*/*.png'
disable_globbing: true
commit_message: "🤖 Updates screenshots"

# Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots.
- name: Run local tests
if: always()
run: ./gradlew testFossDebug testMarketDebug :lint:test

- name: Build all build type and flavor permutations
run: ./gradlew assemble

Expand All @@ -88,10 +125,10 @@ jobs:
name: Market-APK
path: ${{ github.workspace }}/app-compose/build/outputs/apk/market/release

- name: Upload build outputs (Raw-APKs)
- name: Upload build outputs (APKs)
uses: actions/upload-artifact@v3
with:
name: Raw-APKs
name: APKs
path: '**/build/outputs/apk/**/*.apk'

- name: Upload mappings
Expand All @@ -116,65 +153,6 @@ jobs:
with:
apk-path: ${{ steps.apk-path.outputs.foss_path }}

test:
runs-on: self-hosted

permissions:
contents: write

timeout-minutes: 60

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2.9.0

- name: Run all local screenshot tests (Roborazzi)
id: screenshotsverify
continue-on-error: true
run: ./gradlew verifyRoborazziFossDebug

- name: Prevent pushing new screenshots if this is a fork
id: checkfork
continue-on-error: false
if: steps.screenshotsverify.outcome == 'failure' && github.event.pull_request.head.repo.full_name != github.repository
run: |
echo "::error::Screenshot tests failed, please create a PR in your fork first." && exit 1

# Runs if previous job failed
- name: Generate new screenshots if verification failed and it's a PR
id: screenshotsrecord
if: steps.screenshotsverify.outcome == 'failure' && github.event_name == 'pull_request'
run: |
./gradlew recordRoborazziFossDebug

- name: Push new screenshots if available
uses: stefanzweifel/git-auto-commit-action@v5
if: steps.screenshotsrecord.outcome == 'success'
with:
file_pattern: '*/*.png'
disable_globbing: true
commit_message: "🤖 Updates screenshots"

# Run local tests after screenshot tests to avoid wrong UP-TO-DATE. TODO: Ignore screenshots.
- name: Run local tests
if: always()
run: ./gradlew testFossDebug testMarketDebug :lint:test

- name: Upload test results (XML)
if: always()
uses: actions/upload-artifact@v3
Expand All @@ -195,7 +173,7 @@ jobs:
run: ./gradlew :app-compose:checkMarketReleaseBadging

androidTest:
needs: build
needs: test_and_apk
runs-on: self-hosted
timeout-minutes: 90
strategy:
Expand All @@ -221,6 +199,9 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2.9.0

- name: Build projects before running emulator
run: ./gradlew packageFossDebug packageFossDebugAndroidTest

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ org.gradle.configureondemand=false
org.gradle.caching=true
# Enable configuration caching between builds.
org.gradle.configuration-cache=true
# This option is set because of https://github.com/google/play-services-plugins/issues/246
# to generate the Configuration Cache regardless of incompatible tasks.
# See https://github.com/android/nowinandroid/issues/1022 before using it.
org.gradle.configuration-cache.problems=warn
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
Expand Down
Loading