-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from buildkite/feature/send-ci-info-to-test-an…
…alytics Detect CI environment and send associated data along with the test suite
- Loading branch information
Showing
30 changed files
with
1,293 additions
and
425 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,30 @@ on: | |
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
BUILDKITE_ANALYTICS_TOKEN: ${{ secrets.BUILDKITE_ANALYTICS_TOKEN }} | ||
BUILDKITE_ANALYTICS_DEBUG_ENABLED: ${{ secrets.BUILDKITE_ANALYTICS_DEBUG_ENABLED }} | ||
GITHUB_ACTION: ${{ github.action }} | ||
GITHUB_RUN_ID: ${{ github.run_id }} | ||
GITHUB_RUN_NUMBER: ${{ github.run_number }} | ||
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }} | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
GITHUB_REF_NAME: ${{ github.ref_name }} | ||
GITHUB_SHA: ${{ github.sha }} | ||
GITHUB_WORKFLOW: ${{ github.workflow }} | ||
GITHUB_ACTOR: ${{ github.actor }} | ||
|
||
jobs: | ||
example-project-unit-tests: | ||
name: Run Example Project Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
BUILDKITE_ANALYTICS_TOKEN: ${{ secrets.BUILDKITE_ANALYTICS_TOKEN }} | ||
BUILDKITE_ANALYTICS_DEBUG_ENABLED: ${{ secrets.BUILDKITE_ANALYTICS_DEBUG_ENABLED }} | ||
|
||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3.3.0 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: zulu | ||
java-version: 17 | ||
|
@@ -33,28 +42,39 @@ jobs: | |
|
||
example-project-instrumented-tests: | ||
name: Run Example Project Instrumented Tests | ||
runs-on: macos-latest | ||
|
||
env: | ||
BUILDKITE_ANALYTICS_TOKEN: ${{ secrets.BUILDKITE_ANALYTICS_TOKEN }} | ||
BUILDKITE_ANALYTICS_DEBUG_ENABLED: ${{ secrets.BUILDKITE_ANALYTICS_DEBUG_ENABLED }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
api-level: [28] | ||
timeout-minutes: 90 | ||
|
||
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 | ||
ls /dev/kvm | ||
- name: Git Checkout | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3.3.0 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: zulu | ||
java-version: 17 | ||
|
||
- name: Debug Build | ||
run: ./gradlew :example:buildDebug | ||
|
||
- name: Example Project Instrumented Tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
- name: "Run instrumented tests" | ||
uses: reactivecircus/[email protected] | ||
with: | ||
api-level: 27 | ||
api-level: ${{ matrix.api-level }} | ||
force-avd-creation: false | ||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -timezone Australia/Melbourne -camera-back none | ||
disable-animations: true | ||
disable-spellchecker: true | ||
profile: Nexus 6 | ||
arch: x86_64 | ||
ram-size: 4096M | ||
heap-size: 512M | ||
script: "support/scripts/example-instrumented-tests" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# CI Environment Variables Setup | ||
|
||
This document provides instructions for setting up environment variables for different CI platforms to enrich test reports. | ||
|
||
## Accessing Environment Variables in CI Configuration | ||
|
||
To enrich your test reports with valuable CI information such as commit messages, branch names, and build numbers, you need to pass environment variables in your CI pipeline. | ||
For example, here is how you can set up the environment variables for GitHub Actions: | ||
|
||
### GitHub Actions | ||
|
||
In your GitHub Actions workflow configuration, add the following environment variables: | ||
|
||
```yaml | ||
env: | ||
BUILDKITE_ANALYTICS_TOKEN: ${{ secrets.BUILDKITE_ANALYTICS_TOKEN }} | ||
GITHUB_ACTION: ${{ github.action }} | ||
GITHUB_RUN_ID: ${{ github.run_id }} | ||
GITHUB_RUN_NUMBER: ${{ github.run_number }} | ||
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }} | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
GITHUB_REF_NAME: ${{ github.ref_name }} | ||
GITHUB_SHA: ${{ github.sha }} | ||
GITHUB_WORKFLOW: ${{ github.workflow }} | ||
GITHUB_ACTOR: ${{ github.actor }} | ||
``` | ||
## Additional Setup for Instrumented Tests | ||
While the above setup is sufficient for unit tests collector, instrumented tests collector require additional configuration. Below are examples for different CI platforms supported by the test collectors. | ||
In your build.gradle.kts file, add the following to pass the required environment variables for instrumented tests: | ||
### Buildkite | ||
``` | ||
android { | ||
... | ||
defaultConfig { | ||
... | ||
testInstrumentationRunnerArguments["BUILDKITE_ANALYTICS_TOKEN"] = System.getenv("BUILDKITE_ANALYTICS_TOKEN") | ||
testInstrumentationRunnerArguments["BUILDKITE_BUILD_ID"] = System.getenv("BUILDKITE_BUILD_ID") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_BUILD_URL"] = System.getenv("BUILDKITE_BUILD_URL") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_BRANCH"] = System.getenv("BUILDKITE_BRANCH") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_COMMIT"] = System.getenv("BUILDKITE_COMMIT") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_BUILD_NUMBER"] = System.getenv("BUILDKITE_BUILD_NUMBER") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_JOB_ID"] = System.getenv("BUILDKITE_JOB_ID") ?: "" | ||
testInstrumentationRunnerArguments["BUILDKITE_MESSAGE"] = System.getenv("BUILDKITE_MESSAGE") ?: "" | ||
} | ||
} | ||
``` | ||
|
||
### GitHub Actions | ||
|
||
``` | ||
android { | ||
... | ||
defaultConfig { | ||
... | ||
testInstrumentationRunnerArguments["BUILDKITE_ANALYTICS_TOKEN"] = System.getenv("BUILDKITE_ANALYTICS_TOKEN") | ||
testInstrumentationRunnerArguments["GITHUB_ACTION"] = System.getenv("GITHUB_ACTION") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_RUN_ID"] = System.getenv("GITHUB_RUN_ID") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_RUN_NUMBER"] = System.getenv("GITHUB_RUN_NUMBER") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_RUN_ATTEMPT"] = System.getenv("GITHUB_RUN_ATTEMPT") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_REPOSITORY"] = System.getenv("GITHUB_REPOSITORY") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_REF_NAME"] = System.getenv("GITHUB_REF_NAME") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_SHA"] = System.getenv("GITHUB_SHA") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_WORKFLOW"] = System.getenv("GITHUB_WORKFLOW") ?: "" | ||
testInstrumentationRunnerArguments["GITHUB_ACTOR"] = System.getenv("GITHUB_ACTOR") ?: "" | ||
} | ||
} | ||
``` | ||
|
||
### CircleCI | ||
|
||
``` | ||
android { | ||
... | ||
defaultConfig { | ||
... | ||
testInstrumentationRunnerArguments["BUILDKITE_ANALYTICS_TOKEN"] = System.getenv("BUILDKITE_ANALYTICS_TOKEN") | ||
testInstrumentationRunnerArguments["CIRCLE_BUILD_NUM"] = System.getenv("CIRCLE_BUILD_NUM") ?: "" | ||
testInstrumentationRunnerArguments["CIRCLE_WORKFLOW_ID"] = System.getenv("CIRCLE_WORKFLOW_ID") ?: "" | ||
testInstrumentationRunnerArguments["CIRCLE_BUILD_URL"] = System.getenv("CIRCLE_BUILD_URL") ?: "" | ||
testInstrumentationRunnerArguments["CIRCLE_BRANCH"] = System.getenv("CIRCLE_BRANCH") ?: "" | ||
testInstrumentationRunnerArguments["CIRCLE_SHA1"] = System.getenv("CIRCLE_SHA1") ?: "" | ||
} | ||
} | ||
``` | ||
|
||
By following these steps, you ensure that your CI environment variables are passed correctly to your Android instrumentation and unit tests. | ||
For a complete setup example, check out the [example](example) project in the repository. |
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
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
Oops, something went wrong.