Github Extension

The Github extension allows Gofer pipelines to be run on Github webhook events. This makes it possible to write event driven workloads that depend on an action happening on Github.

See the events section below for all supported events and the environment variables they pass to each pipeline.

Note:

Due to the nature of Github's API and webhooks, you'll need to first set up a new Github app to use with Gofer's Github extension.

Steps to accomplish this can be found in the setup section.

Danger:

The Github extension requires the external events feature of Gofer in order to accept webhooks from Github's servers. This requires your application to take traffic from external, potentially unknown sources.

Visit the external events page for more information on how to configure Gofer's external events endpoint.

If Github is your only external extension, to increase security consider limiting the IP addresses that can access Gofer's external events endpoint.

Pipeline Configuration

KeyDefaultDescription
repositoryRequiredThe Github repository you would like to listen for events from. The format is in the form.
event_filterRequiredThe event/action combination the pipeline will be triggered upon. It is presented in the form: <event>/<action1>,<action2>.... For events that do not have actions or if you simply want to trigger on any action, just putting the <event> will suffice.
Note:

If you don't include actions on an event that has multiple, Gofer will be triggered on any action. You can find a list of events and their actions here(Actions listed as 'activity type' in Github nomenclature.): https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

Example

gofer pipeline subscribe simple github run-tests \
    -s "repository=clintjedwards/experimental" \
    -s "event_filter=pull_request_with_check/opened,synchronize,reopened"

Extension Configuration

The Github extension isn't installed by default. It requires a Github app of your own; the setup walkthrough below covers creating one and installing the extension.

KeyDefaultSecretDescription
app_idRequirednoThe Github app's ID, shown on the app's settings page.
app_installationRequirednoThe ID of the app's installation on your account or organization. See finding the installation ID below.
app_keyRequiredyesThe Github app's private key in PEM format, exactly as Github gives it to you.
app_webhook_secretRequiredyesThe webhook secret set on the Github app. Gofer uses it to verify that webhooks really came from Github. It should be a long, random string.
gofer_urlnoWhere people reach Gofer's web UI, like https://gofer.example.com. When set, each check run links to its run's page in Gofer. When not, check runs have no link.

Secret settings must be global secret references like global_secret{{github-app-key}}.

Example

[[extensions.install]]
id = "github"
manifest = "https://raw.githubusercontent.com/clintjedwards/gofer/v<gofer version>/containers/extensions/github/manifest.toml"
[extensions.install.settings]
app_id = "112348"
app_installation = "99560091"
app_key = "global_secret{{github-app-key}}"
app_webhook_secret = "global_secret{{github-app-webhook-secret}}"
gofer_url = "https://gofer.example.com"
Note:

Before Gofer 0.12 the private key had to be base64 encoded. It's now passed exactly as Github gives it to you; store the original .pem file, not the base64 version.

Setting it up

Due to the nature of Github's API and webhooks, you'll need to first set up a new Github app to use with Gofer's Github extension. Once this app has been set up, you'll have everything you need to configure the extension.

Here is a quick and dirty walkthrough on the important parts of setting up the Github application.

1. Create a new Github application:

Github's documentation will be the most up to date and relevant so please see their walkthrough.

On the configuration page for the new Github application the following should be noted:

  • APP ID: Take note of the id; it will be used later for extension configuration.

  • Webhook URL: Should be the address of your Gofer's external extension instance and pointing to the events/github endpoint:

    ex: https://mygoferinstance.yourdomain.com/external/github

  • Webhook Secret: Make this a secure, long, random string of characters and note it for future extension configuration.

  • Private Keys: Generate a private key and keep the .pem file Github gives you; you'll store it in Gofer's secret store in step 3.

Note:

If you need a logo for your new Github application you're welcome to use logo-small

2. Find the installation ID

Once the Github application has been created, install it. This will give you an opportunity to configure the permissions and scope of the Github application. It is recommended that you give read-only permissions to any permissions that might include webhooks and read-write for code-suite and code-runs.

You might also utilize this Github App to perform other actions within Github with either other extensions or your own pipeline jobs. Remember to allow the correct permissions for all use cases.

The installation ID is unfortunately hidden in an event that gets sent once the Github app has been created and installed. You can find it by navigating to the settings page for the Github application and then viewing it in the "Recent Deliveries" page.

🪧 These recent deliveries only last a short amount of time, so if you take a while to check on them, they might not exist anymore. If that has happened you should be able to create another event and that will create another recent delivery.

Recent Deliveries Installation webhook event

3. Store the secrets

Put the private key and webhook secret in Gofer's global secret store. Leaving out the value prompts for it, which keeps it out of your shell history.

gofer secret global put github-app-key < ~/Downloads/myorg-gofer.2022-01-24.private-key.pem
gofer secret global put github-app-webhook-secret

4. Add the extension to Gofer's config

Add an [[extensions.install]] entry like the example above, with your app ID and installation ID and references to the two secrets. Point manifest at the github manifest for your version of Gofer.

gofer extension manifest <manifest url> --id github prints this block for you, with every setting documented.

5. Reload

gofer extension reload

Gofer shows the extension it's about to install and its settings; confirm, and it starts. If it doesn't, gofer extension list shows why and gofer extension logs github shows what the extension itself reported.

Events

Gofer's extensions have the ability to pass along event specific information in the form of environment variables that get injected into each container's run. Most of these variables are pulled from the webhook request that comes in.

Below is a breakdown of the environment variables that are passed to a run based on the event that was generated. You can find more information about the format the variables will be in by referencing the payloads for the event.

Events below are the only events that are supported.

EventMetadata
pull_request"GOFER_EXTENSION_GITHUB_EVENT"
"GOFER_EXTENSION_GITHUB_ACTION"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_HEAD_REF"
"GOFER_EXTENSION_GITHUB_REPOSITORY"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_HEAD_SHA"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_USERNAME"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_EMAIL"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_NAME"
pull_request_with_check"GOFER_EXTENSION_GITHUB_EVENT"
"GOFER_EXTENSION_GITHUB_ACTION"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_HEAD_REF"
"GOFER_EXTENSION_GITHUB_REPOSITORY"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_HEAD_SHA"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_USERNAME"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_EMAIL"
"GOFER_EXTENSION_GITHUB_PULLREQUEST_AUTHOR_NAME"
push"GOFER_EXTENSION_GITHUB_EVENT":
"GOFER_EXTENSION_GITHUB_ACTION"
"GOFER_EXTENSION_GITHUB_REF"
"GOFER_EXTENSION_GITHUB_REPOSITORY"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_ID"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_AUTHOR_NAME"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_AUTHOR_EMAIL"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_AUTHOR_USERNAME"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_COMMITTER_NAME"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_COMMITTER_EMAIL"
"GOFER_EXTENSION_GITHUB_HEAD_COMMIT_COMMITTER_USERNAME"
release"GOFER_EXTENSION_GITHUB_ACTION"
"GOFER_EXTENSION_GITHUB_REPOSITORY"
"GOFER_EXTENSION_GITHUB_RELEASE_TAG_NAME"
"GOFER_EXTENSION_GITHUB_RELEASE_TARGET_COMMITISH"
"GOFER_EXTENSION_GITHUB_RELEASE_AUTHOR_LOGIN"
"GOFER_EXTENSION_GITHUB_RELEASE_CREATED_AT"
"GOFER_EXTENSION_GITHUB_RELEASE_PUBLISHED_AT"
Note:

The event pull_request_with_check is a special event not found within the Github API. It's primarily to be used when the subscriber wants to report the job status back to the pull request based on the result of the job started