> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usetusk.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosted Runners

> Run Tusk-generated tests on your own GitHub Actions runner

<Warning>
  **We recommend using Tusk's managed test environments** for most teams. The managed flow is faster to set up, requires no maintenance, and works with GitHub and GitLab. If you're setting up a new repository, use the **Analyze Repository** flow on the Unit Tests page instead.

  Self-hosted runners are available for teams with specific infrastructure requirements. Contact [support@usetusk.ai](mailto:support@usetusk.ai) to enable this option.
</Warning>

## When to Use Self-Hosted Runners

Self-hosted runners may be appropriate if you:

* Have strict compliance requirements for code execution
* Need access to private network resources during tests
* Already have significant GitHub Actions infrastructure
* Require specific hardware (GPUs, high memory)

## Requirements

Before you begin, make sure that you meet these requirements:

* Use **GitHub** for version control (GitLab not currently supported for self-hosted runners)
* Have GitHub **admin access** to manage secrets or variables for your repo
* Already have a **CI workflow** for running unit tests (setup, test script available)
* Have contacted Tusk support to enable self-hosted runners

## Overview

To surface meaningful and validated tests, Tusk needs to execute the tests it generates against your commit with your specific project's dependencies.

Most engineering teams already have existing CI pipelines for running their unit test suites, most commonly with GitHub Actions.

The self-hosted flow allows you to provision a GitHub Actions runner as an ephemeral sandbox, enabling you to leverage your existing workflow setup and giving you greater control over the configuration.

<Info>
  Using Tusk via self-hosted runners will accrue GitHub Actions minutes for your organization. GitHub provides a generous amount of [free minutes](https://docs.github.com/en/billing/managing-billing-for-your-products/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes) but a single Tusk test generation run can cost \$0.16-0.32 depending on which runner you use. More on GitHub Actions billing [here](https://docs.github.com/en/billing/managing-billing-for-your-products/managing-billing-for-github-actions/about-billing-for-github-actions).
</Info>

## Set-Up Instructions

<Steps>
  <Step title="Start the environment set-up">
    In the [Unit Tests](https://app.usetusk.ai/app/unit-tests/repos) page, click **Start setup** under the synced repo that you would like to set up a test environment for.

    <img alt="Setup test environment button in Repos page" classname="block" src="https://mintcdn.com/tusk/ZSRG9RyWtVo44p2P/images/repos-page-self-serve-1.png?fit=max&auto=format&n=ZSRG9RyWtVo44p2P&q=85&s=99f1ea4c979d05c4a00d5317dd491f70" width="1176" height="648" data-path="images/repos-page-self-serve-1.png" />

    You'll be directed to the wizard for setting up a test environment. Click **Begin setup**.

    <img alt="Tusk setup wizard beginning" className="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-1.jpg?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=c9c112c43a82ff24dcc1d81a2ba77eb5" width="2539" height="1542" data-path="images/tusk-self-serve-wizard-1.jpg" />
  </Step>

  <Step title="Configure your test environment">
    Start by selecting whether the repo you're setting a test environment for is a monorepo or not. If it is a monorepo, include the application directory in the field that appears.

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-2.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=169bff07194399bf475c237e5fc560c0" width="2582" height="1124" data-path="images/tusk-self-serve-wizard-2.png" />

    Then, choose your primary programming language and unit testing framework.

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-3.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=2101a28a84385393bc9db88a6bb49eb9" width="2326" height="468" data-path="images/tusk-self-serve-wizard-3.png" />

    Next, provide the file paths of the workflows for running your unit test suite and linting/formatting checks. Tusk uses this to generate an accurate workflow file for running its tests.

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-4.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=27a0d71cea7480510f996b90fa04e98c" width="2226" height="676" data-path="images/tusk-self-serve-wizard-4.png" />
  </Step>

  <Step title="Create the Tusk GitHub workflow">
    Pick between using the Tusk template for the GitHub Actions workflow file (Option 1) or creating the workflow file manually (Option 2).

    We recommend going with Option 1 and clicking **Create PR with template** to use Tusk's tailored workflow file.

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-5.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=19842b9a09bb53a689e974920bf4972a" width="2232" height="824" data-path="images/tusk-self-serve-wizard-5.png" />
  </Step>

  <Step title="Modify the Tusk GitHub workflow file">
    If you chose Option 1, click the URL to view the PR for the Tusk GitHub workflow. The workflow file will be tailored to your repo according to your configurations in the earlier steps.

    **Note:** You may need to modify the workflow file to customize it to your project (e.g., setup steps, RegEx for matching test files). Refer to the comments in the workflow file itself as a guide for modifying the file. More details in [this FAQ](https://docs.usetusk.ai/automated-tests/self-hosted#what-modifications-do-i-need-to-make-to-the-tusk-github-workflow-template).

    <img alt="Merging the Tusk GitHub workflow PR" classname="block" src="https://mintcdn.com/tusk/ZSRG9RyWtVo44p2P/images/tusk-self-serve-4.png?fit=max&auto=format&n=ZSRG9RyWtVo44p2P&q=85&s=15bbda9847f964e67c5180e9727a1eb6" width="3450" height="1530" data-path="images/tusk-self-serve-4.png" />
  </Step>

  <Step title="Create Tusk API key">
    In the Tusk set-up wizard, create an API key under the "Confirm Tusk API Key" section. Make sure to copy the API key on first creation and **add it to your repo's secrets**.

    <img alt="Create and merge Tusk GitHub workflow" classname="block" src="https://mintcdn.com/tusk/ZSRG9RyWtVo44p2P/images/tusk-self-serve-5.png?fit=max&auto=format&n=ZSRG9RyWtVo44p2P&q=85&s=6e572417fa08ab21181444b75389a538" width="2388" height="1186" data-path="images/tusk-self-serve-5.png" />
  </Step>

  <Step title="Merge the Tusk GitHub workflow PR">
    Once you've reviewed and approved the Tusk GitHub workflow PR, merge the PR into your default branch.

    <img alt="Merging the Tusk GitHub workflow PR" classname="block" src="https://mintcdn.com/tusk/ZSRG9RyWtVo44p2P/images/tusk-self-serve-6.png?fit=max&auto=format&n=ZSRG9RyWtVo44p2P&q=85&s=fcc7aa79803e686f7f997d8a2553adc4" width="1868" height="518" data-path="images/tusk-self-serve-6.png" />
  </Step>

  <Step title="Select the workflow file">
    In the Tusk set-up wizard, click **Refetch** under the "Select workflow" step. Then, select the Tusk GitHub workflow file you just merged. Click **Continue**.

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-6.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=60a5fc178fa3e5b6a66431eb5f87bca4" width="2236" height="634" data-path="images/tusk-self-serve-wizard-6.png" />
  </Step>

  <Step title="Verify the Tusk GitHub workflow">
    Choose the branch to test the Tusk GitHub workflow on and then paste in file paths of existing test files in the repo. We recommend including at least 2 test files (use comma-separated values).

    <img alt="Naming your test environment" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-7.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=0f7570801d132e0d08c0a17f974488af" width="2576" height="1534" data-path="images/tusk-self-serve-wizard-7.png" />

    Click **Verify workflow** to run the test run. You should see Tusk attempt to verify that the workflow runs as expected.

    <img alt="Tusk GitHub workflow verification steps" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-8.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=1d0ad7e72473c12f42a79777a5a726b6" width="2204" height="1402" data-path="images/tusk-self-serve-wizard-8.png" />
  </Step>

  <Step title="Complete test environment set-up">
    Click **Finalize configuration** once the Tusk GitHub workflow passes all steps.

    <img alt="Tusk GitHub workflow verification steps" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-9.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=4cae9f8693ac0a3ac43f576568e7cb66" width="2234" height="1682" data-path="images/tusk-self-serve-wizard-9.png" />

    Now, **enable seats** to start seeing Tusk's test generation on your PRs.

    <img alt="Tusk GitHub workflow verification steps" classname="block" src="https://mintcdn.com/tusk/49Gm3zgLxpzGJza1/images/tusk-self-serve-wizard-10.png?fit=max&auto=format&n=49Gm3zgLxpzGJza1&q=85&s=d224f43b3a700de6cb20787d49f7f596" width="2592" height="1678" data-path="images/tusk-self-serve-wizard-10.png" />
  </Step>
</Steps>

## FAQs

<AccordionGroup>
  <Accordion title="What modifications do I need to make to the Tusk GitHub workflow template?">
    You will be prompted to make modifications to the workflow template via comments in the workflow file itself. They include but are not limited to:

    * Setup steps that are specific to your project
    * Tusk API key
    * appDir relative to the root of the repo if the workflow is for a monorepo containing multiple services
    * Test framework used (e.g., pytest, Jest)
    * RegEx to match all test files in the services
    * Script to run to lint the code
    * Script to run to test the code
  </Accordion>

  <Accordion title="What is `appDir` and do I need to use one?">
    It refers to the directory containing your service code. If you have a monorepo containing multiple services, create a separate workflow for each service with a different (and non-overlapping) appDir. appDir should be relative to the root of the repo.

    Remove appDir if it doesn't apply to your repo (i.e., it is a single-service repo).
  </Accordion>

  <Accordion title="Why do I need to merge the GitHub workflow into my default branch?">
    GitHub doesn't let you run workflows that don't exist on the default branch. See [GitHub docs](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch) for `workflow_dispatch`:

    > This event will only trigger a workflow run if the workflow file exists on the default branch.
  </Accordion>

  <Accordion title="My workflow verification failed. How do I resolve this?">
    1. Create a new branch in your repo
    2. Make necessary changes to the workflow file to fix the issues
    3. Push your changes to the branch
    4. Return to the Tusk set-up wizard and retry verification (make sure to provide the correct branch above)
    5. Merge the branch into your default branch
  </Accordion>
</AccordionGroup>
