Skip to content

Commit 263a2f0

Browse files
committed
support input
1 parent bc16e7d commit 263a2f0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ inputs:
77
headers:
88
description: "Headers to configure gRPC metadata"
99
required: false
10+
repo-token:
11+
description: 'The GITHUB_TOKEN secret'
12+
required: false
1013
runs:
1114
using: "docker"
1215
image: "Dockerfile"
1316
env:
1417
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ inputs.endpoint }}
1518
OTEL_EXPORTER_OTLP_HEADERS: ${{ inputs.headers }}
19+
GITHUB_TOKEN: ${{ inputs.repo-token }}

main.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ type actionConfig struct {
3636

3737
func getSteps(ctx context.Context, conf actionConfig) error {
3838
tracer := otel.Tracer(conf.githubRepository)
39+
client := github.NewClient(nil)
40+
3941
// login using the GITHUB_TOKEN coming from the jobs
4042
// as per https://docs.github.com/en/actions/security-guides/automatic-token-authentication
4143
githubToken, ok := os.LookupEnv("GITHUB_TOKEN")
42-
if !ok {
43-
return errors.New("missing variable: GITHUB_TOKEN")
44+
if ok {
45+
ts := oauth2.StaticTokenSource(
46+
&oauth2.Token{AccessToken: githubToken},
47+
)
48+
tc := oauth2.NewClient(ctx, ts)
49+
client = github.NewClient(tc)
4450
}
45-
ts := oauth2.StaticTokenSource(
46-
&oauth2.Token{AccessToken: githubToken},
47-
)
48-
tc := oauth2.NewClient(ctx, ts)
49-
client := github.NewClient(tc)
51+
5052
id, err := strconv.ParseInt(conf.runID, 10, 64)
5153
if err != nil {
5254
return err

0 commit comments

Comments
 (0)