@tektonic-ci/reporter-github
GitHub reporters for tektonic: GitHubStatusReporter
posts commit statuses, and GitHubChecksReporter posts check runs that carry the failing
step's output (see Check runs).
Reports each task's outcome to the
GitHub Commit Status API, so a
PipelineRun shows up as per-task checks on the commit. Every context reads Queued before
the DAG starts, then Running once its task's pod starts, then the task's result. A finally
task reconciles anything left pending because its task was skipped, OOMKilled, evicted or
timed out.
Running needs a core with the StatusReporter.startStep hook (2.4.0 or later).
Under older cores a context goes straight from Queued to its result.
Install
npm install @tektonic-ci/reporter-github
@tektonic-ci/core is a peer dependency, deliberately: a reporter is matched to its
tasks by object identity, and two copies of the core package are two incompatible sets of
classes. Your project pins the version; this package follows it.
Use
import { Task } from '@tektonic-ci/core';
import { GitHubStatusReporter } from '@tektonic-ci/reporter-github';
// Under PAC, reuse the git-auth token from the pod env rather than injecting a
// github-token secret into every step.
const statusReporter = new GitHubStatusReporter({ skipTokenInjection: true });
new Task({ name: 'test', statusReporter, steps: [/* … */] });
The task's statusContext (defaulting to its name) becomes the GitHub check name. The
reporter needs repo-full-name and revision params, which it merges into every task that
uses it; TektonicProject binds both from PAC.
A failed task's status names the step that failed and its exit code (Failed: step test exited 1), so the check says where it broke before you open any logs. With Running
reported, the result also says how long the task took: Passed in 3m12s, Failed: step test exited 1 (2m05s).
Details links
By default the statuses carry no Details link. Pass detailsUrl to give each one a
target_url into your console. For a Tekton Dashboard:
import { GitHubStatusReporter, tektonDashboardUrl } from '@tektonic-ci/reporter-github';
const statusReporter = new GitHubStatusReporter({
skipTokenInjection: true,
detailsUrl: tektonDashboardUrl('https://tekton.example.com'),
});
A task's own statuses (Running and its result) link its TaskRun. Queued statuses and the ones the finally reconciler
posts (skipped or killed tasks, which may have no TaskRun) link the PipelineRun. For another
console, pass the templates yourself, using {namespace}, {pipelineRun} and {taskRun}:
detailsUrl: {
pipelineRun: 'https://console.example.com/runs/{namespace}/{pipelineRun}',
taskRun: 'https://console.example.com/runs/{namespace}/{pipelineRun}/{taskRun}', // optional
}
Setting it adds a pipeline-run-name param to each reporting task, bound from
$(context.pipelineRun.name) in the pipeline, so nothing new has to be passed in.
These links cover the per-task statuses only. The Pipelines as Code CI / … check runs take
their links from Pipelines as Code's own pipelines-as-code ConfigMap (tekton-dashboard-url
or the custom-console-* keys), which is cluster configuration.
Image
The status steps POST with nushell's http post, so they need an image providing nushell.
They resolve through the project's injectedStepImage and synthesis fails naming the
capability if it does not declare one — pass image to override per reporter.
Check runs
GitHubChecksReporter reports each task as a GitHub
check run instead of a commit status. A commit
status holds a state, a 140-character description and a link. A check run can carry:
- real
queued, in_progress and completed states, with GitHub's own timing;
- a Markdown summary: a table of the task's steps and how each ended;
- the tail of the first failing step's output (ANSI colours stripped);
- annotations parsed from that output, such as
./pkg/x.go:42:7: undefined: foo, shown inline on the PR;
- a
skipped conclusion for tasks Tekton skipped, instead of a green status.
import { GitHubChecksReporter, tektonDashboardUrl } from '@tektonic-ci/reporter-github';
// PAC's per-run GitHub App token, on the reporter's steps only. PAC substitutes
// {{ git_auth_secret }} in the task files before it applies them.
const statusReporter = new GitHubChecksReporter({
tokenSecretName: '{{ git_auth_secret }}',
tokenSecretKey: 'git-provider-token',
detailsUrl: tektonDashboardUrl('https://tekton.example.com'),
});
The token must be a GitHub App installation token. A personal access token gets
403 Resource not accessible. Under Pipelines as Code, use PAC's App token as shown above. The
runs then belong to the PAC App's check suite. Outside PAC, put an App installation token in a
Secret and pass tokenSecretName (and tokenSecretKey if its key is not token).
Avoid a pod-wide GITHUB_TOKEN. Passing the token through TektonicProject's
podTemplateEnv with skipTokenInjection: true also works, but it reaches every step,
including the code under test, for the token's lifetime (an hour). Tekton also gives pod
template env precedence over step env,
so it silently replaces any GITHUB_TOKEN a step sets for itself, such as a PAT used for SARIF
upload.
Long or queued pipelines: use appAuth. PAC's token expires an hour after PAC creates the
PipelineRun, and that hour includes any time the run waits in a Repository's
concurrency_limit queue. Calls made after that fail and leave the check as it was: queued, or
in_progress for a task that was running. A Renovate automerge or a required check then waits
forever. With appAuth, every reporting step mints its own short-lived installation token from a
GitHub App's private key, so the reporter works however long the run waits or runs:
const statusReporter = new GitHubChecksReporter({
// A Secret with `app-id` (App ID or client ID) and `private-key` (the App's PEM key).
appAuth: { secretName: 'github-checks-app' },
detailsUrl: tektonDashboardUrl('https://tekton.example.com'),
});
Each step signs a JWT with openssl (the reporter's image must provide it, alongside nushell),
looks up the App's installation on the repository, and asks for a token limited to that one
repository and checks: write. Give the App only Checks: read and write and install it on the
repositories it reports for. Its private key can mint tokens for every installation of the App,
so prefer an App of its own over the PAC App's key. The check runs belong to this App's check
suite, and appAuth excludes tokenSecretName/tokenSecretKey. appIdKey and privateKeyKey
rename the Secret keys.
Step output is posted as printed, secrets included. Anyone who can see the repository's
checks can read it, which for a public repository means anyone. Pass output: false for a task
that may print credentials. Annotations come from that output, so they go away with it.
Options it shares with GitHubStatusReporter (image, tokenSecretName, tokenSecretKey,
skipTokenInjection, repoFullNameParam, revisionParam, pendingTaskComputeResources,
failOnError, detailsUrl) mean the same here. On top of those:
| Option |
Default |
|
appAuth |
none |
{ secretName, appIdKey?, privateKeyKey? }: mint a fresh GitHub App installation token in every step instead of reading tokenSecretName. See above |
output |
{ maxBytes: 60000 } |
How much of the failing step's output to post, or false. 60000 is also the cap: GitHub limits a summary to 65535 characters |
annotationPattern |
DEFAULT_ANNOTATION_PATTERN |
Rust-syntax regex with named groups path, line and message, applied to each output line. false turns annotations off |
How a run moves:
- The pending task creates a
queued run per context, linked to the PipelineRun, and passes
each ID to its task through a pending-task result.
- When the task's pod starts, the run moves to
in_progress, linked to the TaskRun.
- The task's final step completes it with
success or failure, the summary, the output tail
and annotations.
- The
finally reconciler concludes a skipped task's run as skipped, and the run of a task
killed before its final step (OOMKill, eviction, timeout, image pull) as failure. A run its
task already completed is left alone, so its summary survives.
No GitHub failure fails a pipeline. If the pending task cannot create a run, the start step
creates it; if neither could, the final step does. The pending task writes every result before
it calls GitHub, so a pipeline never fails on a missing result.
It needs core 2.5.0 or later, for pendingTaskResults and step-output capture. A
GitHubChecksReporter and a GitHubStatusReporter can share a pipeline; each gets its own
pending and reconciler task.
Not verified yet: what Pipelines as Code does when someone presses Re-run on one of these
check runs. GitHub sends the PAC App a check_run.rerequested event; PAC most likely re-runs
the whole PipelineRun rather than the one task.
Exports
| Export |
What it is |
GitHubStatusReporter |
The StatusReporter implementation |
GitHubStatusReporterOptions |
Constructor options |
statusParam(taskName) |
The $(tasks.<name>.status) param its reconciler task binds |
tektonDashboardUrl(baseUrl) |
detailsUrl templates for a Tekton Dashboard |
StatusDetailsUrl |
The detailsUrl option's type |
PIPELINE_RUN_PARAM |
Name of the param detailsUrl adds (pipeline-run-name) |
GitHubChecksReporter |
The check-runs StatusReporter |
GitHubChecksReporterOptions |
Its constructor options |
checkRunResultName(context) |
The pending-task result holding a context's check-run ID |
CHECK_RUN_ID_PARAM |
The param a reporting task receives that ID in (check-run-id) |
CHECK_RUN_ID_PATH |
Where the start step leaves the ID for the final step |
DEFAULT_ANNOTATION_PATTERN |
The default annotationPattern |
MAX_CHECK_OUTPUT_BYTES |
Default and cap for output.maxBytes (60000) |
Why it is a separate package
Because nothing else proves the StatusReporter seam works. This repo builds and tests
against @tektonic-ci/core as published on npm, exactly as a third-party reporter would, so
anything such a reporter would need and cannot reach fails here first. See
docs/status-reporters.md to write your own.
License
Apache-2.0