mirror of
https://github.com/bitwarden/android.git
synced 2026-04-29 20:38:41 -05:00
Replace test workflow with sharded parallel CI execution (#6582)
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Álison Fernandes <vvolkgang@users.noreply.github.com>
This commit is contained in:
131
.github/workflows/test.yml
vendored
131
.github/workflows/test.yml
vendored
@@ -15,12 +15,42 @@ env:
|
|||||||
_GITHUB_ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}
|
_GITHUB_ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-sharded:
|
||||||
name: Test
|
name: "Test ${{ matrix.group }}"
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
permissions:
|
permissions:
|
||||||
packages: read
|
packages: read
|
||||||
pull-requests: write
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- group: static-analysis
|
||||||
|
fastlane_method: checkLint
|
||||||
|
fastlane_options: ""
|
||||||
|
# App shards
|
||||||
|
- group: app-data
|
||||||
|
fastlane_method: testAppShard
|
||||||
|
fastlane_options: "--tests com.x8bit.bitwarden.data.*"
|
||||||
|
- group: app-ui-auth-tools
|
||||||
|
fastlane_method: testAppShard
|
||||||
|
fastlane_options: "--tests com.x8bit.bitwarden.ui.auth.* --tests com.x8bit.bitwarden.ui.tools.* --tests com.x8bit.bitwarden.ui.autofill.* --tests com.x8bit.bitwarden.ui.credentials.*"
|
||||||
|
- group: app-ui-platform
|
||||||
|
fastlane_method: testAppShard
|
||||||
|
fastlane_options: "--tests com.x8bit.bitwarden.ui.platform.*"
|
||||||
|
- group: app-ui-vault
|
||||||
|
fastlane_method: testAppShard
|
||||||
|
fastlane_options: "--tests com.x8bit.bitwarden.ui.vault.*"
|
||||||
|
# Authenticator
|
||||||
|
- group: authenticator
|
||||||
|
fastlane_method: testLibraries
|
||||||
|
fastlane_options: ":authenticator"
|
||||||
|
# Library shards
|
||||||
|
- group: lib-core-network-bridge
|
||||||
|
fastlane_method: testLibraries
|
||||||
|
fastlane_options: ":core :network :cxf :authenticatorbridge :testharness"
|
||||||
|
- group: lib-data-ui
|
||||||
|
fastlane_method: testLibraries
|
||||||
|
fastlane_options: ":data :ui"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
@@ -31,49 +61,98 @@ jobs:
|
|||||||
- name: Setup Android Build
|
- name: Setup Android Build
|
||||||
uses: ./.github/actions/setup-android-build
|
uses: ./.github/actions/setup-android-build
|
||||||
|
|
||||||
- name: Build and test
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Used in settings.gradle.kts to download the SDK from GitHub Maven Packages
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
_GROUP: ${{ matrix.group }}
|
||||||
|
_FASTLANE_METHOD: ${{ matrix.fastlane_method }}
|
||||||
|
_FASTLANE_OPTIONS: ${{ matrix.fastlane_options }}
|
||||||
run: |
|
run: |
|
||||||
bundle exec fastlane check
|
if [ "$_GROUP" = "app-ui-auth-tools" ]; then
|
||||||
|
_TOP_LEVEL_TESTS=$(basename -a -s .kt app/src/test/kotlin/com/x8bit/bitwarden/*Test.kt \
|
||||||
|
| xargs -I{} printf ' --tests com.x8bit.bitwarden.{}')
|
||||||
|
_FASTLANE_OPTIONS="${_FASTLANE_OPTIONS} ${_TOP_LEVEL_TESTS}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$_GROUP" = "static-analysis" ]; then
|
||||||
|
bundle exec fastlane "$_FASTLANE_METHOD"
|
||||||
|
else
|
||||||
|
bundle exec fastlane "$_FASTLANE_METHOD" target:"$_FASTLANE_OPTIONS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Generate coverage report
|
||||||
|
if: always() && matrix.group != 'static-analysis' && (github.event_name == 'push' || github.event_name == 'pull_request')
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
bundle exec fastlane generateCoverageReport
|
||||||
|
|
||||||
|
- name: Upload to codecov.io
|
||||||
|
if: always() && matrix.group != 'static-analysis' && (github.event_name == 'push' || github.event_name == 'pull_request')
|
||||||
|
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
os: linux
|
||||||
|
files: build/reports/kover/reportMergedCoverage.xml
|
||||||
|
flags: ${{ matrix.group }}
|
||||||
|
fail_ci_if_error: true
|
||||||
|
disable_search: true
|
||||||
|
|
||||||
- name: Upload test reports
|
- name: Upload test reports
|
||||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||||
if: always()
|
if: always()
|
||||||
with:
|
with:
|
||||||
name: test-reports
|
name: test-reports-${{ matrix.group }}
|
||||||
path: |
|
path: |
|
||||||
build/reports/kover/reportMergedCoverage.xml
|
**/build/reports/tests/
|
||||||
app/build/reports/tests/
|
app/build/reports/lint-results-*.html
|
||||||
authenticator/build/reports/tests/
|
app/build/reports/detekt/
|
||||||
authenticatorbridge/build/reports/tests/
|
if-no-files-found: warn
|
||||||
core/build/reports/tests/
|
|
||||||
data/build/reports/tests/
|
|
||||||
network/build/reports/tests/
|
|
||||||
ui/build/reports/tests/
|
|
||||||
|
|
||||||
- name: Upload to codecov.io
|
coverage-notify:
|
||||||
id: upload-to-codecov
|
name: Coverage Notification
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: test-sharded
|
||||||
|
if: always() && !cancelled() && (github.event_name == 'push' || github.event_name == 'pull_request')
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Notify Codecov that all uploads are complete
|
||||||
|
id: codecov-notify
|
||||||
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
|
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
|
||||||
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
os: linux
|
run_command: send-notifications
|
||||||
files: build/reports/kover/reportMergedCoverage.xml
|
|
||||||
fail_ci_if_error: true
|
|
||||||
disable_search: true
|
|
||||||
|
|
||||||
- name: Comment PR if tests failed
|
- name: Comment PR if coverage notification failed
|
||||||
if: steps.upload-to-codecov.outcome == 'failure' && (github.event_name == 'push' || github.event_name == 'pull_request')
|
if: steps.codecov-notify.outcome == 'failure'
|
||||||
env:
|
env:
|
||||||
PR_NUMBER: ${{ github.event.number }}
|
PR_NUMBER: ${{ github.event.number }}
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
RUN_ACTOR: ${{ github.triggering_actor }}
|
RUN_ACTOR: ${{ github.triggering_actor }}
|
||||||
run: |
|
run: |
|
||||||
echo "> [!WARNING]" >> "$GITHUB_STEP_SUMMARY"
|
echo "> [!WARNING]" >> "$GITHUB_STEP_SUMMARY"
|
||||||
echo "> Uploading code coverage report failed. Please check the \"Upload to codecov.io\" step of \"Process Test Reports\" job for more details." >> "$GITHUB_STEP_SUMMARY"
|
echo "> Uploading code coverage report failed. Please check the \"Notify Codecov\" step for more details." >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
|
||||||
if [ -n "$PR_NUMBER" ]; then
|
if [ -n "$PR_NUMBER" ]; then
|
||||||
message=$'> [!WARNING]\n> @'$RUN_ACTOR' Uploading code coverage report failed. Please check the "Upload to codecov.io" step of [Process Test Reports job]('$_GITHUB_ACTION_RUN_URL') for more details.'
|
message=$'> [!WARNING]\n> @'$RUN_ACTOR' Uploading code coverage report failed. Please check the "Coverage Notification" step of [Test]('$_GITHUB_ACTION_RUN_URL') for more details.'
|
||||||
gh pr comment --repo "$GITHUB_REPOSITORY" "$PR_NUMBER" --body "$message"
|
gh pr comment --repo "$GITHUB_REPOSITORY" "$PR_NUMBER" --body "$message"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
permissions: {}
|
||||||
|
needs: test-sharded
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- name: Ensure sharded tests passed
|
||||||
|
env:
|
||||||
|
TESTS_RESULT: ${{ needs.test-sharded.result }}
|
||||||
|
run: |
|
||||||
|
if [ "$TESTS_RESULT" != "success" ]; then
|
||||||
|
echo "❌ Tests failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "✅ All tests passed!"
|
||||||
|
|||||||
@@ -122,6 +122,39 @@ platform :android do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Run static analysis (detekt + lint)"
|
||||||
|
lane :checkLint do
|
||||||
|
gradle(
|
||||||
|
tasks: [
|
||||||
|
"detekt",
|
||||||
|
"lintStandardDebug",
|
||||||
|
"lintDebug",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Run app module tests for a specific shard"
|
||||||
|
lane :testAppShard do |options|
|
||||||
|
gradle(
|
||||||
|
task: ":app:testStandardDebugUnitTest",
|
||||||
|
flags: options[:target],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Run library module tests for specified modules"
|
||||||
|
lane :testLibraries do |options|
|
||||||
|
tasks = options[:target].split(" ").map { |mod| "#{mod}:testDebugUnitTest" }
|
||||||
|
gradle(tasks: tasks)
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Generate merged Kover coverage report from existing binary data"
|
||||||
|
lane :generateCoverageReport do
|
||||||
|
gradle(
|
||||||
|
task: "koverXmlReportMergedCoverage",
|
||||||
|
flags: "-x testStandardDebugUnitTest -x testDebugUnitTest",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
desc "Apply build version information"
|
desc "Apply build version information"
|
||||||
fastlane_require "time"
|
fastlane_require "time"
|
||||||
lane :setBuildVersionInfo do |options|
|
lane :setBuildVersionInfo do |options|
|
||||||
|
|||||||
Reference in New Issue
Block a user