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