Skip to content

Commit 3fe2a34

Browse files
committed
T41: add GitHub runner provider
C33 V74 V76
1 parent a05208b commit 3fe2a34

9 files changed

Lines changed: 776 additions & 11 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
.PHONY: build test install clean
22

33
BINARY_NAME = workflow-plugin-github
4+
PROVIDER_BINARY_NAME = github-runner-provider
45
INSTALL_DIR ?= data/plugins/$(BINARY_NAME)
56

67
build:
7-
GOPRIVATE=github.com/GoCodeAlone/* go build -o bin/$(BINARY_NAME) ./cmd/$(BINARY_NAME)
8+
GOWORK=off GOPRIVATE=github.com/GoCodeAlone/* go build -o bin/$(BINARY_NAME) ./cmd/$(BINARY_NAME)
9+
GOWORK=off GOPRIVATE=github.com/GoCodeAlone/* go build -o bin/$(PROVIDER_BINARY_NAME) ./cmd/$(PROVIDER_BINARY_NAME)
810

911
test:
10-
GOPRIVATE=github.com/GoCodeAlone/* go test ./... -v -race
12+
GOWORK=off GOPRIVATE=github.com/GoCodeAlone/* go test ./... -v -race
1113

1214
install: build
1315
mkdir -p $(DESTDIR)/$(INSTALL_DIR)

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,36 @@ modules:
2121
2222
The module registers an HTTP handler at `/webhooks/github`. Configure your GitHub repository webhook to point to `https://<host>/webhooks/github`.
2323

24+
### Module: `github.runner_provider`
25+
26+
Provides the GitHub-owned side of the workflow-compute runner provider boundary.
27+
It mints repository-scoped GitHub Actions runner registration tokens and removes
28+
runners without exposing GitHub API credentials to workflow-compute.
29+
30+
```yaml
31+
modules:
32+
- name: github-runners
33+
type: github.runner_provider
34+
config:
35+
token: "${GITHUB_TOKEN}"
36+
provider_token: "${GITHUB_RUNNER_PROVIDER_TOKEN}"
37+
repositories: ["GoCodeAlone/workflow-compute"]
38+
```
39+
40+
For local proof runs, the repo also builds `github-runner-provider`, a small
41+
HTTP provider service:
42+
43+
```sh
44+
GITHUB_TOKEN=... \
45+
GITHUB_RUNNER_PROVIDER_TOKEN=... \
46+
GITHUB_RUNNER_PROVIDER_REPOSITORIES=GoCodeAlone/workflow-compute \
47+
bin/github-runner-provider 127.0.0.1:8090
48+
```
49+
50+
workflow-compute should point at that service with
51+
`COMPUTE_GITHUB_RUNNER_PROVIDER_URL` and
52+
`COMPUTE_GITHUB_RUNNER_PROVIDER_TOKEN`; it should not receive `GITHUB_TOKEN`.
53+
2454
### Step: `step.gh_action_trigger`
2555

2656
Triggers a GitHub Actions workflow via `workflow_dispatch`.

cmd/github-runner-provider/main.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Command github-runner-provider serves the GitHub-owned runner provider API
2+
// used by workflow-compute without placing GitHub API credentials in compute.
3+
package main
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"log/slog"
9+
"net/http"
10+
"os"
11+
"strings"
12+
"time"
13+
14+
"github.com/GoCodeAlone/workflow-plugin-github/internal"
15+
)
16+
17+
func main() {
18+
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
19+
if err := run(context.Background(), logger, os.Args[1:]); err != nil {
20+
logger.Error("github-runner-provider failed", "error", err)
21+
os.Exit(1)
22+
}
23+
}
24+
25+
func run(ctx context.Context, logger *slog.Logger, args []string) error {
26+
addr := "127.0.0.1:8090"
27+
if len(args) > 0 {
28+
addr = args[0]
29+
}
30+
githubToken := os.Getenv("GITHUB_RUNNER_PROVIDER_GITHUB_TOKEN")
31+
if githubToken == "" {
32+
githubToken = os.Getenv("GITHUB_TOKEN")
33+
}
34+
if githubToken == "" {
35+
return fmt.Errorf("GITHUB_RUNNER_PROVIDER_GITHUB_TOKEN or GITHUB_TOKEN is required")
36+
}
37+
providerToken := os.Getenv("GITHUB_RUNNER_PROVIDER_TOKEN")
38+
if providerToken == "" {
39+
return fmt.Errorf("GITHUB_RUNNER_PROVIDER_TOKEN is required")
40+
}
41+
handler, err := internal.NewGitHubRunnerProviderHTTPHandler("github-runner-provider", map[string]any{
42+
"token": githubToken,
43+
"provider_token": providerToken,
44+
"api_base_url": os.Getenv("GITHUB_API_BASE_URL"),
45+
"repositories": strings.TrimSpace(os.Getenv("GITHUB_RUNNER_PROVIDER_REPOSITORIES")),
46+
})
47+
if err != nil {
48+
return err
49+
}
50+
server := &http.Server{
51+
Addr: addr,
52+
Handler: handler,
53+
ReadHeaderTimeout: 5 * time.Second,
54+
}
55+
logger.InfoContext(ctx, "starting github-runner-provider", "addr", addr)
56+
return server.ListenAndServe()
57+
}

0 commit comments

Comments
 (0)