Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 7dbaf16

Browse files
authored
Merge pull request #32 from Telefonica/mrodm-pdemonaco_fix_org-api-url-calculation
fix: default org only token url (Cont. from #26)
2 parents 9c78ab9 + 1be751c commit 7dbaf16

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

manifests/instance.pp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@
7171
$token_url = "${github_api}/repos/${org_name}/${repo_name}/actions/runners/registration-token"
7272
$url = "${github_domain}/${org_name}/${repo_name}"
7373
} else {
74-
$token_url = $github_api ? {
75-
'https://api.github.com' => "${github_api}/repos/${org_name}/actions/runners/registration-token",
76-
default => "${github_api}/orgs/${org_name}/actions/runners/registration-token",
77-
}
74+
$token_url = "${github_api}/orgs/${org_name}/actions/runners/registration-token"
7875
$url = "${github_domain}/${org_name}"
7976
}
8077
} elsif $enterprise_name {

spec/classes/github_actions_runner_spec.rb

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,78 @@
164164
end
165165
end
166166

167-
context 'is expected to create a github_actions_runner installation script' do
168-
it do
167+
context 'installation scripts for different types of runners' do
168+
let(:params) do
169+
super().merge(
170+
'org_name' => :undef,
171+
'enterprise_name' => :undef,
172+
'instances' => {
173+
'first_runner' => {
174+
'org_name' => 'github_org',
175+
'repo_name' => 'test_repo',
176+
},
177+
'org_runner' => {
178+
'org_name' => 'github_org',
179+
'labels' => ['default'],
180+
},
181+
'enterprise_runner' => {
182+
'org_name' => :undef,
183+
'enterprise_name' => 'test_enterprise',
184+
'labels' => ['default'],
185+
},
186+
},
187+
)
188+
end
189+
190+
it 'creates a repo specific runner script' do
169191
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with(
170-
'ensure' => 'present',
171-
'owner' => 'root',
172-
'group' => 'root',
173-
'mode' => '0755',
192+
'ensure' => 'present',
193+
'owner' => 'root',
194+
'group' => 'root',
195+
'mode' => '0755',
196+
)
197+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(
198+
%r{https://api.github.com/repos/github_org/test_repo/actions/runners/registration-token},
174199
)
200+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/github_org/test_repo })
201+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--name foo-first_runner })
175202
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').that_requires('Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]')
176203
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').that_notifies('Exec[first_runner-run_configure_install_runner.sh]')
177204
end
205+
206+
it 'creates an org specific runner script' do
207+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with(
208+
'ensure' => 'present',
209+
'owner' => 'root',
210+
'group' => 'root',
211+
'mode' => '0755',
212+
)
213+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(
214+
%r{https://api.github.com/orgs/github_org/actions/runners/registration-token},
215+
)
216+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/github_org })
217+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(%r{--name foo-org_runner })
218+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').that_requires('Archive[org_runner-actions-runner-linux-x64-2.272.0.tar.gz]')
219+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').that_notifies('Exec[org_runner-run_configure_install_runner.sh]')
220+
end
221+
222+
it 'creates an enterprise specific runner script' do
223+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with(
224+
'ensure' => 'present',
225+
'owner' => 'root',
226+
'group' => 'root',
227+
'mode' => '0755',
228+
)
229+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(
230+
%r{https://api.github.com/enterprises/test_enterprise/actions/runners/registration-token},
231+
)
232+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/enterprises/test_enterprise })
233+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(%r{--name foo-enterprise_runner })
234+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').that_requires(
235+
'Archive[enterprise_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
236+
)
237+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').that_notifies('Exec[enterprise_runner-run_configure_install_runner.sh]')
238+
end
178239
end
179240

180241
context 'is expected to create a github_actions_runner installation script with test version' do
@@ -234,6 +295,8 @@
234295

235296
it do
236297
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{https://github.com/enterprises/test_enterprise})
298+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/enterprises/test_enterprise })
299+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--name foo-first_runner })
237300
end
238301
end
239302

0 commit comments

Comments
 (0)