# GitHub Actions adapter

Shows the runs of your GitHub repositories in the notch, under the GitHub Actions tile: whether a run works, passed or failed, its jobs as stages, and a request when a run waits for your review. Blossom only shows them: approving, re-running and cancelling happen on GitHub, in your browser.

The adapter reads GitHub through `gh`, the GitHub command line, signed in as you. It holds no token and writes nothing to GitHub: it only runs `gh run list` and `gh run view`. Why is in [the decision](../../documentation/decisions/actions.md), and what it shows when, in [the specification](../../documentation/roadmap/pipelines.md).

## Before you start

```sh
brew install gh
gh auth login
gh run list --repo <owner>/<name> --limit 1
```

The last command must print a run. If it says you are not signed in, or prints `HTTP 404`, the adapter will say the same and show nothing.

## Connect from Blossom

With `gh` installed and signed in, as above, Settings > Agents lists GitHub Actions. Turn its switch on: Blossom asks `gh` for your repositories, 200 at most and only your own, and lists them. Check the ones whose runs you want to see and click "Watch": Blossom adds this adapter with those repositories as its arguments and starts it. No token is asked for or written; the adapter uses the session of `gh`. A repository of an organization is added by hand, as below. "Disconnect", shown while it is off, takes the adapter out. See [the decision](../../documentation/decisions/connecting.md).

## Run it

Blossom includes this adapter as the package `actions`. Name the repositories to watch as its arguments, `owner/name`, or `host/owner/name` for GitHub Enterprise, in the configuration of Blossom, `~/Library/Application Support/Blossom/configuration.json`:

```json
{
  "adapters": [{ "package": "actions", "arguments": ["you/app", "you/site"] }]
}
```

It finds `gh` where Homebrew puts it also when Blossom is opened from Finder; see [`../../documentation/decisions/commands.md`](../../documentation/decisions/commands.md).

To try it from this repository, after `bun run build`, edit the repository in `adapters/actions/configuration.json` and run from the root:

```sh
BLOSSOM_CONFIGURATION=adapters/actions/configuration.json apps/macos/build/Build/Products/Debug/Blossom.app/Contents/MacOS/Blossom
```

The adapter logs to the terminal that started Blossom. It polls every sixty seconds, so a run shows up within a minute.

## What it shows

- Runs that work or wait for a review when Blossom starts, and every run that starts while it watches, with its outcome. Runs that finished before Blossom started are not shown.
- A run is named after its workflow, with its branch next to it, in the project of its repository, without the owner. Where a run is shown alone it reads `blossom · ci`. Two or more runs of one repository stack in one row of peek and of the command bar, `blossom · 3 runs`, that opens with `↩` or a click and lists them by workflow and branch. Two repositories of different owners with the same name are one project. A character that acts or hides, in any of the three, shows as its escape.
- The jobs of a run are its stages, in the order GitHub lists them.
- A run that waits for the review of an environment, or for a maintainer to let the workflows of a fork run, raises a request with one answer, Review in GitHub, which opens the run in your browser.
- A run cancelled or skipped on GitHub leaves the notch.

## Checks by hand

Not run against real GitHub Actions runs. Use a repository of yours where Actions run, with a workflow you can start by hand, such as one with `on: workflow_dispatch` and two jobs.

1. Start Blossom with the adapter watching that repository, as above. Nothing about past runs appears.
2. Start the workflow: `gh workflow run <workflow> --repo <owner>/<name>`. Within a minute the GitHub Actions tile appears in the ear. Hover the ear: peek shows the run as `<repository> · <workflow>` with its branch, a segment per job and the job it is at. Start the workflow again: peek shows one row, `<repository> · 2 runs`; click it, and the two runs are listed under it by workflow and branch. Click the row: detail lists the jobs, and `↩` opens the run in your browser.
3. Wait for the end. The toast says GitHub Actions is done, and the badge turns green. Make a job fail, for example with `exit 1` in a step, and run it again: the toast says it failed and names the job that failed.
4. Cancel a run while it works: `gh run cancel <id> --repo <owner>/<name>`. Within a minute it leaves the notch.
5. With an environment that requires your review, start a run that deploys to it. The request panel opens with Review in GitHub; choose it, and the page of the run opens in your browser. Approve it there: within a minute the run works again.
6. Quit Blossom and start it again with `GH_CONFIG_DIR=$(mktemp -d) GH_TOKEN=` before the command, which hides your sign in from `gh` without signing you out: the terminal says `gh is not signed in to github` and nothing appears.
