Semaphore CI
Configure Flaky Tests using Semaphore CI
Getting Started
You can use the analytics test uploader within your Semaphore CI workflows to upload your test results.
The Trunk Flaky Tests Uploader currently only supports Linux x64 and macOS for Intel and Arm. If you have another use case, please get in touch with support at https://slack.trunk.io. For the best results, you'll need to validate that your test invocation doesn't use cached test results and doesn't automatically retry failing tests.
Create a Semaphore workflow that runs the tests you want to monitor. In order for us to use the results, these tests must produce a test report in JUnit XML format.
Find Organization Slug and Token
Next you will need your Trunk organization slug and token. Navigate to app.trunk.io. Once logged in navigate to Settings -> Manage -> Organization. Copy your organization slug. You can find your Trunk token by navigating to Settings → Manage Organization → Organization API Token and clicking "View." Copy this token.
In your Semaphore dashboard, store your Trunk token in a secret named TRUNK_TOKEN. Update your Semaphore workflow to download and run the test uploader binary after you've run your tests.
Sample Semaphore workflow steps
Portion of repo/.semaphore/semaphore.yml
. See the complete file here.
The workflow above configures the cache and then runs npm test
to actually generate the test output XML. The epilogue of the test block uses Semaphore's test-results
command to publish the junit.xml
file to Semaphore. Then it uses the curl command to download the latest version of the trunk-analytics-uploader
, make it executable, and finally run the uploader to send the junit.xml
to Trunk.
The trunk-analytics-uploader
tool has several important arguments.
--junit-paths
is a comma separated list of paths.--org-url-slug
is an identifier for the Trunk account you are using. This is the Organization Slug you copied from your Trunk settings above.--token
is the Trunk API token you added as a Semaphore secret above.
Hourly Tests
Running on a golden branch is how we detect that tests are flaky. Create a copy of your semaphore.yml
file called hourly.yml
. In your Semaphore dashboard, create a new task to run tests on the main branch, and link to the hourly.yml
file. Schedule it to run every hour, every day. Click Create then manually run the workflow to check that it's working. Now you can look at the data being collected in Trunk's Flaky Tests dashboard.
The source for the settings above are available in our SemaphoreFlakyTestExample repo.
If you're interested in better understanding this binary or want to contribute to it, you can find the open source repo here.
Last updated