Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
labels:
{{- include "gha-runner-scale-set.labels" . | nindent 4 }}
spec:
githubConfigUrl: {{ required ".Values.githubConfigUrl is required" .Values.githubConfigUrl }}
githubConfigUrl: {{ required ".Values.githubConfigUrl is required" (trimSuffix "/" .Values.githubConfigUrl) }}
githubConfigSecret: {{ include "gha-runner-scale-set.githubsecret" . }}
{{- with .Values.runnerGroup }}
runnerGroup: {{ . }}
Expand Down
28 changes: 28 additions & 0 deletions charts/gha-runner-scale-set/tests/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,31 @@ func TestTemplateNamingConstraints(t *testing.T) {
})
}
}

func TestTemplateRenderedGitHubConfigUrlEndsWIthSlash(t *testing.T) {
t.Parallel()

// Path to the helm chart we will test
helmChartPath, err := filepath.Abs("../../gha-runner-scale-set")
require.NoError(t, err)

releaseName := "test-runners"
namespaceName := "test-" + strings.ToLower(random.UniqueId())

options := &helm.Options{
SetValues: map[string]string{
"githubConfigUrl": "https://github.com/actions/",
"githubConfigSecret.github_token": "gh_token12345",
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
}

output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/autoscalingrunnerset.yaml"})

var ars v1alpha1.AutoscalingRunnerSet
helm.UnmarshalK8SYaml(t, output, &ars)

assert.Equal(t, namespaceName, ars.Namespace)
assert.Equal(t, "test-runners", ars.Name)
assert.Equal(t, "https://github.com/actions", ars.Spec.GitHubConfigUrl)
}
4 changes: 2 additions & 2 deletions github/actions/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type GitHubConfig struct {
}

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

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

pathParts := strings.Split(strings.TrimPrefix(u.Path, "/"), "/")
pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")

switch len(pathParts) {
case 1: // Organization
Expand Down
43 changes: 42 additions & 1 deletion github/actions/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions_test
import (
"errors"
"net/url"
"strings"
"testing"

"github.com/actions/actions-runner-controller/github/actions"
Expand All @@ -26,6 +27,16 @@ func TestGitHubConfig(t *testing.T) {
IsHosted: true,
},
},
{
configURL: "https://github.com/org/repo/",
expected: &actions.GitHubConfig{
Scope: actions.GitHubScopeRepository,
Enterprise: "",
Organization: "org",
Repository: "repo",
IsHosted: true,
},
},
{
configURL: "https://github.com/org",
expected: &actions.GitHubConfig{
Expand All @@ -46,6 +57,16 @@ func TestGitHubConfig(t *testing.T) {
IsHosted: true,
},
},
{
configURL: "https://github.com/enterprises/my-enterprise/",
expected: &actions.GitHubConfig{
Scope: actions.GitHubScopeEnterprise,
Enterprise: "my-enterprise",
Organization: "",
Repository: "",
IsHosted: true,
},
},
{
configURL: "https://www.github.com/org",
expected: &actions.GitHubConfig{
Expand All @@ -56,6 +77,16 @@ func TestGitHubConfig(t *testing.T) {
IsHosted: true,
},
},
{
configURL: "https://www.github.com/org/",
expected: &actions.GitHubConfig{
Scope: actions.GitHubScopeOrganization,
Enterprise: "",
Organization: "org",
Repository: "",
IsHosted: true,
},
},
{
configURL: "https://github.localhost/org",
expected: &actions.GitHubConfig{
Expand All @@ -76,11 +107,21 @@ func TestGitHubConfig(t *testing.T) {
IsHosted: false,
},
},
{
configURL: "https://my-ghes.com/org/",
expected: &actions.GitHubConfig{
Scope: actions.GitHubScopeOrganization,
Enterprise: "",
Organization: "org",
Repository: "",
IsHosted: false,
},
},
}

for _, test := range tests {
t.Run(test.configURL, func(t *testing.T) {
parsedURL, err := url.Parse(test.configURL)
parsedURL, err := url.Parse(strings.Trim(test.configURL, "/"))
require.NoError(t, err)
test.expected.ConfigURL = parsedURL

Expand Down