Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 913874c

Browse files
TingluoHuangunpollito
authored andcommitted
Trim slash for configure URL. (actions#2381)
1 parent 7e8407a commit 913874c

4 files changed

Lines changed: 73 additions & 4 deletions

File tree

charts/gha-runner-scale-set/templates/autoscalingrunnerset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
labels:
1313
{{- include "gha-runner-scale-set.labels" . | nindent 4 }}
1414
spec:
15-
githubConfigUrl: {{ required ".Values.githubConfigUrl is required" .Values.githubConfigUrl }}
15+
githubConfigUrl: {{ required ".Values.githubConfigUrl is required" (trimSuffix "/" .Values.githubConfigUrl) }}
1616
githubConfigSecret: {{ include "gha-runner-scale-set.githubsecret" . }}
1717
{{- with .Values.runnerGroup }}
1818
runnerGroup: {{ . }}

charts/gha-runner-scale-set/tests/template_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,3 +869,31 @@ func TestTemplateNamingConstraints(t *testing.T) {
869869
})
870870
}
871871
}
872+
873+
func TestTemplateRenderedGitHubConfigUrlEndsWIthSlash(t *testing.T) {
874+
t.Parallel()
875+
876+
// Path to the helm chart we will test
877+
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set")
878+
require.NoError(t, err)
879+
880+
releaseName := "test-runners"
881+
namespaceName := "test-" + strings.ToLower(random.UniqueId())
882+
883+
options := &helm.Options{
884+
SetValues: map[string]string{
885+
"githubConfigUrl": "https://github.com/actions/",
886+
"githubConfigSecret.github_token": "gh_token12345",
887+
},
888+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
889+
}
890+
891+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnerset.yaml"})
892+
893+
var ars v1alpha1.AutoscalingRunnerSet
894+
helm.UnmarshalK8SYaml(t, output, &ars)
895+
896+
assert.Equal(t, namespaceName, ars.Namespace)
897+
assert.Equal(t, "test-runners", ars.Name)
898+
assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl)
899+
}

github/actions/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type GitHubConfig struct {
2929
}
3030

3131
func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
32-
u, err := url.Parse(in)
32+
u, err := url.Parse(strings.Trim(in, "/"))
3333
if err != nil {
3434
return nil, err
3535
}
@@ -45,7 +45,7 @@ func ParseGitHubConfigFromURL(in string) (*GitHubConfig, error) {
4545

4646
invalidURLError := fmt.Errorf("%q: %w", u.String(), ErrInvalidGitHubConfigURL)
4747

48-
pathParts := strings.Split(strings.TrimPrefix(u.Path, "/"), "/")
48+
pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")
4949

5050
switch len(pathParts) {
5151
case 1: // Organization

github/actions/config_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package actions_test
33
import (
44
"errors"
55
"net/url"
6+
"strings"
67
"testing"
78

89
"github.com/actions/actions-runner-controller/github/actions"
@@ -26,6 +27,16 @@ func TestGitHubConfig(t *testing.T) {
2627
IsHosted: true,
2728
},
2829
},
30+
{
31+
configURL: "https://github.com/org/repo/",
32+
expected: &actions.GitHubConfig{
33+
Scope: actions.GitHubScopeRepository,
34+
Enterprise: "",
35+
Organization: "org",
36+
Repository: "repo",
37+
IsHosted: true,
38+
},
39+
},
2940
{
3041
configURL: "https://github.com/org",
3142
expected: &actions.GitHubConfig{
@@ -46,6 +57,16 @@ func TestGitHubConfig(t *testing.T) {
4657
IsHosted: true,
4758
},
4859
},
60+
{
61+
configURL: "https://github.com/enterprises/my-enterprise/",
62+
expected: &actions.GitHubConfig{
63+
Scope: actions.GitHubScopeEnterprise,
64+
Enterprise: "my-enterprise",
65+
Organization: "",
66+
Repository: "",
67+
IsHosted: true,
68+
},
69+
},
4970
{
5071
configURL: "https://www.github.com/org",
5172
expected: &actions.GitHubConfig{
@@ -56,6 +77,16 @@ func TestGitHubConfig(t *testing.T) {
5677
IsHosted: true,
5778
},
5879
},
80+
{
81+
configURL: "https://www.github.com/org/",
82+
expected: &actions.GitHubConfig{
83+
Scope: actions.GitHubScopeOrganization,
84+
Enterprise: "",
85+
Organization: "org",
86+
Repository: "",
87+
IsHosted: true,
88+
},
89+
},
5990
{
6091
configURL: "https://github.localhost/org",
6192
expected: &actions.GitHubConfig{
@@ -76,11 +107,21 @@ func TestGitHubConfig(t *testing.T) {
76107
IsHosted: false,
77108
},
78109
},
110+
{
111+
configURL: "https://my-ghes.com/org/",
112+
expected: &actions.GitHubConfig{
113+
Scope: actions.GitHubScopeOrganization,
114+
Enterprise: "",
115+
Organization: "org",
116+
Repository: "",
117+
IsHosted: false,
118+
},
119+
},
79120
}
80121

81122
for _, test := range tests {
82123
t.Run(test.configURL, func(t *testing.T) {
83-
parsedURL, err := url.Parse(test.configURL)
124+
parsedURL, err := url.Parse(strings.Trim(test.configURL, "/"))
84125
require.NoError(t, err)
85126
test.expected.ConfigURL = parsedURL
86127

0 commit comments

Comments
 (0)