Skip to content

Commit 38d7b16

Browse files
Add enterprise list runner applications download (#2496)
Fixes: #2495 .
1 parent 3344412 commit 38d7b16

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

github/enterprise_actions_runners.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ import (
1010
"fmt"
1111
)
1212

13+
// ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
14+
//
15+
// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#list-runner-applications-for-an-enterprise
16+
func (s *EnterpriseService) ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*RunnerApplicationDownload, *Response, error) {
17+
u := fmt.Sprintf("enterprises/%v/actions/runners/downloads", enterprise)
18+
req, err := s.client.NewRequest("GET", u, nil)
19+
if err != nil {
20+
return nil, nil, err
21+
}
22+
23+
var rads []*RunnerApplicationDownload
24+
resp, err := s.client.Do(ctx, req, &rads)
25+
if err != nil {
26+
return nil, resp, err
27+
}
28+
29+
return rads, resp, nil
30+
}
31+
1332
// CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
1433
//
1534
// GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-enterprise

github/enterprise_actions_runners_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,44 @@ func TestEnterpriseService_RemoveRunner(t *testing.T) {
119119
return client.Enterprise.RemoveRunner(ctx, "o", 21)
120120
})
121121
}
122+
123+
func TestEnterpriseService_ListRunnerApplicationDownloads(t *testing.T) {
124+
client, mux, _, teardown := setup()
125+
defer teardown()
126+
127+
mux.HandleFunc("/enterprises/o/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) {
128+
testMethod(t, r, "GET")
129+
fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`)
130+
})
131+
132+
ctx := context.Background()
133+
downloads, _, err := client.Enterprise.ListRunnerApplicationDownloads(ctx, "o")
134+
if err != nil {
135+
t.Errorf("Enterprise.ListRunnerApplicationDownloads returned error: %v", err)
136+
}
137+
138+
want := []*RunnerApplicationDownload{
139+
{OS: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")},
140+
{OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")},
141+
{OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")},
142+
{OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")},
143+
{OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm64-2.164.0.tar.gz")},
144+
}
145+
if !cmp.Equal(downloads, want) {
146+
t.Errorf("Enterprise.ListRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
147+
}
148+
149+
const methodName = "ListRunnerApplicationDownloads"
150+
testBadOptions(t, methodName, func() (err error) {
151+
_, _, err = client.Enterprise.ListRunnerApplicationDownloads(ctx, "\n")
152+
return err
153+
})
154+
155+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
156+
got, resp, err := client.Enterprise.ListRunnerApplicationDownloads(ctx, "o")
157+
if got != nil {
158+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
159+
}
160+
return resp, err
161+
})
162+
}

0 commit comments

Comments
 (0)