# Run the jobs of a GitHub repository on a runner pool

Keep a repository, its pull requests and its workflows on GitHub, and run its GitHub Actions jobs on {{product}} machines by changing one line of the workflow.

GitHub keeps the code, the pull requests, the workflows and the secrets. A job whose `runs-on`
names the pool's label runs on a machine of a Deutsche Cloud runner pool instead of one of GitHub's: a
just-in-time runner made for that job on a machine in your organization. You run no runner server,
scaling workflow or token of your own. Every other job stays on GitHub's runners.

## Prerequisites

- The repository belongs to a GitHub **organization**. Repositories of a personal GitHub account
  are not supported.
- Someone who administers that GitHub organization installs the Deutsche Cloud GitHub App on it.
- In Deutsche Cloud: `git:ConnectGithub` to connect the installation, `ci:ConnectGithubRunners` to
  switch the runners on, and `ci:CreateRunnerPool` when the organization has no pool for GitHub
  jobs yet.

## Set it up

Installing the App is the whole setup. When you install it from Deutsche Cloud, every repository the
installation covers is switched on, and if your organization has no runner pool for GitHub jobs,
the pool **dc-4x8** is created: labels `dc-4x8` and `deutsche-cloud`, 4 vCPU and 8 GiB, own hosts
first, no machine while nothing runs, at most 16 at once. Every other size (`dc-16x32`,
`dc-arm-4x8`, …) gets its pool the first time a job names it: see [Runner sizes](runner-sizes.md).

**Console**
1. Open **Git**, then **Connect GitHub**, and choose **Connect a GitHub account**.
2. On GitHub, choose the organization and the repositories, and install the App. GitHub sends you
   back to Deutsche Cloud.
3. Under the organization, **Run GitHub Actions jobs on our runners** is on and names the pool.
   For an installation made before, switch it on there.

**CLI**
After installing the App on the organization, bind one repository (replace acme/app with
yours):

```sh
dcloud ci runner-pools connect-github acme/app
```

Add `--pool` with the name of another pool to use that one.

**API**
```http
POST /ci/api/runner-pools/connect-github/acme%2Fapp
{ "allowForkPullRequests": false }
```

Every repository of an installation (its id from `GET /git/api/github/installations`):

```http
PUT /ci/api/github-runners/installations/{id}
{ "enabled": true }
```

Then change the job's `runs-on` in the workflow on GitHub:

```yaml
jobs:
  build:
    runs-on: [self-hosted, dc-4x8] # was: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make test
```

`runs-on: [self-hosted, deutsche-cloud]` works too: it is another name for `dc-4x8`. A job reaches
a pool when every label it names is one of the pool's labels or `self-hosted`, `linux` or `x64`,
and at least one is the pool's.

Once a repository is bound, its jobs reach every runner of your organization whose labels they
name, not only the bound pool:

| The job's `runs-on`                                            | Where it runs                                                                                                                                 |
| -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `[self-hosted, <a pool's label>]`                              | that Linux runner pool                                                                                                                        |
| `[self-hosted, dc-16x32]` (any [runner size](runner-sizes.md)) | your organization's pool for that size, made when the first job asks                                                                          |
| `[self-hosted, windows-latest]` (or `windows-2022`, …)         | your Windows runner pool on Azure, one fresh VM per job; without one, the hosted Windows runner (see [Hosted runners](use-hosted-runners.md)) |
| `[self-hosted, macos-latest]` (or `macos-14`, `macOS`, …)      | your Macs, one fresh macOS VM per job; without one, the hosted macOS runner                                                                   |

Keep `self-hosted` in the list: a job that names only GitHub's own labels (`ubuntu-latest`,
`windows-latest`, `macos-latest`) runs on GitHub's machines, never on yours. Intel macOS labels
(`macos-15-intel`, `macos-13`) wait on GitHub: every Mac is Apple silicon.

**Important:**
The pool's machines are cloud machines of your organization and are billed per started hour, like
any runner pool (see [Cap cloud spend](cap-cloud-spend.md)). GitHub does not bill minutes of jobs
on self-hosted runners.

## Result

When GitHub queues such a job, the pool starts a machine (or uses an idle one) within about a
minute. The machine asks GitHub for a just-in-time runner that takes one job, runs it with
GitHub's own runner, and cleans up: containers, volumes, the work directory and `/tmp` are removed
before its next job. The run, its logs and its check stay on GitHub.

The pool's page (**Runners**, then the pool) shows, for GitHub jobs:

- **GitHub repositories**: what sends jobs to the pool, with **Remove**.
- **GitHub jobs, per job**: for each repository, workflow and job name (a matrix leg is its own
  job), the median (p50) and p90 duration over its last 20 successful runs, the last run, and the
  machine's highest CPU and memory use while the jobs ran.
- **GitHub jobs, newest first**: how long each waited and took, **Last time** (the same job's run
  before), the machine size and where it ran.

The same is returned by `ci.runner-pools.github-jobs`.

## Who runs on the machines

- A machine serves one GitHub repository for its life, and one kind of job: the default branch,
  tags, schedules and dispatches; or merge queue builds; or one pull request. It never takes a job
  of another repository, another pull request or one of your Deutsche Cloud repositories.
- **Pull requests from forks** never run on the pool unless the binding allows it
  (`allowForkPullRequests`). Such a job is refused, its workflow run is cancelled on GitHub, and
  the pool hands out no runner for that repository while the job is still queued. On GitHub, also
  set **Require approval for all external contributors** under the repository's Actions settings.
- The runners join a GitHub runner group made for the binding (Deutsche Cloud followed by the
  pool's name), which only the bound repository may use. Where GitHub refuses a runner group (an
  organization on GitHub Free), they join the organization's **Default** group and the binding says
  so; then any private repository of that organization whose jobs name the pool's label can use them.
- A job that deploys with an environment's secrets or OIDC leaves nothing for the next job only on
  a pool that destroys every machine after its job: set **cleanMachinePerJob** on such a pool (see
  [Change or delete a runner pool](change-or-delete-a-runner-pool.md)).

## Related

- [Create a runner pool](create-a-runner-pool.md)
- [Cap cloud spend](cap-cloud-spend.md)
- [Connect GitHub](/docs/git/guide/connect-github)
