Documentation
¶
Overview ¶
Package githubactions provides the HTTP client and GitHub Actions-specific facts (run status/conclusion vocabulary and run id encoding) shared by every domain's GitHub Actions-backed BuildRunner. It intentionally holds no BuildRunner interface or domain entity types — each domain (submitqueue, stovepipe, ...) defines its own BuildRunner and its own BuildStatus, and adapts this package's RunStatus to it. See platform/buildkite's README for the analogous rationale applied to the Buildkite backend.
Index ¶
- Variables
- func EncodeRunID(runID int64) string
- func ParseRunID(id string) (int64, error)
- func RunMetadata(run WorkflowRun) map[string]string
- type Client
- func (c *Client) CancelRun(ctx context.Context, runID int64) error
- func (c *Client) DispatchWorkflow(ctx context.Context, req DispatchWorkflowRequest) (DispatchWorkflowResponse, error)
- func (c *Client) GetRun(ctx context.Context, runID int64) (WorkflowRun, error)
- func (c *Client) Owner() string
- func (c *Client) Repo() string
- func (c *Client) WorkflowID() string
- type DispatchWorkflowRequest
- type DispatchWorkflowResponse
- type RunStatus
- type WorkflowRun
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("githubactions: resource not found")
ErrNotFound is returned when the GitHub Actions API responds with 404 to a request for a resource by ID (e.g. GetRun on an unknown run, or CancelRun on an already-deleted run).
Functions ¶
func EncodeRunID ¶
EncodeRunID encodes a GitHub Actions workflow run id as an opaque build id string.
func ParseRunID ¶
ParseRunID is the inverse of EncodeRunID.
func RunMetadata ¶
func RunMetadata(run WorkflowRun) map[string]string
RunMetadata builds the caller-facing metadata map for a workflow run: the run's own identity and outcome fields, keyed for direct use as (or merge into) a domain's BuildMetadata.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin wrapper around the GitHub Actions REST endpoints a BuildRunner needs: workflow dispatch, get workflow run, and cancel run. It is bound to a single repository and workflow.
func NewClient ¶
NewClient wraps a pre-configured *http.Client as a GitHub Actions Client bound to one repository and workflow. The caller is responsible for base URL resolution (e.g. via platform/http.BaseURLTransport, typically "https://api.github.com") and auth (a token with actions:read/actions:write injected via a transport).
func (*Client) CancelRun ¶
CancelRun requests cancellation of the workflow run. Returns nil when the run is already terminal or otherwise not cancellable (HTTP 409/422) — the BuildRunner contract treats that as a no-op.
func (*Client) DispatchWorkflow ¶
func (c *Client) DispatchWorkflow(ctx context.Context, req DispatchWorkflowRequest) (DispatchWorkflowResponse, error)
DispatchWorkflow dispatches the bound workflow.
Dispatching is not idempotent and a rejection carries its status code like any other, so a caller that retries a 502 can start a second run when the first was already accepted. Callers that cannot tolerate that need their own idempotency check.
func (*Client) WorkflowID ¶
WorkflowID is the workflow file name or numeric workflow ID this Client is bound to.
type DispatchWorkflowRequest ¶
type DispatchWorkflowRequest struct {
Ref string `json:"ref"`
ReturnRunDetails bool `json:"return_run_details,omitempty"`
Inputs map[string]string `json:"inputs,omitempty"`
}
DispatchWorkflowRequest is the payload for POST .../dispatches.
type DispatchWorkflowResponse ¶
type DispatchWorkflowResponse struct {
WorkflowRunID int64 `json:"workflow_run_id"`
RunURL string `json:"run_url"`
HTMLURL string `json:"html_url"`
}
DispatchWorkflowResponse is the subset of fields callers need from a dispatch-workflow response.
type RunStatus ¶
type RunStatus string
RunStatus is GitHub Actions' own run status/conclusion vocabulary, collapsed into the five states every domain's BuildStatus already distinguishes.
const ( // RunStatusUnknown is returned for a raw status/conclusion pair this // package does not recognize. Not terminal — callers should keep polling // rather than treat it as a final outcome. RunStatusUnknown RunStatus = "" // RunStatusAccepted means the run has been accepted for execution but has // not started yet (GitHub: queued, requested, waiting, pending). RunStatusAccepted RunStatus = "accepted" // RunStatusRunning means the run is currently executing (GitHub: // in_progress). RunStatusRunning RunStatus = "running" // RunStatusSucceeded means the run completed successfully (GitHub: // completed with conclusion success). RunStatusSucceeded RunStatus = "succeeded" // RunStatusFailed means the run completed without a passing result // (GitHub: completed with any conclusion other than success/cancelled). RunStatusFailed RunStatus = "failed" // RunStatusCancelled means the run was cancelled (GitHub: completed with // conclusion cancelled). RunStatusCancelled RunStatus = "cancelled" )
func ParseRunStatus ¶
ParseRunStatus maps a raw GitHub Actions run status/conclusion pair to a RunStatus. conclusion is only consulted when status is "completed". An unrecognized status, or a completed run with an empty conclusion, maps to RunStatusUnknown rather than being assumed terminal.
type WorkflowRun ¶
type WorkflowRun struct {
ID int64 `json:"id"`
Name string `json:"name"`
DisplayTitle string `json:"display_title"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
HTMLURL string `json:"html_url"`
RunAttempt int `json:"run_attempt"`
Event string `json:"event"`
HeadBranch string `json:"head_branch"`
CreatedAt string `json:"created_at"`
}
WorkflowRun is the subset of a GitHub Actions workflow run object callers need.