3 Commits

Author SHA1 Message Date
Francesco Renzi c974e98471 Add static user agent field (#54) 2026-02-02 16:43:21 +01:00
Jeffrey Luszcz 913a6c443b Merge pull request #49 from actions/Jeffrey-Luszcz-patch-1
Update copyright notice in LICENSE file
2026-02-02 09:06:31 -05:00
Jeffrey Luszcz 256f252d31 Update copyright notice in LICENSE file 2026-01-20 17:52:52 -05:00
5 changed files with 21 additions and 25 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 GitHub
Copyright GitHub, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+3 -5
View File
@@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"
"maps"
"net/http"
"net/url"
@@ -127,9 +126,9 @@ type ProxyFunc func(req *http.Request) (*url.URL, error)
type SystemInfo struct {
// System is the name of the scale set implementation
System string `json:"system"`
// Version is the version of the controller
// Version is the version of the client
Version string `json:"version"`
// CommitSHA is the git commit SHA of the controller
// CommitSHA is the git commit SHA of the client
CommitSHA string `json:"commit_sha"`
// ScaleSetID is the ID of the scale set
ScaleSetID int `json:"scale_set_id"`
@@ -223,6 +222,7 @@ type userAgent struct {
SystemInfo
BuildVersion string `json:"build_version"`
BuildCommitSHA string `json:"build_commit_sha"`
Kind string `json:"kind"`
}
func (c *Client) newGitHubAPIRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error) {
@@ -836,8 +836,6 @@ func (c *Client) getActionsServiceAdminConnection(ctx context.Context, rt *regis
return nil, fmt.Errorf("failed to get actions service admin connection: %w", err)
}
slog.Info("got admin connection", *adminConnection.ActionsServiceURL)
return adminConnection, nil
}
+1
View File
@@ -137,6 +137,7 @@ func (c *commonClient) setUserAgent() {
SystemInfo: c.systemInfo,
BuildVersion: buildInfo.version,
BuildCommitSHA: buildInfo.commitSHA,
Kind: "scaleset",
})
c.userAgent = string(b)
}
+2
View File
@@ -124,6 +124,7 @@ func TestUserAgent(t *testing.T) {
SystemInfo: testSystemInfo,
BuildCommitSHA: sha,
BuildVersion: version,
Kind: "scaleset",
}
b, err := json.Marshal(wantInfo)
require.NoError(t, err, "failed to marshal expected user agent")
@@ -144,6 +145,7 @@ func TestUserAgent(t *testing.T) {
SystemInfo: userAgentInfo,
BuildCommitSHA: sha,
BuildVersion: version,
Kind: "scaleset",
}
b, err = json.Marshal(wantInfo)
require.NoError(t, err, "failed to marshal expected user agent after SetSystemInfo")
+14 -19
View File
@@ -74,40 +74,35 @@ func run(ctx context.Context, c Config) error {
runnerGroupID = runnerGroup.ID
}
slog.Info("creating scale set")
// Create the runner scale set
scaleSet, err := scalesetClient.CreateRunnerScaleSet(ctx, &scaleset.RunnerScaleSet{
Name: c.ScaleSetName,
RunnerGroupID: runnerGroupID,
Labels: []scaleset.Label{},
Labels: c.BuildLabels(),
RunnerSetting: scaleset.RunnerSetting{
DisableUpdate: true,
},
})
if err != nil {
slog.Error("failed to create", err)
return fmt.Errorf("failed to create runner scale set: %w", err)
}
slog.Info("created")
// Set the user agent for the scaleset client now that we have the scale set ID
scalesetClient.SetSystemInfo(systemInfo(scaleSet.ID))
// defer func() {
// logger.Info(
// "Deleting runner scale set",
// slog.Int("scaleSetID", scaleSet.ID),
// )
// if err := scalesetClient.DeleteRunnerScaleSet(context.WithoutCancel(ctx), scaleSet.ID); err != nil {
// slog.Error(
// "Failed to delete runner scale set",
// slog.Int("scaleSetID", scaleSet.ID),
// slog.String("error", err.Error()),
// )
// }
// }()
defer func() {
logger.Info(
"Deleting runner scale set",
slog.Int("scaleSetID", scaleSet.ID),
)
if err := scalesetClient.DeleteRunnerScaleSet(context.WithoutCancel(ctx), scaleSet.ID); err != nil {
slog.Error(
"Failed to delete runner scale set",
slog.Int("scaleSetID", scaleSet.ID),
slog.String("error", err.Error()),
)
}
}()
dockerClient, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithAPIVersionNegotiation())
if err != nil {