# Start a workflow from GitHub events

> Run a workflow when GitHub reports a push, a pull request, an issue, or a release, with a Webhook block set to GitHub.

To run a workflow when GitHub reports a push, a pull request, an issue, or a release, add a **Webhook** block whose **Source** is **GitHub** and give its URL to a webhook on GitHub. GitHub posts one event per request. Each event starts its own run.

You need permission to add webhooks to the repository whose events you want, and edit access to the workflow's project. The GitHub steps happen on GitHub.

## Add the Webhook block and generate its URL

1. In a draft workflow, add a **Webhook** block. The block palette also lists **GitHub webhook** in the **Start** group, which adds the block with its source already set.
2. Under **Source**, choose **GitHub**. The line under the setting reads "Verifies the signature · one run per event · skips duplicates".
3. Under **Webhook URL**, select **Generate URL**, then copy the URL.

The badge beside the URL reads "Runs start after publish". The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.

## Create the webhook in GitHub

GitHub does not issue a secret for a webhook. You choose one, enter it in GitHub's webhook form, and save the same value in OutWin. Make it long and random, and keep a copy until the next section, because GitHub does not show it again.

1. On GitHub, open the repository's **Settings**, then **Webhooks**, and add a webhook. To receive events from every repository of an organization, open the organization's **Settings** instead.
2. Paste the URL you copied as the address the webhook sends to.
3. Enter the secret you chose in **Secret**.
4. Choose the events GitHub sends to this URL, and save the webhook.

The form offers two content types for the request. The block reads both, so keep either.

The Webhook block offers these GitHub event types: `push`, `pull_request`, `pull_request_review`, `issues`, `issue_comment`, `release`, `workflow_run`, `check_run`, `create`, `delete`, `star`, `fork`, and `deployment_status`.

When the webhook is created, GitHub sends one `ping` request to the URL. **Recent deliveries** lists it as **Ping** with "A ping from the sender, not an event. Nothing ran." It shows that GitHub can reach the URL. It starts no run on a draft or on a published workflow.

## Save the Secret

GitHub signs each request with the secret from the webhook's form. The same value lets OutWin check that signature.

1. In OutWin, paste the secret into **Secret** in the block's settings.
2. Select **Save**.

After you save, the settings show only the last four characters of the secret, with **Replace** and **Remove**. Under **Set up**, the second line changes to "The secret is saved: deliveries are verified."

The secret belongs to one webhook, so OutWin saves it on the block's URL. It is not saved on a connection. A second Webhook block has its own URL and needs its own GitHub webhook and secret.

If you lose the secret, choose a new one, enter it in the webhook's form on GitHub, and select **Replace** in OutWin.

Without a saved secret the block still starts runs, and nothing is verified: anyone who has the URL can start the workflow. Publishing then shows a warning that ends "has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow". The warning does not block publishing.

## Choose which events start a run

Under **Events that start a run**, tick the event types that start a run. With none ticked, every event GitHub sends starts a run. To start runs for a type that is not listed, type it into the box under the list and select **Add**.

An event whose type is not ticked is listed as **Filtered out** and starts no run. A GitHub event type can cover more than one action, and the body's `action` field names it, such as `opened` on an `issues` event. To start runs for one action only, add a row under **Only when** with the field `body.action`. [Webhook settings](https://outwin.ai/docs/reference/triggers-approvals-and-waits/#webhook-settings) lists the comparisons.

## Send a test and check what arrived

1. On GitHub, do something that causes one of the events the webhook sends, such as opening an issue in a test repository.
2. In OutWin, look under **Recent deliveries** in the block's settings.

**Recent deliveries** lists every event that reached the URL, including while the workflow is a draft. On a draft each event is listed as **Dropped** with "The workflow is not published, so nothing ran." It starts no run and is not run later. The last line under **Set up** changes from "Waiting for the first event…" to, for example, "Received issues. Dropped." After the ping alone it reads "Received ping. Ping."

With a secret saved, an event listed as **Dropped** on a draft has passed the signature check. A delivery that fails the check is listed as **Refused**.

If you have edit access, select an event to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.

## Read the event in the next block

Each run receives one GitHub event. GitHub puts the event's type and id in request headers, not in the body, so read them from `event`. An HTTP request block or a database block directly after the Webhook block reads the event with these expressions. An AI block such as **Think** receives the whole value as its input.

| Expression | What it holds |
| --- | --- |
| `{{input.body}}` | The event's data as GitHub sent it. Many event types carry an `action` field, such as `opened` on an `issues` event. Other fields depend on the event type. |
| `{{input.body.action}}` | One field of the event. Read any other field the same way. |
| `{{input.event.type}}` | The event's type, such as `issues`. It is the request's `X-GitHub-Event` header. |
| `{{input.event.id}}` | The delivery's id. It is the request's `X-GitHub-Delivery` header. |
| `{{input.event.time}}` | Empty. OutWin reads no event time from a GitHub request. `{{input.delivery.receivedAt}}` holds the time the request arrived. |
| `{{input.delivery.verified}}` | `true` only when the signature was checked and passed. |

A block further along reads the same values through the Webhook block's name, as in `{{steps["GitHub"].body.action}}` for a block named `GitHub`. [Data and context](https://outwin.ai/docs/reference/data-and-context/) describes what each block passes on.

## Publish and check the runs

[Publish the workflow](https://outwin.ai/docs/run/publish-and-start/). From then on, each event that passes the filter starts a run. On a published workflow the block's settings are read-only, and **Recent deliveries** is in the block's inspector. You can still replace the secret there.

| Outcome | What happened |
| --- | --- |
| **Ran** | The event started a run. |
| **Waiting** | 10 runs of the workflow are already active. The event starts a run when one of them ends. An event that waits longer than an hour is listed as **Dropped**. |
| **Duplicate** | A request with the same `X-GitHub-Delivery` id already ran in the last 72 hours, which happens when a delivery is sent again from GitHub. The line reads "This event was already received and run, so it did not run again." |
| **Ping** | GitHub's `ping`. It starts no run. |

Runs start in the order events arrive. That is not always the order things happened, so do not build a workflow that relies on `pull_request` arriving before `pull_request_review`.

Receiving an event costs no credits, and neither does an event that is filtered out, a duplicate, or a ping. A run that starts uses credits for the blocks that run in it.

## If nothing runs

Open **Recent deliveries** and read the outcome and the sentence beside the newest event.

| What you see | Cause | Fix |
| --- | --- | --- |
| "Nothing has arrived yet." | No request has reached the URL, not even the ping. | Check that the webhook on GitHub is active and that its address is the block's current URL. **Rotate token** on a published workflow changes the URL, and the old one stops working. |
| **Ping** and nothing else | GitHub reached the URL, and no event has happened since. | Cause one of the events the webhook sends, and check that the webhook is set to send that event. |
| **Dropped** with "The workflow is not published, so nothing ran." | The workflow is a draft. | Publish the workflow. Events that arrived before then are not run later. |
| **Dropped** with "The workflow is paused, so nothing ran." | The workflow is paused. | Resume the workflow. Events that arrived while it was paused are not run later. |
| **Filtered out** with `Events of type "push" are not chosen on this trigger.` | The event's type is not ticked under **Events that start a run**. | Tick the type, or clear every tick so that all events start a run. The settings are read-only on a published workflow. |
| **Refused** with "The signature did not match. Check that the secret saved here is the one the sender shows for this URL." | The secret saved in OutWin is not the one in the webhook's form on GitHub. GitHub does not show its copy, so you cannot compare the two. | Choose a new secret, enter it in the webhook's form on GitHub, and select **Replace** in OutWin. You do not republish the workflow. |
| **Refused** with "The request carried no signature." | A secret is saved in OutWin, and the webhook on GitHub has none, so GitHub sent the request unsigned. | Enter the same secret in the webhook's form on GitHub. |

A delivery listed as **Refused** is answered with status `401` and starts nothing. OutWin keeps none of its data. For every other outcome in the table, GitHub receives a success response and OutWin does not run the event later.
