Integrating TestPulse in GitHub Actions
In this section we will modify a GitHub Action pipeline and add a new step that uploads test results to TestPulse.
For simplicity we will use a Java pipeline, but the upload step is not different for other languages!
Our initial GitHub workflow looks like this:
name: Testing Testpulse
on:
push:
branches:
- main
jobs:
fast-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build and run tests
run: ./gradlew clean test
As you can see, we simply checkout the repository, setup Java, and then run ./gradlew clean test
.
When Gradle runs, it will create test reports. We now need to upload these reports to TestPulse to analyze.
Add TestPulse upload step
Since our utility is written in python, you first need to setup a python environment (if not already setup!). Then, install our python utility called testpulse-uploader
using pip install
.
Finally, call testpulse-upload
and pass all the necessary parameters. The full list of parameters is explained in its documentation.
An environment variable named TESTPULSE_TOKEN
should be assigned to the token that’s stored as a secret.
For example:
# code we saw before...
run: ./gradlew clean test
# Setup python environment!
- uses: actions/setup-python@v5
if: '!cancelled()'
with:
python-version: '3.11'
# Upload to testpulse
- name: Upload to testpulse
if: '!cancelled()'
env:
TESTPULSE_TOKEN: $
run: |
pip install testpulse-uploader
testpulse-upload -tr "build/test-results/test/.*\.xml" -cr "build/reports/jacoco/test/.*\.xml" --config-file .testpulse.yaml
The uploader has many options. We suggest you to read its its documentation.
Worth mentioning:
- make sure you modify the path to the test results and coverage files!
- each step has an
if: '!cancelled()'
condition. By default GitHub stops executing steps after the first failure, which means that if there are test failures (the test step fails), the upload does not run and TestPulse does not receive results! Which of course is not what we want. Adding!cancelled()
makes sure that the upload is always executed, except when a workflow is cancelled. TESTPULSE_TOKEN
: make sure to set this env variable, or you will get an authentication error
Push some code and check the results
Configuration-wise, you are done! The next time you run this job, the test results will be imported in TestPulse.