---
title: "Report deploys to GitHub"
summary: "How ob reports deploys and rollbacks to GitHub deployments from wherever it runs, which commit it reports, and what it never does."
description: "Show every deploy and rollback in a repository's Environments tab, on pull requests, and to tools that read deployment statuses."
status: shipped
read_when:
  - "Showing what is live in GitHub without deploying from GitHub Actions"
  - "Wiring a tool that reads deployment_status events to Onebox deploys"
  - "Working out why a deploy was not reported"
---
Hosting platforms tell GitHub when a commit goes live, so pull requests say
"deployed to production" and tools that listen for `deployment_status` events
react. A deploy run from GitHub Actions gets the same through a job's
`environment`. `ob` deploys from a laptop, a dev box or an agent, so it reports
itself.

```yaml
spec:
  github:
    repository: labstack/shop
```

With this block, `ob deploy` creates a GitHub deployment once the server has
recorded the deploy's start, marks it in progress, and marks it `success`, `failure`
or `error` when it finishes. `ob rollback` records a deployment for the release
it restored. `ob resume` gives an interrupted deploy's deployments their final
outcome, and records the release if the interrupted run never reached GitHub;
`ob abort` marks them `failure`. A no-op deploy, and a deploy refused before it
started, report nothing.

`ob` reports the same way from a terminal, an agent or a
[GitHub Actions workflow](/docs/guides/deploy-from-github-actions). For GitHub
Enterprise, set `apiUrl` to the API base, such as
`https://github.example.com/api/v3` or `https://api.acme.ghe.com`, and confirm
it in your own environment with the same URL:

```sh
export ONEBOX_GITHUB_API_URL=https://github.example.com/api/v3
```

A project file names the host, so without that confirmation `ob` sends no
token there. A github.com token is never sent to it either: `ob` uses
`tokenEnv`, then `GH_ENTERPRISE_TOKEN`, `GITHUB_ENTERPRISE_TOKEN`, or the token
`gh` holds for that host. For the same reason `tokenEnv` must name a GitHub
token variable, containing `GH` or `GITHUB` and ending in `TOKEN`, such as
`SHOP_GH_TOKEN`.

## The token stays where `ob` runs

`ob` uses the variable named by `tokenEnv`, otherwise `GH_TOKEN`, then
`GITHUB_TOKEN`, then `gh auth token`. With `apiUrl` set for GitHub Enterprise,
the fallbacks are `GH_ENTERPRISE_TOKEN`, `GITHUB_ENTERPRISE_TOKEN`, then
`gh auth token --hostname HOST`. The token needs Deployments write access
to the repository: a fine-grained token with **Deployments: read and write**,
or a classic token with `repo_deployment`.

The token is never written to the server, the journal or structured output.
That is also why work the server runs on its own, such as scheduled jobs, is
not reported.

In GitHub Actions, `GH_TOKEN: ${{ github.token }}` with
`permissions: deployments: write` is enough.

A missing token or a failed GitHub call is a warning on stderr. It never fails
or blocks a deploy, and a GitHub that does not answer delays the end of the
command by at most 15 seconds.

## Which commit is reported

GitHub records one commit per deployment, and it must be one GitHub has seen.
`ob` decides which at plan time, so a saved plan reports exactly what was
reviewed:

1. A workload image whose `org.opencontainers.image.source` label names the
   repository is reported at its `org.opencontainers.image.revision`. Images
   are pinned by digest, so the labels cannot change between plan and apply.
2. Each image repository is reported in its own GitHub environment, because a
   release that ships `shop-web` at one version and `shop-server` at another
   has no single commit: `production (shop-web)` and
   `production (shop-server)`.
3. When no image comes from the repository, the repository holds only the
   configuration. If the checkout is a clean clone of the repository, its
   commit is reported, in an environment named after the application, such as
   `production (shop)`.

Anything else reports nothing rather than something untrue: a dirty checkout,
a checkout of another repository, an image whose labels could not be read, an
image from the repository without a full revision, or one image repository
deployed at two commits. That includes third-party images such as a database:
if one cannot be inspected, the release reports nothing, because `ob` cannot
tell that it is not from the repository. A commit that was never pushed is
refused by GitHub and reported as a warning.

A rollback reports the commits the restored release recorded when it was
deployed. A release deployed before the `github` block was added has none, and
its rollback is not reported.

### Labelling images

`docker/metadata-action` computes both labels, but they reach the image only
when its `labels` output is passed to the build, for example
`labels: ${{ steps.meta.outputs.labels }}` on `docker/build-push-action`. `ob`
reads image labels, not manifest annotations. On a `pull_request` build the
revision is GitHub's merge commit unless `DOCKER_METADATA_PR_HEAD_SHA` is
`true`.

## Reading the deployments

Every environment name carries a component, as Vercel's
`Production – project` names do, so names stay the same when a project adds an
image repository. A consumer should not match the literal name `production`.
Each deployment's payload says where it belongs:

| Field | Value |
| --- | --- |
| `environment` | the Onebox environment, such as `production` |
| `component` | the image repository, or the application for a configuration-only repository |
| `commit_source` | `image` or `checkout` |
| `release_id` | the Onebox release |
| `app`, `operator`, `runner` | the application, who deployed, and the `ob` version |

`production_environment` is set for every component of the `production`
environment.

## What GitHub does not do here

Environment protection rules, such as required reviewers and wait timers, are
documented as gating GitHub Actions jobs. They never gate `ob`: approval stays
with Onebox's own plan review and `policy.requireApproval`. If a rule makes
GitHub refuse the report, the refusal is a warning and the deploy is
unaffected.