diff --git a/api/authentication.mdx b/api/authentication.mdx index a365745f..a4d8654d 100644 --- a/api/authentication.mdx +++ b/api/authentication.mdx @@ -47,7 +47,7 @@ Each permission adds writes: | **Skip batching** | Opt a pull request out of batching so it gets a test run of its own. | A submit that sends `allowBatching: false`; a queue-entry update that sends `allowBatching` | | **Merge PRs with direct to queue** | Send a pull request to the queue before branch protection is satisfied. The queue's own tests still run and still gate the merge. | A submit that sends `direct: true`; a queue-entry update that sends `direct` | | **Update Merge Queue settings** | Change queue settings; pause, resume, or drain a queue; and create or delete queues. | [Create](/api/mergequeues/create-a-merge-queue), [delete](/api/mergequeues/delete-a-merge-queue), [update configuration](/api/mergequeues/update-a-merge-queues-configuration), [switch modes](/api/mergequeues/switch-a-merge-queues-mode), [pause](/api/mergequeues/pause-a-merge-queue), [resume](/api/mergequeues/resume-a-merge-queue), [drain](/api/mergequeues/drain-a-merge-queue) | -| **Upload test results** (Flaky Tests) | Upload test results from CI, including looking up which tests are quarantined before the upload. | Test-results uploads through the API. The Trunk Analytics CLI and `trunk-io/analytics-uploader` don't use it yet | +| **Upload test results** (Flaky Tests) | Upload test results from CI, including looking up which tests are quarantined before the upload. | Test-results uploads from the [`trunk` CLI](/flaky-tests/get-started/trunk-cli) (`trunk flakytests`), the Trunk Analytics CLI 1.0.0 and later, and `trunk-io/analytics-uploader@v3` | | **Quarantine tests** (Flaky Tests) | Always or never quarantine a test whatever its monitors decided, or clear that override, for one test or many at once. | [One test](/api/tests/set-a-tests-quarantine-override), [many tests](/api/tests/set-quarantine-overrides-on-many-tests) | | **Flag tests** (Flaky Tests) | Mark a test flaky by hand or clear that mark, and add or remove a test's labels. | [Mark flaky](/api/tests/mark-a-test-flaky), [clear the mark](/api/tests/clear-a-tests-flaky-mark), [add labels](/api/tests/add-labels-to-a-test), [remove labels](/api/tests/remove-labels-from-a-test) | | **Manage monitors** (Flaky Tests) | Create monitors and change their settings, including turning a monitor off for every test. | [Create](/api/testcollections/create-a-monitor), [edit](/api/monitors/edit-a-monitor) | diff --git a/docs.json b/docs.json index bfc5c7c5..3af500fb 100644 --- a/docs.json +++ b/docs.json @@ -208,6 +208,7 @@ "group": "Getting Started", "root": "flaky-tests/get-started/index", "pages": [ + "flaky-tests/get-started/trunk-cli", { "group": "Test frameworks", "root": "flaky-tests/get-started/frameworks", diff --git a/flaky-tests/get-started/ci-providers/depot-ci.mdx b/flaky-tests/get-started/ci-providers/depot-ci.mdx index 25475f64..69b50476 100644 --- a/flaky-tests/get-started/ci-providers/depot-ci.mdx +++ b/flaky-tests/get-started/ci-providers/depot-ci.mdx @@ -16,31 +16,31 @@ Before you start these steps, see the [Test Frameworks](../frameworks/) docs for Work through the steps below in order. Once you've finished the last one, you're set up — navigate to [app.trunk.io](https://app.trunk.io) to see your results. - Get your Trunk organization slug, token, and collection ID} /> - Set your token as a secret in Depot CI} /> + Get your Trunk organization slug, API key, and collection ID} /> + Set your API key as a secret in Depot CI} /> Configure Depot CI to upload to Trunk} /> Validate your uploads in Trunk} /> -## Trunk Organization Slug and Token +## Trunk Organization Slug and API Key -Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, your token, and the ID of the test collection to upload to. +Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, an API key, and the ID of the test collection to upload to. ### Trunk Slug You can find your organization slug under **Settings** → **Organization** → **General**. -### Trunk Token +### Trunk API Key -You can find your token under **Settings** → **Developer** → **API Keys**, in the **Organization API token (v1)** section. Since this is a secret, do not leak it publicly. Ensure you get your _organization token_, not an API key or a repo token. +Create an API key under **Settings** → **Developer** → **API Keys** with the **Create Key** button, and select the **Upload test results** permission. The key starts with `trunk_v2_` and is shown only once. See [Create an API key](/flaky-tests/get-started/trunk-cli#create-an-api-key). ### Test Collection ID Create a [test collection](/flaky-tests/test-collections) under **Flaky Tests** → **Collections**, or open an existing one, and copy its ID from the collection's page header. It is not a secret, so you can include it directly in your upload command. -## Add Your Trunk Token as a Secret +## Add Your API Key as a Secret -Store the Trunk API token as a [Depot CI secret](https://depot.dev/docs/ci/how-to-guides/manage-secrets-and-variables) named `TRUNK_API_TOKEN`. If you already store it as a GitHub secret, `depot ci migrate secrets-and-vars` imports it. +Store the API key as a [Depot CI secret](https://depot.dev/docs/ci/how-to-guides/manage-secrets-and-variables) named `TRUNK_API_KEY`. If you already store it as a GitHub secret, `depot ci migrate secrets-and-vars` imports it. ## Upload to Trunk @@ -67,12 +67,12 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} # Upload the results even if the tests fail continue-on-error: true # don't fail this job if the upload fails - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: "**/junit.xml" org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` The action accepts every report format the GitHub Actions guide shows (XCResult, Bazel BEP, Swift Test XUnit). See the [Analytics Uploader reference](https://github.com/trunk-io/analytics-uploader) for all available arguments. @@ -94,4 +94,4 @@ Once your workflow has run on a stable branch, navigate to [app.trunk.io](https: - The **Uploads** tab lists every report Trunk has ingested, with status and any warnings (missing file paths, malformed XML, and so on). - The **Tests** tab shows individual test cases once an upload has been processed. -If a recent run isn't showing up, check the job logs in Depot for upload errors and confirm your `TRUNK_API_TOKEN` secret is available to the workflow and the collection ID is correct. +If a recent run isn't showing up, check the job logs in Depot for upload errors and confirm your `TRUNK_API_KEY` secret is available to the workflow and the collection ID is correct. diff --git a/flaky-tests/get-started/ci-providers/github-actions.mdx b/flaky-tests/get-started/ci-providers/github-actions.mdx index fb03f913..86fa9bda 100644 --- a/flaky-tests/get-started/ci-providers/github-actions.mdx +++ b/flaky-tests/get-started/ci-providers/github-actions.mdx @@ -3,7 +3,7 @@ title: "GitHub Actions" description: "Configure Flaky Tests detection using a GitHub Action" og:title: "Using GitHub Actions with Trunk Flaky Tests" --- -Trunk Flaky Tests integrates with your CI by adding a step in your GitHub Action workflow to upload tests with the [Trunk Analytics CLI](../../reference/cli-reference). +Trunk Flaky Tests integrates with your CI by adding a step in your GitHub Action workflow that uploads tests with the [`trunk-io/analytics-uploader`](https://github.com/trunk-io/analytics-uploader) action. Version 3 of the action installs the [`trunk` CLI](../trunk-cli) and runs `trunk flakytests` for you. Before you start these steps, see the [Test Frameworks](../frameworks/) docs for instructions on producing Trunk-compatible reports for your test framework. @@ -12,31 +12,31 @@ Before you start these steps, see the [Test Frameworks](../frameworks/) docs for Work through the steps below in order. Once you've finished the last one, you're set up — navigate to [app.trunk.io](https://app.trunk.io) to see your results. - Get your Trunk organization slug, token, and collection ID} /> - Set your slug and token as secrets in GitHub Actions} /> + Get your Trunk organization slug, API key, and collection ID} /> + Store your API key as a secret in GitHub Actions} /> Configure GitHub Actions to upload to Trunk} /> Validate your uploads in Trunk} /> -## Trunk Organization Slug and Token +## Trunk Organization Slug and API Key -Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, your token, and the ID of the test collection to upload to. +Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, an API key, and the ID of the test collection to upload to. ### Trunk Slug You can find your organization slug under **Settings** → **Organization** → **General**. You'll save this as a variable in CI in a later step. -### Trunk Token +### Trunk API Key -You can find your token under **Settings** → **Developer** → **API Keys**, in the **Organization API token (v1)** section. Since this is a secret, do not leak it publicly. Ensure you get your _organization token_, not an API key or a repo token. +Create an API key under **Settings** → **Developer** → **API Keys** with the **Create Key** button, and select the **Upload test results** permission. The key starts with `trunk_v2_` and is shown only once. See [Create an API key](/flaky-tests/get-started/trunk-cli#create-an-api-key). ### Test Collection ID Create a [test collection](/flaky-tests/test-collections) under **Flaky Tests** → **Collections**, or open an existing one, and copy its ID from the collection's page header. It is not a secret, so you can include it directly in your upload command. -## Add Your Trunk Token and Organization Slug as Secrets +## Add Your API Key as a Secret -Store the Trunk slug and API token obtained in the previous step in your repo as [GitHub secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) named `TRUNK_ORG_URL_SLUG` and `TRUNK_API_TOKEN` respectively. +Store the API key from the previous step in your repo as a [GitHub secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) named `TRUNK_API_KEY`. The organization slug isn't a secret, so you can write it in the workflow or store it as a variable. ## Upload to Trunk @@ -52,7 +52,7 @@ Trunk can also detect test flakes on PR and merge branches. To best detect flaky ### Example GitHub Actions Workflow -The following is an example of a GitHub Actions workflow step to upload test results after your tests using Trunk's [**Analytics Uploader Action**](https://github.com/trunk-io/analytics-uploader). +The following is an example of a GitHub Actions workflow step to upload test results after your tests using Trunk's [**Analytics Uploader Action**](https://github.com/trunk-io/analytics-uploader). The action runs on Linux and macOS runners (macOS 14 or later). Windows runners are experimental. To find out how to produce the report files the uploader needs, see the instructions for your test framework in the [**Test Frameworks**](../frameworks/) docs. @@ -70,12 +70,12 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} # Upload the results even if the tests fail continue-on-error: true # don't fail this job if the upload fails - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: **/junit.xml org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` ```yaml XCResult Path jobs: @@ -90,12 +90,12 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} # Upload the results even if the tests fail continue-on-error: true # don't fail this job if the upload fails - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: xcresult-path: ./test-results.xcresult org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` ```yaml Bazel BEP JSON jobs: @@ -110,12 +110,12 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} # Upload the results even if the tests fail continue-on-error: true # don't fail this job if the upload fails - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: bazel-bep-path: ./build_events.json org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` ```yaml Swift Test XUnit jobs: @@ -130,14 +130,14 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} # Upload the results even if the tests fail continue-on-error: true # don't fail this job if the upload fails - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: # One run writes both: swift-testing results to junit-swift-testing.xml # and XCTest results to junit.xml, so one glob covers the pair. swift-test-xunit-paths: junit*.xml org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` ```yaml RSpec plugin jobs: @@ -147,13 +147,23 @@ jobs: steps: - name: Run Tests and Upload Results to Trunk.io - run: TRUNK_ORG_URL_SLUG=${{ vars.TRUNK_ORG_URL_SLUG }} TRUNK_TEST_COLLECTION_ID= TRUNK_API_TOKEN=${{ secrets.TRUNK_API_TOKEN }} bundle exec rspec + run: TRUNK_ORG_URL_SLUG=${{ vars.TRUNK_ORG_URL_SLUG }} TRUNK_TEST_COLLECTION_ID= TRUNK_API_TOKEN=${{ secrets.TRUNK_API_KEY }} bundle exec rspec ``` See the [GitHub Actions Reference page](https://github.com/trunk-io/analytics-uploader) for all available CLI arguments and usage. +### Upgrading from v2 + +Version 3 of the action runs the Trunk Analytics CLI 1.x through the `trunk` CLI. To move a workflow from `@v2` to `@v3`: + +- Replace the `token` value with an API key that has the **Upload test results** permission. The Trunk Analytics CLI 1.x refuses the legacy organization token. To keep using that token for now, stay on `@v2`, which runs a 0.x release of the Trunk Analytics CLI. +- Set `test-collection-id` on every step. It's required. +- Remove the `hide-banner` and `public-repo-id` inputs. Version 3 doesn't have them. For uploads from fork pull requests, use [`allow-forked-pr-uploads`](../fork-pr-uploads). + +`quarantine: false` still turns off quarantining for the step. + ### Enable quarantining You can quarantine flaky tests by wrapping the test command or as a follow-up step. @@ -185,12 +195,12 @@ Here's an example file. - name: Upload test results if: always() - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: org-slug: my-trunk-org-slug test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` If you want to run the test command and upload in a single step, the test command must be **run via the Analytics Uploader** through the `run: ` parameter. @@ -210,46 +220,58 @@ This will override the response code of the test command. Make sure to set `cont uses: actions/checkout@v3 - name: Run tests and upload results - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: run: # command to run tests goes here org-slug: my-trunk-org-slug test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` - + **Using Flaky Tests as a separate step** If you upload your test results as a second step after you run your tests, you need to make sure your test step **continues on errors** so the upload step that's run after can quarantine failed tests. -When quarantining is enabled, the `trunk-analytics-cli upload` command will **return an error** if there are unquarantined failures and return a status code 0 if all tests are quarantined. +When quarantining is enabled, the `trunk flakytests upload` command will **return an error** if there are unquarantined failures and return a status code 0 if all tests are quarantined. -```sh +Install the [`trunk` CLI](../trunk-cli) and store your API key first: + +```yaml + - name: Install the trunk CLI + run: | + curl -fsSL https://install.trunk.io | sh -s -- --install-dir "$RUNNER_TEMP/trunk" + echo "$RUNNER_TEMP/trunk" >> "$GITHUB_PATH" + + - name: Store the Trunk API key + run: trunk auth api-key set + env: + TRUNK_ORG_API_KEY: ${{ secrets.TRUNK_API_KEY }} +``` + +```sh || true # doesn't fail job on failure -| - ./trunk-analytics-cli upload \ - --org-url-slug $TRUNK_ORG_URL_SLUG \ - --test-collection-id \ - --token $TRUNK_API_TOKEN \ - --junit-paths $JUNIT_PATH + +trunk flakytests upload \ + --org-url-slug $TRUNK_ORG_URL_SLUG \ + --test-collection-id \ + --junit-paths $JUNIT_PATH ``` **Using Flaky Tests as a single step** -You can also wrap the test command with the Trunk Analytics CLI. When wrapping the command with the Trunk Analytics CLI, if there are unquarantined tests, the command will return an error. If there are no unquarantined tests, the command will return a status code `0`. +You can also wrap the test command with `trunk flakytests test`. If there are unquarantined tests, the command will return an error. If there are no unquarantined tests, the command will return a status code `0`. ```bash -./trunk-analytics-cli test \ +trunk flakytests test \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ --junit-paths $JUNIT_PATH \ --allow-empty-test-results \ - + -- ``` @@ -265,7 +287,7 @@ Once your workflow has run on a stable branch, navigate to [app.trunk.io](https: - The **Uploads** tab lists every report Trunk has ingested, with status and any warnings (missing file paths, malformed XML, and so on). - The **Tests** tab shows individual test cases once an upload has been processed. -If a recent run isn't showing up, check the action logs for upload errors and confirm your `TRUNK_API_TOKEN` and `TRUNK_ORG_URL_SLUG` secrets are set on the repo running the workflow and the collection ID is correct. +If a recent run isn't showing up, check the action logs for upload errors and confirm your `TRUNK_API_KEY` secret is set on the repo running the workflow, the key has the **Upload test results** permission, and the collection ID is correct. ## Getting Direct Links to Job Logs @@ -310,12 +332,12 @@ jobs: - name: Upload test results if: always() - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: org-slug: my-trunk-org-slug test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} env: JOB_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.get-job-id.outputs.jobId }} ``` @@ -352,12 +374,12 @@ jobs: - name: Upload test results if: always() - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: junit.xml org-slug: my-trunk-org-slug test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} env: JOB_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.get-job-id.outputs.jobId }} ``` diff --git a/flaky-tests/get-started/ci-providers/otherci.mdx b/flaky-tests/get-started/ci-providers/otherci.mdx index 293bf977..d49f9bbf 100644 --- a/flaky-tests/get-started/ci-providers/otherci.mdx +++ b/flaky-tests/get-started/ci-providers/otherci.mdx @@ -3,7 +3,7 @@ title: "Other CI Providers" description: "Configure Flaky Tests using any CI Provider" og:title: "Using other CI providers with Trunk Flaky Tests" --- -Trunk Flaky Tests integrates with your CI provider by adding an upload step in each of your testing CI jobs via the [Trunk Analytics CLI](../../reference/cli-reference). +Trunk Flaky Tests integrates with your CI provider by adding an upload step in each of your testing CI jobs via the [`trunk` CLI](../trunk-cli). **Not using GitHub for source control?** @@ -18,31 +18,33 @@ Before you start on these steps, see the [Test Frameworks](../frameworks/) docs Work through the steps below in order. Once you've finished the last one, you're set up — navigate to [app.trunk.io](https://app.trunk.io) to see your results. - Get your Trunk organization slug, token, and collection ID} /> - Set your slug and token as a variable in CI} /> + Get your Trunk organization slug, API key, and collection ID} /> + Store your slug and API key in CI} /> Configure your CI to upload to Trunk} /> Validate your uploads in Trunk} /> -## Trunk Organization Slug and Token + -Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, your token, and the ID of the test collection to upload to. +## Trunk Organization Slug and API Key + +Before setting up uploads to Trunk, you must sign in to [app.trunk.io](https://app.trunk.io/login?intent=flaky%20tests) and obtain your Trunk organization slug, an API key, and the ID of the test collection to upload to. ### Trunk Slug You can find your organization slug under **Settings** → **Organization** → **General**. You'll save this as a variable in CI in a later step. -### Trunk Token +### Trunk API Key -You can find your token under **Settings** → **Developer** → **API Keys**, in the **Organization API token (v1)** section. Since this is a secret, do not leak it publicly. Ensure you get your _organization token_, not an API key or a repo token. +Create an API key under **Settings** → **Developer** → **API Keys** with the **Create Key** button, and select the **Upload test results** permission. The key starts with `trunk_v2_` and is shown only once. See [Create an API key](/flaky-tests/get-started/trunk-cli#create-an-api-key). ### Test Collection ID Create a [test collection](/flaky-tests/test-collections) under **Flaky Tests** → **Collections**, or open an existing one, and copy its ID from the collection's page header. It is not a secret, so you can include it directly in your upload command. -## Add the Trunk Token as a Secret +## Add the API Key as a Secret -Store the Trunk slug and API token obtained in the previous step in your CI provider as a secret, environment variable, or an equivalent concept and name them `TRUNK_ORG_URL_SLUG` and `TRUNK_API_TOKEN` respectively. +Store the API key in your CI provider as a secret named `TRUNK_API_KEY`. Store the organization slug as a variable named `TRUNK_ORG_URL_SLUG`. ## Upload to Trunk @@ -58,71 +60,61 @@ Trunk can also detect test flakes on PR and merge branches. To best detect flaky ### Example Upload Script -The following is an example of a script to upload test results after your tests run. Note: you must either run `trunk` from the repo root when uploading test results or pass a `--repo-root` argument. +The following script installs the [`trunk` CLI](../trunk-cli), stores your API key, and uploads test results after your tests run. Run `trunk flakytests` from the repository root, or pass `--repo-root`. To find out how to produce the report files the uploader needs, see the instructions for your test framework in the [frameworks](../frameworks/) docs. -You can install the Trunk Analytics CLI locally like this: +```bash +curl -fsSL https://install.trunk.io | sh +TRUNK_ORG_API_KEY="$TRUNK_API_KEY" trunk auth api-key set - -```bash Linux (x64) -SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ - "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ - | tar -xz + -chmod +x trunk-analytics-cli +trunk flakytests upload --junit-paths \ + --org-url-slug "$TRUNK_ORG_URL_SLUG" \ + --test-collection-id ``` -```bash Linux (arm64) -SKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ - "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ - | tar -xz -chmod +x trunk-analytics-cli -``` -```bash macOS (arm64) -SKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ - "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ - | tar -xz +To run your tests and upload in one step, so that [quarantined](../../quarantining/) failures don't fail the job, wrap the test command instead: -chmod +x trunk-analytics-cli +```bash +trunk flakytests test --junit-paths \ + --org-url-slug "$TRUNK_ORG_URL_SLUG" \ + --test-collection-id \ + -- ``` -```bash macOS (x64) -SKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ - "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ - | tar -xz -chmod +x trunk-analytics-cli -``` - +The installer supports Linux and macOS 14 or later. If it reports that its install directory isn't on your `PATH`, add it, or pass `--install-dir`. Most CI providers set `CI=true`, which turns off the CLI's automatic updates; to pin the CLI and the Trunk Analytics CLI it runs, see [Pin versions](../trunk-cli#pin-versions). -Then, you can validate the results using the `trunk-analytics-cli validate` command like this: + +Run `trunk flakytests validate --junit-paths ` on your reports before you upload to catch malformed JUnit XML early. + -```bash -./trunk-analytics-cli validate --junit-paths -``` +See the [CLI reference](../../reference/cli-reference) for all available command line arguments and usage. + +### Running trunk-analytics-cli directly -Then upload them: +You can also download the Trunk Analytics CLI and run it yourself, without the `trunk` CLI. Pass it the API key with `--token` or the `TRUNK_API_TOKEN` environment variable: ```bash +SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz" +VERSION=$(curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \ + https://trunk.io/releases/analytics-cli/prod/channel-1.json | cut -d'"' -f4) +curl -fL --connect-timeout 10 --max-time 60 --retry 3 \ + "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ + | tar -xz + ./trunk-analytics-cli upload --junit-paths \ - --org-url-slug $TRUNK_ORG_URL_SLUG \ + --org-url-slug "$TRUNK_ORG_URL_SLUG" \ --test-collection-id \ - --token $TRUNK_API_TOKEN + --token "$TRUNK_API_KEY" ``` -See the [uploader.md](../../reference/cli-reference.md) for all available command line arguments and usage. +For the other platforms and for pinning a version, see [Manual Download](../../reference/cli-reference#manual-download). ### Environment Variables -Set these environment variables before running `trunk-analytics-cli upload` on unsupported CI systems: +Set these environment variables before running `trunk flakytests upload` on unsupported CI systems: **Config Requirement:** `CUSTOM` must be set to `true` for environment variables to take effect and override the auto-detection of CI. @@ -167,4 +159,4 @@ Once your pipeline has run on a stable branch, navigate to [app.trunk.io](https: - The **Uploads** tab lists every report Trunk has ingested, with status and any warnings (missing file paths, malformed XML, and so on). - The **Tests** tab shows individual test cases once an upload has been processed. -If a recent run isn't showing up, check your CI logs for upload errors and confirm your `TRUNK_API_TOKEN` and `TRUNK_ORG_URL_SLUG` secrets are set on the project running the pipeline and the collection ID is correct. +If a recent run isn't showing up, check your CI logs for upload errors and confirm your `TRUNK_API_KEY` secret and `TRUNK_ORG_URL_SLUG` variable are set on the project running the pipeline, the key has the **Upload test results** permission, and the collection ID is correct. diff --git a/flaky-tests/get-started/fork-pr-uploads.mdx b/flaky-tests/get-started/fork-pr-uploads.mdx index 1942527a..7423c2bb 100644 --- a/flaky-tests/get-started/fork-pr-uploads.mdx +++ b/flaky-tests/get-started/fork-pr-uploads.mdx @@ -1,12 +1,12 @@ --- title: "Uploads from Forked Pull Requests" -description: "Upload test results and apply quarantining on pull requests from forks, which can't read your repository secrets or your Trunk API token." +description: "Upload test results and apply quarantining on pull requests from forks, which can't read your repository secrets or your Trunk API key." og:title: "Uploading test results from fork pull requests to Trunk" --- -CI on a pull request from a fork can't use your Trunk API token. GitHub Actions workflows triggered by `pull_request` events from a fork run with read-only permissions and can't read repository secrets, so `$TRUNK_API_TOKEN` is empty. Trunk lets these runs upload to a [test collection](../test-collections) without a token through an opt-in on the collection. +CI on a pull request from a fork can't use your Trunk API key. GitHub Actions workflows triggered by `pull_request` events from a fork run with read-only permissions and can't read repository secrets, so the secret that holds your API key is empty. Trunk lets these runs upload to a [test collection](../test-collections) without a key through an opt-in on the collection. -This is intended for public repositories that accept outside contributions. For private repositories or forks inside your organization, keep using `$TRUNK_API_TOKEN`. +This is intended for public repositories that accept outside contributions. For private repositories or forks inside your organization, keep using your API key. A forked run can also read quarantined tests, so [quarantining](../quarantining/) works on fork pull requests the same way it does on your own branches. @@ -37,7 +37,7 @@ jobs: - name: Upload Test Results to Trunk.io if: ${{ !cancelled() }} continue-on-error: true - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: "**/junit.xml" org-slug: ${{ vars.TRUNK_ORG_SLUG }} @@ -45,15 +45,20 @@ jobs: allow-forked-pr-uploads: true ``` -This needs `analytics-uploader` v2.1.4 or later, which the `@v2` tag already resolves to, and analytics-cli 0.15.5 or later. The action installs the latest CLI unless you pin an older one with `cli-version`. +The action signs the upload in with the job's own `GITHUB_TOKEN`, which Trunk accepts only for a pull request from a fork. A run on a branch of your own repository still needs `token`. -If you call the CLI directly, pass `--allow-forked-pr-uploads` together with `--test-collection-id`, or set `TRUNK_ALLOW_FORKED_PR_UPLOADS=true` and `TRUNK_TEST_COLLECTION_ID`: +If you run [`trunk flakytests`](./trunk-cli) yourself, pass `--allow-forked-pr-uploads` together with `--test-collection-id`, or set `TRUNK_ALLOW_FORKED_PR_UPLOADS=true` and `TRUNK_TEST_COLLECTION_ID`. Set `GITHUB_TOKEN` on the step, because GitHub doesn't export it to commands: -```sh -./trunk-analytics-cli upload --junit-paths "test_output.xml" \ - --org-url-slug \ - --test-collection-id \ - --allow-forked-pr-uploads +```yaml + - name: Upload Test Results to Trunk.io + if: ${{ !cancelled() }} + run: | + trunk flakytests upload --junit-paths "test_output.xml" \ + --org-url-slug \ + --test-collection-id \ + --allow-forked-pr-uploads + env: + GITHUB_TOKEN: ${{ github.token }} ``` `--allow-forked-pr-uploads` without a collection ID is an error, because the collection's own setting is what authorizes the upload. diff --git a/flaky-tests/get-started/index.mdx b/flaky-tests/get-started/index.mdx index 4ae8be4b..6c70c3b7 100644 --- a/flaky-tests/get-started/index.mdx +++ b/flaky-tests/get-started/index.mdx @@ -9,6 +9,7 @@ Trunk Flaky Tests detects flaky tests by analyzing test results from your CI run * Account at [app.trunk.io](https://app.trunk.io) * Ability to modify repository CI configuration and add secrets +* A Trunk API key with the **Upload test results** permission, or access to create one under **Settings** → **Developer** → **API Keys** * Tests running in CI on both PRs and stable branches (e.g., main, master, or develop) ### Step 1: Create a test collection @@ -32,10 +33,11 @@ If not, configure your test frameworks to output JUnit XML: ### Step 3: Configure CI uploads -Add test result uploads to all CI jobs that run tests. Every upload step passes the **Collection ID** from Step 1, as `--test-collection-id` or the `TRUNK_TEST_COLLECTION_ID` environment variable. +Add test result uploads to all CI jobs that run tests. Uploads go through the [`trunk` CLI](./trunk-cli): install it, store a Trunk API key with the **Upload test results** permission with `trunk auth api-key set`, and run `trunk flakytests upload` after your tests. On GitHub Actions, the [`trunk-io/analytics-uploader@v3`](./ci-providers/github-actions) action does all three. Every upload step passes the **Collection ID** from Step 1, as `--test-collection-id` or the `TRUNK_TEST_COLLECTION_ID` environment variable. -1. See [**CI Providers**](./ci-providers/) for integration instructions -2. Configure uploads in jobs that run on: +1. Create an API key with the **Upload test results** permission. See [Create an API key](./trunk-cli#create-an-api-key). +2. See [**CI Providers**](./ci-providers/) for integration instructions +3. Configure uploads in jobs that run on: * Pull request branches * Stable branches (`main`, `master`, `develop`, etc.) * Merge queue branches (if applicable) diff --git a/flaky-tests/get-started/trunk-cli.mdx b/flaky-tests/get-started/trunk-cli.mdx new file mode 100644 index 00000000..1b002280 --- /dev/null +++ b/flaky-tests/get-started/trunk-cli.mdx @@ -0,0 +1,174 @@ +--- +title: "Trunk CLI" +description: "Install the trunk CLI, store a Trunk API key, and upload test results to Trunk Flaky Tests with trunk flakytests." +og:title: "Uploading test results with the trunk CLI" +--- +The `trunk` CLI uploads your test results to Trunk Flaky Tests. You install it once, store a Trunk API key with it, and run `trunk flakytests` (or its alias, `trunk ft`) after your tests. The CLI downloads the [Trunk Analytics CLI](/flaky-tests/reference/cli-reference) (`trunk-analytics-cli`) on first use, runs it with your arguments, and passes it your credential. + +To upload from GitHub Actions, use the [`trunk-io/analytics-uploader` action](/flaky-tests/get-started/ci-providers/github-actions), which installs and runs the `trunk` CLI for you. + +## Install the trunk CLI + + + +```bash +curl -fsSL https://install.trunk.io | sh +``` + +The installer supports: + +- Linux on x64 and arm64. One static build runs on any distribution, including Alpine and minimal containers. +- macOS 14 (Sonoma) or later, on Apple silicon and Intel Macs. + +It installs `trunk` to `/usr/local/bin` when that directory is writable, and to `~/.local/bin` otherwise. It never runs `sudo`. If the install directory isn't on your `PATH`, the installer prints the line to add to your shell profile. Pass `--install-dir ` to install somewhere else. + + +In PowerShell (Windows PowerShell 5.1 or PowerShell 7 and later): + +```powershell +irm https://install.trunk.io/install.ps1 | iex +``` + +The installer puts `trunk.exe` in `%LOCALAPPDATA%\Programs\trunk\bin` and adds that directory to your user `PATH`. Open a new terminal before you run `trunk`. Windows on Arm gets the x64 build, which runs under emulation on Windows 11. + +On Windows, the CLI supports `trunk auth`, `trunk flakytests`, and `trunk update`. The Trunk Analytics CLI it runs there is an experimental build. The binary isn't code-signed, so a browser download can show a SmartScreen prompt; the installer doesn't trigger it. + + + +Check the install: + +```bash +trunk --version +``` + +It prints `trunk` and a version number, such as `trunk 1.2.3`. + + +If you already have the older `trunk` CLI for Code Quality on your `PATH`, the installer warns you and installs the new CLI anyway. Make sure the new CLI's directory comes first on your `PATH`, or remove the old one. The older CLI prints a bare version number for `trunk --version`. + + +## Create an API key + +`trunk flakytests` uploads with a Trunk API key that has the **Upload test results** permission. + +1. In the [Trunk app](https://app.trunk.io), navigate to **Settings** → **Developer** → **API Keys** and click the **Create Key** button. +2. Name the key after what will use it, such as `flaky-tests-ci`. +3. Select the **Upload test results** permission. +4. Copy the key. It starts with `trunk_v2_` and is shown only once. + +See [API keys](/api/authentication#api-keys) for how keys and permissions work. + +## Store the API key + +Run `trunk auth api-key set` and paste the key at the prompt: + +```bash +trunk auth api-key set +``` + +The prompt doesn't echo what you type. When the `TRUNK_ORG_API_KEY` environment variable is set, the command reads the key from it instead of prompting. Use it in CI, where there's no terminal to prompt on: + +```bash +TRUNK_ORG_API_KEY="$TRUNK_API_KEY" trunk auth api-key set +``` + +The command checks the key with Trunk before it stores anything. If Trunk refuses the key, the command exits with an error and stores nothing. It doesn't check the key's permissions: uploads with a key that lacks **Upload test results** fail with `403`. The command never takes the key as an argument, so the key stays out of your shell history and process listings. + +The key is stored in `~/.config/trunk-cli/credentials.json` (`%APPDATA%\trunk-cli\credentials.json` on Windows), readable only by you. To remove it, run `trunk auth api-key clear`. + + +`trunk auth login` signs you in as yourself, for commands such as `trunk mergequeue`. It doesn't authorize uploads: `trunk flakytests` uses only the stored API key. + + +## Upload test results + +Run `trunk flakytests upload` after your tests, from the root of your repository: + +```bash +trunk flakytests upload --junit-paths "**/junit.xml" \ + --org-url-slug \ + --test-collection-id +``` + +- `--org-url-slug` is your organization slug, from **Settings** → **Organization** → **General**. +- `--test-collection-id` is the ID of the [test collection](/flaky-tests/test-collections) to upload to, from the collection's page header. It's required. + +To run your tests and upload their results in one step, wrap your test command with `trunk flakytests test`. Put the test command after `--`: + +```bash +trunk flakytests test --junit-paths "**/junit.xml" \ + --org-url-slug \ + --test-collection-id \ + -- npm test +``` + +When every failure is a [quarantined](/flaky-tests/quarantining/) test, `trunk flakytests test` exits with `0`, so known flaky tests don't fail your build. + +`trunk flakytests` accepts every Trunk Analytics CLI command and option, such as `--bazel-bep-path`, `--xcresult-path`, `--variant`, and `validate`. See the [CLI reference](/flaky-tests/reference/cli-reference) for the full list, or run `trunk flakytests upload --help`. + +## Use the trunk CLI in CI + +Store the API key as a secret in your CI provider, such as `TRUNK_API_KEY`. Then add these steps to each job that runs tests: + +```bash +curl -fsSL https://install.trunk.io | sh +TRUNK_ORG_API_KEY="$TRUNK_API_KEY" trunk auth api-key set + + + +trunk flakytests upload --junit-paths "**/junit.xml" \ + --org-url-slug \ + --test-collection-id +``` + +If the installer reports that its directory isn't on your `PATH`, add the directory to `PATH` for the later steps, or pass `--install-dir` with a directory that is. + +Upload from jobs on pull requests and on your stable branches, such as `main`. For provider-specific setup, see [CI Providers](/flaky-tests/get-started/ci-providers/). + +You can skip `trunk auth api-key set` and set `TRUNK_API_TOKEN` to the API key on the `trunk flakytests` step instead. When `TRUNK_API_TOKEN` or `--token` is set, `trunk flakytests` passes it to the Trunk Analytics CLI unchanged. + + +On a self-hosted runner that keeps its home directory between jobs, the stored key stays in `~/.config/trunk-cli/credentials.json` for later jobs. Run `trunk auth api-key clear` at the end of the job, or set `TRUNK_API_TOKEN` instead of storing the key. + + +## Pin versions + +By default, the installer installs the latest `trunk` CLI, and `trunk flakytests` runs the latest Trunk Analytics CLI. To get the same versions on every run, pin them: + +- **trunk CLI.** Pass `--version` to the installer. A pinned install doesn't update itself. + + ```bash + curl -fsSL https://install.trunk.io | sh -s -- --version + ``` + + On Windows, run `iex "& {$(irm https://install.trunk.io/install.ps1)} -Version "`. +- **Trunk Analytics CLI.** Set `TRUNK_ANALYTICS_CLI_VERSION` to a version, such as `1.0.0`. The `trunk` CLI downloads each version once and caches it. + +Trunk Analytics CLI 1.0.0 and later accept only an API key. If you still upload with the legacy organization token, pin `TRUNK_ANALYTICS_CLI_VERSION` to a 0.17.x release and pass the token with `--token` or `TRUNK_API_TOKEN`. The `trunk` CLI passes a stored API key only to 1.0.0 and later. + +## Updates + +The `trunk` CLI updates itself. Once a day it checks for a new version in the background and switches to it on the next run. It doesn't check when: + +- `CI` is set to `true`. Most CI providers, including GitHub Actions, set it for you. +- `TRUNK_NO_AUTO_UPDATE` is set to any value. +- The install is pinned to a version. + +To update now, run `trunk update`. It works even when automatic updates are off, and it removes a version pin. + +## Telemetry + +The `trunk` CLI sends usage telemetry, such as the command name and its exit code, while you're signed in with `trunk auth login` or have an API key stored. A fork pull request upload with no API key sends none. To turn telemetry off, set `TRUNK_TELEMETRY=0` or `DO_NOT_TRACK=1`. `trunk auth status` shows whether telemetry is on. + +## Environment variables + +| Variable | Use | +| --- | --- | +| `TRUNK_ORG_API_KEY` | The API key for `trunk auth api-key set` to store, instead of prompting for it. | +| `TRUNK_API_TOKEN` | A credential to pass to the Trunk Analytics CLI as is, instead of the stored API key. | +| `TRUNK_ORG_URL_SLUG` | Your organization slug, instead of `--org-url-slug`. | +| `TRUNK_TEST_COLLECTION_ID` | The test collection ID, instead of `--test-collection-id`. | +| `TRUNK_ANALYTICS_CLI_VERSION` | The Trunk Analytics CLI version to run. | +| `TRUNK_NO_AUTO_UPDATE` | Any value turns off automatic updates. | +| `TRUNK_TELEMETRY`, `DO_NOT_TRACK` | `TRUNK_TELEMETRY=0` or `DO_NOT_TRACK=1` turns off usage telemetry. | +| `TRUNK_CREDENTIALS_FILE` | The path of the file the stored API key is kept in. | diff --git a/flaky-tests/quarantining/index.mdx b/flaky-tests/quarantining/index.mdx index 8bc2aa84..e980fe2f 100644 --- a/flaky-tests/quarantining/index.mdx +++ b/flaky-tests/quarantining/index.mdx @@ -146,12 +146,12 @@ Here's an example file. - name: Upload test results if: always() - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: org-slug: my-trunk-org-slug test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} ``` If you want to run the test command and upload in a single step, the test command must be **run via the Analytics Uploader** through the `run: ` parameter. @@ -171,11 +171,11 @@ jobs: uses: actions/checkout@v3 - name: Run tests and upload results - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: run: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} org-slug: my-trunk-org-slug test-collection-id: ``` @@ -228,7 +228,7 @@ With `--dry-run`, the CLI still checks your failed tests against Trunk's quarant Keep in mind: -* An organization token and network access are still required; the quarantine check queries Trunk's backend to determine which tests are quarantined. +* An API key with the **Upload test results** permission and network access are still required; the quarantine check queries Trunk's backend to determine which tests are quarantined. * Because nothing is uploaded, the run won't appear in your dashboard or contribute to [flaky test detection](../detection/). Quarantining decisions are based on results from your other, uploading CI jobs. * The local bundle written to `./bundle_upload` can also be useful for inspecting exactly what the CLI would have uploaded. diff --git a/flaky-tests/recipes/explain-failed-pr-tests.mdx b/flaky-tests/recipes/explain-failed-pr-tests.mdx index 12a10047..9ca3657c 100644 --- a/flaky-tests/recipes/explain-failed-pr-tests.mdx +++ b/flaky-tests/recipes/explain-failed-pr-tests.mdx @@ -81,7 +81,7 @@ A quarantined test with a failure rate near 100% isn't flaky: it fails every tim ## 5. Post the comment -This script does steps 2 to 5 and creates or updates one comment on the pull request. It needs Node.js 18 or later and an [API key](/api/authentication#api-keys). Reading tests needs no permissions, so leave them all off. +This script does steps 2 to 5 and creates or updates one comment on the pull request. It needs Node.js 18 or later and an [API key](/api/authentication#api-keys). Reading tests needs no permissions, so the key the uploader uses, which has **Upload test results**, works here too. ```javascript explain-failed-tests.mjs expandable import { readFileSync } from "node:fs"; @@ -204,12 +204,12 @@ jobs: id: trunk if: ${{ !cancelled() }} continue-on-error: true - uses: trunk-io/analytics-uploader@v2 + uses: trunk-io/analytics-uploader@v3 with: junit-paths: "**/junit.xml" org-slug: test-collection-id: - token: ${{ secrets.TRUNK_API_TOKEN }} + token: ${{ secrets.TRUNK_API_KEY }} - name: Explain failed tests if: ${{ !cancelled() && github.event_name == 'pull_request' && steps.trunk.outputs.summary-output-file != '' }} @@ -225,7 +225,7 @@ jobs: Each job gets its own comment, so a pull request with several test jobs gets one comment per job that had failures. A rerun of the same job updates its comment rather than adding another. -`TRUNK_API_TOKEN` is the organization token the uploader uses. `TRUNK_API_KEY` is an [API key](/api/authentication#api-keys) for the API. They are different credentials. +Both steps use the same `TRUNK_API_KEY`, an [API key](/api/authentication#api-keys) with the **Upload test results** permission. The uploader needs that permission; reading tests needs none. ## Related diff --git a/flaky-tests/reference/cli-reference.mdx b/flaky-tests/reference/cli-reference.mdx index 805dd59a..3ee39a7f 100644 --- a/flaky-tests/reference/cli-reference.mdx +++ b/flaky-tests/reference/cli-reference.mdx @@ -3,7 +3,9 @@ title: "CLI Reference" description: "CLI tool for uploading test results to Trunk from CI, enabling flaky test detection and quarantining." og:title: "Trunk Flaky Tests CLI reference" --- -Trunk detects and tracks flaky tests in your repos by receiving uploads from your test runs in CI, uploaded from the Trunk Analytics CLI. These uploads happen in the CI jobs used to run tests in your nightly CI, post-commit jobs, and PR checks. +Trunk detects and tracks flaky tests in your repos by receiving uploads from your test runs in CI, uploaded by the Trunk Analytics CLI (`trunk-analytics-cli`). These uploads happen in the CI jobs used to run tests in your nightly CI, post-commit jobs, and PR checks. + +You run the Trunk Analytics CLI through the [`trunk` CLI](/flaky-tests/get-started/trunk-cli): `trunk flakytests` (or `trunk ft`) downloads it, runs it with your arguments, and passes it the API key you stored with `trunk auth api-key set`. `trunk flakytests ` takes the same commands and options as `trunk-analytics-cli `. ## Guides @@ -20,11 +22,28 @@ If you're setting up Trunk Flaky Tests for the first time, you can follow the gu /> -The CLI should be **downloaded as part of your test workflow** in your CI system. Download the binary for your platform from `https://trunk.io/releases/analytics-cli/prod`, as shown in [Manual Download](#manual-download). +## Install + +Install the `trunk` CLI and store an API key with the **Upload test results** permission: + +```bash +curl -fsSL https://install.trunk.io | sh +TRUNK_ORG_API_KEY="$TRUNK_API_KEY" trunk auth api-key set +``` + +See [Trunk CLI](/flaky-tests/get-started/trunk-cli) for Windows, pinning versions, and running in CI. + +## Running trunk-analytics-cli directly + +You can download the Trunk Analytics CLI and run it yourself, without the `trunk` CLI. Pass it an API key with the **Upload test results** permission, with `--token` or the `TRUNK_API_TOKEN` environment variable. In the examples on this page, replace `trunk flakytests` with `./trunk-analytics-cli` and add `--token "$TRUNK_API_KEY"`. + + +The Trunk Analytics CLI 1.0.0 and later refuse the legacy organization token. To keep using it, pin a 0.17.x release by setting `VERSION` below. + -## Manual Download +### Manual Download -Releases are served from `https://trunk.io/releases/analytics-cli/prod`. `channel.json` there names the latest version (`{"latest": "x.y.z"}`), and each version's files live under `/`. We provide executables for Linux and OS X. It’s a single file inside a tar and upon downloading the tar you will find a single binary - `trunk-analytics-cli` to use. To pin a version, set `VERSION` to it instead of reading `channel.json`. +Releases are served from `https://trunk.io/releases/analytics-cli/prod`. `channel-1.json` there names the latest 1.x version (`{"latest": "x.y.z"}`), and each version's files live under `/`. We provide executables for Linux and macOS. It’s a single file inside a tar and upon downloading the tar you will find a single binary - `trunk-analytics-cli` to use. To pin a version, set `VERSION` to it instead of reading `channel-1.json`. Releases are also published on [GitHub](https://github.com/trunk-io/analytics-cli/releases), but GitHub rate-limits downloads, so it is not a reliable source for CI. Download from `trunk.io` instead. @@ -33,8 +52,9 @@ Releases are also published on [GitHub](https://github.com/trunk-io/analytics-cl ```bash Linux (x64) SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ +VERSION=$(curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \ + https://trunk.io/releases/analytics-cli/prod/channel-1.json | cut -d'"' -f4) +curl -fL --connect-timeout 10 --max-time 60 --retry 3 \ "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ | tar -xz @@ -42,8 +62,9 @@ chmod +x trunk-analytics-cli ``` ```bash Linux (arm64) SKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ +VERSION=$(curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \ + https://trunk.io/releases/analytics-cli/prod/channel-1.json | cut -d'"' -f4) +curl -fL --connect-timeout 10 --max-time 60 --retry 3 \ "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ | tar -xz @@ -51,8 +72,9 @@ chmod +x trunk-analytics-cli ``` ```bash macOS (arm64) SKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ +VERSION=$(curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \ + https://trunk.io/releases/analytics-cli/prod/channel-1.json | cut -d'"' -f4) +curl -fL --connect-timeout 10 --max-time 60 --retry 3 \ "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ | tar -xz @@ -60,8 +82,9 @@ chmod +x trunk-analytics-cli ``` ```bash macOS (x64) SKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz" -VERSION=$(curl -fsSL https://trunk.io/releases/analytics-cli/prod/channel.json | cut -d'"' -f4) -curl -fL --retry 3 \ +VERSION=$(curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \ + https://trunk.io/releases/analytics-cli/prod/channel-1.json | cut -d'"' -f4) +curl -fL --connect-timeout 10 --max-time 60 --retry 3 \ "https://trunk.io/releases/analytics-cli/prod/${VERSION}/${SKU}" \ | tar -xz @@ -69,30 +92,22 @@ chmod +x trunk-analytics-cli ``` -## Organization Slug and Token +## Organization Slug, API Key, and Test Collection -The CLI requires your Trunk organization slug, token, and test collection ID, passed through `--org-url-slug`, `--token`, and `--test-collection-id`, to upload results to the correct organization and collection. They can alternatively be set via environment variables, `TRUNK_ORG_URL_SLUG`, `TRUNK_API_TOKEN`, and `TRUNK_TEST_COLLECTION_ID`, respectively. +The CLI requires your Trunk organization slug and test collection ID, passed through `--org-url-slug` and `--test-collection-id`, to upload results to the correct organization and collection. They can alternatively be set via environment variables, `TRUNK_ORG_URL_SLUG` and `TRUNK_TEST_COLLECTION_ID`. -You can find your organization slug under **Settings** → **Organization** → **General**. Your token is under **Settings** → **Developer** → **API Keys**, in the **Organization API token (v1)** section. The collection ID is on the collection's page; see [Test Collections](#test-collections). +You can find your organization slug under **Settings** → **Organization** → **General**. The collection ID is on the collection's page; see [Test Collections](#test-collections). + +Uploads also need an API key with the **Upload test results** permission, created under **Settings** → **Developer** → **API Keys**. `trunk flakytests` uses the key stored with `trunk auth api-key set`. When you run the Trunk Analytics CLI directly, pass the key with `--token` or `TRUNK_API_TOKEN`. Your organization slug is the tail of your dashboard URL (`app.trunk.io/`). It defaults to your organization name with spaces replaced by hyphens. To change it, contact [help@trunk.io](mailto:help@trunk.io). - - The General page, with the organization slug in the URL field The General page, with the organization slug in the URL field - - - -The Organization API token (v1) section of the API Keys page -The Organization API token (v1) section of the API Keys page - - - ## Uploading Test Results @@ -100,47 +115,43 @@ Your organization slug is the tail of your dashboard URL (`app.trunk.io/ -Trunk accepts uploads from three main report sources, [JUnit XML](https://github.com/testmoapp/junitxml), [Bazel Event Protocol JSONs](https://bazel.build/remote/bep#consuming-bep-text-json), and Swift (both XCode XCResult paths and the XML written by `swift test --xunit-output`). You can upload each of these test report sources using the `./trunk-analytics-cli upload` command like this: +Trunk accepts uploads from three main report sources, [JUnit XML](https://github.com/testmoapp/junitxml), [Bazel Event Protocol JSONs](https://bazel.build/remote/bep#consuming-bep-text-json), and Swift (both XCode XCResult paths and the XML written by `swift test --xunit-output`). You can upload each of these test report sources using the `trunk flakytests upload` command like this: Trunk can accept JUnit XMLs through the `--junit-paths` argument: ``` -./trunk-analytics-cli upload --junit-paths "test_output.xml" \ +trunk flakytests upload --junit-paths "test_output.xml" \ --org-url-slug \ - --test-collection-id \ - --token $TRUNK_API_TOKEN + --test-collection-id ``` Trunk can accept Bazel through the `--bazel-bep-path` argument: ``` -./trunk-analytics-cli upload --bazel-bep-path \ +trunk flakytests upload --bazel-bep-path \ --org-url-slug \ - --test-collection-id \ - --token $TRUNK_API_TOKEN + --test-collection-id ``` Trunk can accept XCode through the `--xcresult-path` argument: ``` -./trunk-analytics-cli upload --xcresult-path \ +trunk flakytests upload --xcresult-path \ --org-url-slug \ - --test-collection-id \ - --token $TRUNK_API_TOKEN + --test-collection-id ``` Trunk can accept the XML written by `swift test --xunit-output` through the `--swift-test-xunit-paths` argument: ``` -./trunk-analytics-cli upload --swift-test-xunit-paths "junit-swift-testing.xml,junit.xml" \ +trunk flakytests upload --swift-test-xunit-paths "junit-swift-testing.xml,junit.xml" \ --org-url-slug \ - --test-collection-id \ - --token $TRUNK_API_TOKEN + --test-collection-id ``` This XML carries no file path for any test case, so Trunk resolves each test to the file it is declared in by reading your checkout. See [Swift Testing](/flaky-tests/get-started/frameworks/swift-testing) for what a single `swift test` run writes and what the resolution requires. @@ -156,10 +167,9 @@ For example, a test for a mobile app might be flaky on iOS but stable on Android You can specify a variant during upload using the `--variant` option: ```sh Upload an iOS variant -./trunk-analytics-cli upload --junit-paths "test_output.xml" \ +trunk flakytests upload --junit-paths "test_output.xml" \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ --variant ios ``` @@ -175,10 +185,9 @@ Variant names are displayed in brackets next to test names in your dashboard: [Test collections](/flaky-tests/test-collections) group tests so they can be configured and reviewed together, with their own flake detection and quarantining. Every upload names the collection it belongs to, by passing its ID with `--test-collection-id`: ```sh Upload to a test collection -./trunk-analytics-cli upload --junit-paths "test_output.xml" \ +trunk flakytests upload --junit-paths "test_output.xml" \ --org-url-slug \ - --test-collection-id \ - --token $TRUNK_API_TOKEN + --test-collection-id ``` The collection ID is eight alphanumeric characters, and you copy it from the collection in the Trunk app. `--org-url-slug` is still required — the collection ID is an addition to it, not a replacement. @@ -204,44 +213,40 @@ This is especially useful for [Quarantining](../quarantining/), where the Trunk Trunk can accept JUnit XMLs through the `--junit-paths` argument: ``` -./trunk-analytics-cli test --junit-paths "test_output.xml" \ +trunk flakytests test --junit-paths "test_output.xml" \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ - + -- ``` Trunk can accept Bazel through the `--bazel-bep-path` argument: ``` -./trunk-analytics-cli test --bazel-bep-path \ +trunk flakytests test --bazel-bep-path \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ - + -- ``` Trunk can accept XCode through the `--xcresult-path` argument: ``` -./trunk-analytics-cli test --xcresult-path \ +trunk flakytests test --xcresult-path \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ - + -- ``` Trunk can accept the XML written by `swift test --xunit-output` through the `--swift-test-xunit-paths` argument: ``` -./trunk-analytics-cli test --swift-test-xunit-paths "junit-swift-testing.xml,junit.xml" \ +trunk flakytests test --swift-test-xunit-paths "junit-swift-testing.xml,junit.xml" \ --org-url-slug \ --test-collection-id \ - --token $TRUNK_API_TOKEN \ - + -- ``` @@ -267,7 +272,7 @@ You can validate the test reports produced by your test frameworks before you se You can run the validate command like this: ``` -./trunk-analytics-cli validate --junit-paths "test_output.xml" +trunk flakytests validate --junit-paths "test_output.xml" ``` The `validate` command will output any problems with your reports so you can address them before setting up Trunk in CI. @@ -291,13 +296,13 @@ The CLI is preconfigured to work with a set [ci-providers](/flaky-tests/get-star ## Full command reference -The `trunk` command-line tool can upload and analyze test results. The `trunk-analytics-cli` command accepts the following subcommands: +`trunk flakytests` (alias `trunk ft`) and `trunk-analytics-cli` accept the following subcommands: -| Command | Description | -| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `trunk-analytics-cli upload` | Upload data to Trunk Flaky Tests. | -| `trunk-analytics-cli validate` | Validates if the provided JUnit XML files and prints any errors. | -| `trunk-analytics-cli test ` | Runs tests using the provided command, uploads results, checks whether the failures are [quarantined](../quarantining/#updates-in-ci) tests, and correct the exit code based on that. | +| Command | Description | +| --- | --- | +| `trunk flakytests upload` | Upload data to Trunk Flaky Tests. | +| `trunk flakytests validate` | Validates if the provided JUnit XML files and prints any errors. | +| `trunk flakytests test -- ` | Runs tests using the provided command, uploads results, checks whether the failures are [quarantined](../quarantining/#updates-in-ci) tests, and correct the exit code based on that. | The `upload` and `test` commands accept the following options: @@ -309,7 +314,7 @@ The `upload` and `test` commands accept the following options: | `--swift-test-xunit-paths ` | Comma-separated list of glob patterns to files written by `swift test --xunit-output`, resolved against the repository root like `--junit-paths`. This XML carries no file path, so each test is attributed to the file it is declared in, resolved from your checkout. Can also be set with the `TRUNK_SWIFT_TEST_XUNIT_PATHS` environment variable. See [Swift Testing](/flaky-tests/get-started/frameworks/swift-testing). | | `--use-experimental-xcresult-test-locations` | **Beta.** Take each `.xcresult` test's file from where it is declared rather than from the failure that surfaced it, which also gives passing tests a file. macOS only. See [XCTest](/flaky-tests/get-started/frameworks/xctest#attributing-tests-to-their-declaring-file). | | `--org-url-slug ` | Trunk organization slug, from **Settings** → **Organization** → **General**. | -| `--token ` | Trunk organization API token (not an API key or a repo token), from the **Organization API token (v1)** section of **Settings** → **Developer** → **API Keys**. Defaults to the `TRUNK_API_TOKEN` variable. | +| `--token ` | An API key with the **Upload test results** permission, from **Settings** → **Developer** → **API Keys**. Defaults to the `TRUNK_API_TOKEN` variable. `trunk flakytests` sets it for you from the key stored with `trunk auth api-key set`, so pass it only when you run the Trunk Analytics CLI directly. The Trunk Analytics CLI 1.0.0 and later refuse the legacy organization token. | | `-h, --help` | Additional detailed description of the `upload` command. | | `--repo-root` | Path to the repository root. Defaults to the current directory. | | `--repo-url ` | Value to override URL of repository. **Optional**. | @@ -321,7 +326,8 @@ The `upload` and `test` commands accept the following options: | `--allow-empty-test-results` | Don't fail commands if test results are empty or missing. Use it when you sometimes skip all tests for certain CI jobs. Defaults to `true`. | | `--variant ` | Upload tests to a specific variant group. **Optional**. | | `--test-collection-id ` | Upload to a [test collection](/flaky-tests/test-collections), in addition to (not instead of) `--org-url-slug`. Can also be set with the `TRUNK_TEST_COLLECTION_ID` environment variable. **Required**. | -| `--allow-forked-pr-uploads` | Upload from a forked pull request, whose CI can't read your API token. Requires `--test-collection-id`, and the collection must have forked pull request uploads turned on. See [Uploads from Forked Pull Requests](/flaky-tests/get-started/fork-pr-uploads). Can also be set with the `TRUNK_ALLOW_FORKED_PR_UPLOADS=true` environment variable. **Optional**. | +| `--allow-forked-pr-uploads` | Upload from a forked pull request, whose CI can't read your API key. Requires `--test-collection-id`, and the collection must have forked pull request uploads turned on. Works only in a GitHub Actions run of a pull request from a fork, with the job's `GITHUB_TOKEN` in the environment. See [Uploads from Forked Pull Requests](/flaky-tests/get-started/fork-pr-uploads). Can also be set with the `TRUNK_ALLOW_FORKED_PR_UPLOADS=true` environment variable. **Optional**. | +| `--disable-quarantining` | Report every test failure in the exit code, even for quarantined tests. Can also be set with the `TRUNK_DISABLE_QUARANTINING=true` environment variable. **Optional**. | | `--test-process-exit-code` `` | Specify the exit code of the test previously run. This is used by the upload command to identify errors that happen outside of the context of the test execution (such as build errors). | | `--dry-run` | Write the test results bundle to a local `./bundle_upload` directory instead of uploading it to Trunk. [Quarantining](../quarantining/#quarantining-without-uploading) still runs and still determines the exit code. Can also be set with the `TRUNK_DRY_RUN=true` environment variable. **Optional**. | | `--summary-output-file ` | Write a JSON summary of the run to this file: the test counts, and each failed test with its Trunk test ID, whether it was quarantined, and its link. `trunk-analytics-cli summary-output-schema` prints the summary's JSON Schema. See [Explain a Failed Pull Request](/flaky-tests/recipes/explain-failed-pr-tests). Can also be set with the `TRUNK_SUMMARY_OUTPUT_FILE` environment variable. **Optional**. | @@ -329,7 +335,7 @@ The `upload` and `test` commands accept the following options: **Memory Overhead** -Running tests via `trunk-analytics-cli test` adds negligible memory overhead. +Running tests via `trunk flakytests test` adds negligible memory overhead. This subcommand is a thin wrapper around your existing test command and doesn't modify or parallelize test execution.