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

Commit 37e6ed9

Browse files
pdemonacomrodm
authored andcommitted
maint: test code for orgs vs repos
1 parent 51d0ec3 commit 37e6ed9

File tree

1 file changed

+102
-8
lines changed

1 file changed

+102
-8
lines changed

spec/classes/github_actions_runner_spec.rb

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'spec_helper'
2+
require 'deep_merge'
23

34
describe 'github_actions_runner' do
45
on_supported_os.each do |os, os_facts|
@@ -164,16 +165,109 @@
164165
end
165166
end
166167

167-
context 'is expected to create a github_actions_runner installation script' do
168-
it do
168+
context 'installation scripts' do
169+
let(:params) do
170+
super().deep_merge(
171+
'instances' => {
172+
'org_runner' => {
173+
'labels' => ['default'],
174+
},
175+
},
176+
)
177+
end
178+
install_script_content_first_runner = <<~HEREDOC
179+
#!/bin/bash
180+
# Configure the action runner after the package file has been downloaded.
181+
set -e
182+
183+
# Get registration token.
184+
TOKEN=$(curl -s -XPOST -H "authorization: token PAT" \\
185+
https://api.github.com/repos/github_org/test_repo/actions/runners/registration-token | jq -r .token)
186+
187+
# Allow root
188+
export RUNNER_ALLOW_RUNASROOT=true
189+
190+
191+
# (Optional) Remove previous config.
192+
/some_dir/actions-runner-2.272.0/first_runner/config.sh remove \\
193+
--url https://github.com/github_org/test_repo \\
194+
--token ${TOKEN} \\
195+
--name foo-first_runner &>/dev/null
196+
197+
198+
# Configure the runner.
199+
/some_dir/actions-runner-2.272.0/first_runner/config.sh \\
200+
--unattended \\
201+
--replace \\
202+
--name foo-first_runner \\
203+
--url https://github.com/github_org/test_repo \\
204+
--token ${TOKEN} \\
205+
--labels test_label1,test_label2 &>/dev/null
206+
207+
# Copy service endpoint script.
208+
if [ ! -f /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh ]; then
209+
cp /some_dir/actions-runner-2.272.0/first_runner/bin/runsvc.sh /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh
210+
chmod 755 /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh
211+
fi
212+
HEREDOC
213+
install_script_content_org_runner = <<~HEREDOC
214+
#!/bin/bash
215+
# Configure the action runner after the package file has been downloaded.
216+
set -e
217+
218+
# Get registration token.
219+
TOKEN=$(curl -s -XPOST -H "authorization: token PAT" \\
220+
https://api.github.com/orgs/github_org/actions/runners/registration-token | jq -r .token)
221+
222+
# Allow root
223+
export RUNNER_ALLOW_RUNASROOT=true
224+
225+
226+
# (Optional) Remove previous config.
227+
/some_dir/actions-runner-2.272.0/org_runner/config.sh remove \\
228+
--url https://github.com/github_org \\
229+
--token ${TOKEN} \\
230+
--name foo-org_runner &>/dev/null
231+
232+
233+
# Configure the runner.
234+
/some_dir/actions-runner-2.272.0/org_runner/config.sh \\
235+
--unattended \\
236+
--replace \\
237+
--name foo-org_runner \\
238+
--url https://github.com/github_org \\
239+
--token ${TOKEN} \\
240+
--labels default &>/dev/null
241+
242+
# Copy service endpoint script.
243+
if [ ! -f /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh ]; then
244+
cp /some_dir/actions-runner-2.272.0/org_runner/bin/runsvc.sh /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh
245+
chmod 755 /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh
246+
fi
247+
HEREDOC
248+
249+
it 'creates a repo specific runner script' do
169250
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',
251+
'ensure' => 'present',
252+
'owner' => 'root',
253+
'group' => 'root',
254+
'mode' => '0755',
255+
'require' => 'Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
256+
'notify' => 'Exec[first_runner-run_configure_install_runner.sh]',
257+
'content' => install_script_content_first_runner,
258+
)
259+
end
260+
261+
it 'creates an org specific runner script' do
262+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with(
263+
'ensure' => 'present',
264+
'owner' => 'root',
265+
'group' => 'root',
266+
'mode' => '0755',
267+
'require' => 'Archive[org_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
268+
'notify' => 'Exec[org_runner-run_configure_install_runner.sh]',
269+
'content' => install_script_content_org_runner,
174270
)
175-
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]')
176-
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]')
177271
end
178272
end
179273

0 commit comments

Comments
 (0)