GitHub Actions Quickstart

Configure Flaky Tests detection using a GitHub Action

Configuring the Analytics Uploader Action

The Analytics Uploader Action uploads test reports to Trunk Analytics from your GitHub workflows. Here are the steps for setting it up:

  1. Create a GitHub workflow that runs the tests you want to monitor and produces a test report in JUnit XML format. Be careful that your test invocation doesn't use cached test results, and doesn't automatically retry failing tests.

  2. Modify your GitHub workflow to add the Trunk Analytics Uploader Action as the step after your tests run. Point the uploader to the locations on disk where your test runner outputs Junit XML files:

      - name: Upload results
        # Run this step even if the test step ahead fails
        if: "!cancelled()"
        uses: trunk-io/analytics-uploader@main
        with:
          # Path to your test results.
          junit-paths: target/path/**/*_test.xml
          # Provide your Trunk organization slug.
          org-slug: my-trunk-org
          # Provide your Trunk API token as a GitHub secret.
          token: ${{ secrets.TRUNK_API_TOKEN }}
        continue-on-error: true
  1. To find your organization slug, you can open app.trunk.io. Once you are logged in, you should be automatically redirected to a URL like https://app.trunk.io/my-org-slug/repo-owner/repo-name/ci-analytics.

  2. You can find your Trunk token by navigating to Settings → Manage Organization → Organization API Token and clicking "View". Provide this token as a GitHub secret.


Sample GitHub Actions workflow file:

name: Upload Test Results
on:
  workflow_dispatch: {}
  schedule:
    # run every hour on the hour
    - cron: 0 * * * *

permissions: read-all

jobs:
  test:
    name: Run Tests
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v4

      - name: Install Dependencies
        run: npm ci

      - name: Run Jest Tests
        run: npm test

      - name: Upload Jest Test Results
        uses: trunk-io/analytics-uploader@main
        # Upload the results even if the tests fail
        if: "!cancelled()"
        with:
          junit-paths: junit.xml
          org-slug: matt
          token: ${{ secrets.TRUNK_API_TOKEN }}
        # don't fail this job if the upload fails
        continue-on-error: true

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