Skip to content

Commit fb72e66

Browse files
authored
Merge pull request #70 from myii/ci/add-windows-testing-via-github-actions
ci(windows): test using GitHub Actions
2 parents 79257d5 + d734d43 commit fb72e66

File tree

14 files changed

+393
-9
lines changed

14 files changed

+393
-9
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen Vagrant (Windows)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'
9+
10+
jobs:
11+
test:
12+
runs-on: 'macos-10.15'
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
instance:
17+
- windows-windows-81-latest-py3
18+
steps:
19+
- name: 'Check out code'
20+
uses: 'actions/checkout@v2'
21+
- name: 'Set up Bundler cache'
22+
uses: 'actions/cache@v1'
23+
with:
24+
path: 'vendor/bundle'
25+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
26+
restore-keys: "${{ runner.os }}-gems-"
27+
- name: 'Run Bundler'
28+
run: |
29+
ruby --version
30+
bundle config path vendor/bundle
31+
bundle install --jobs 4 --retry 3
32+
- name: 'Run Test Kitchen'
33+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen (Windows)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
machine_user: kitchen
9+
machine_pass: Pass@word1
10+
machine_port: 5985
11+
KITCHEN_LOCAL_YAML: 'kitchen.windows.yml'
12+
13+
jobs:
14+
test-2019:
15+
runs-on: 'windows-2019'
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
instance:
20+
- windows-windows-2019-latest-py3
21+
steps:
22+
- name: 'Check out code'
23+
uses: 'actions/checkout@v2'
24+
- name: 'Install Chef'
25+
uses: 'actionshub/[email protected]'
26+
with:
27+
project: 'chef'
28+
version: '16.10.8'
29+
- name: 'Add Chef bindir to PATH'
30+
uses: 'myci-actions/export-env-var-powershell@1'
31+
with:
32+
name: 'PATH'
33+
value: "C:\\opscode\\chef\\bin;\
34+
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
35+
- name: 'Set up Bundler cache'
36+
uses: 'actions/cache@v1'
37+
with:
38+
path: 'vendor/bundle'
39+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
40+
restore-keys: "${{ runner.os }}-gems-"
41+
- name: 'Set up test user'
42+
run: |
43+
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
44+
New-LocalUser $env:machine_user -Password $password
45+
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
46+
- name: 'Set up WinRM'
47+
run: >
48+
Set-WSManQuickConfig -Force;
49+
Set-WSManInstance -ResourceURI winrm/config/service
50+
-ValueSet @{AllowUnencrypted="true"}
51+
- name: 'Run Bundler'
52+
run: |
53+
ruby --version
54+
bundle config path vendor/bundle
55+
bundle install --jobs 4 --retry 3
56+
- name: 'Run Test Kitchen'
57+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
58+
test-2016:
59+
runs-on: 'windows-2016'
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
instance:
64+
- windows-windows-2016-latest-py3
65+
steps:
66+
- name: 'Check out code'
67+
uses: 'actions/checkout@v2'
68+
- name: 'Install Chef'
69+
uses: 'actionshub/[email protected]'
70+
with:
71+
project: 'chef'
72+
version: '16.10.8'
73+
- name: 'Add Chef bindir to PATH'
74+
uses: 'myci-actions/export-env-var-powershell@1'
75+
with:
76+
name: 'PATH'
77+
value: "C:\\opscode\\chef\\bin;\
78+
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
79+
- name: 'Set up Bundler cache'
80+
uses: 'actions/cache@v1'
81+
with:
82+
path: 'vendor/bundle'
83+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
84+
restore-keys: "${{ runner.os }}-gems-"
85+
- name: 'Set up test user'
86+
run: |
87+
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
88+
New-LocalUser $env:machine_user -Password $password
89+
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
90+
- name: 'Set up WinRM'
91+
run: >
92+
Set-WSManQuickConfig -Force;
93+
Set-WSManInstance -ResourceURI winrm/config/service
94+
-ValueSet @{AllowUnencrypted="true"}
95+
- name: 'Run Bundler'
96+
run: |
97+
ruby --version
98+
bundle config path vendor/bundle
99+
bundle install --jobs 4 --retry 3
100+
- name: 'Run Test Kitchen'
101+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure
1212
# rubocop:enable Layout/LineLength
1313
gem 'kitchen-inspec', '>= 2.2.1'
1414
gem 'kitchen-salt', '>= 0.6.3'
15+
16+
group :vagrant do
17+
gem 'kitchen-vagrant'
18+
end

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ GEM
292292
kitchen-salt (0.6.3)
293293
hashie (>= 3.5)
294294
test-kitchen (>= 1.4)
295+
kitchen-vagrant (1.7.0)
296+
test-kitchen (>= 1.4, < 3)
295297
libyajl2 (1.2.0)
296298
license-acceptance (1.0.19)
297299
pastel (~> 0.7)
@@ -525,6 +527,7 @@ DEPENDENCIES
525527
kitchen-docker!
526528
kitchen-inspec (>= 2.2.1)
527529
kitchen-salt (>= 0.6.3)
530+
kitchen-vagrant
528531

529532
BUNDLED WITH
530533
2.1.2

docs/README.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ e.g. ``debian-9-2019-2-py3``.
271271
``bin/kitchen converge``
272272
^^^^^^^^^^^^^^^^^^^^^^^^
273273

274-
Creates the docker instance and runs the ``packages`` main state, ready for testing.
274+
Creates the docker instance and runs the ``packages`` main states, ready for testing.
275275

276276
``bin/kitchen verify``
277277
^^^^^^^^^^^^^^^^^^^^^^
@@ -292,3 +292,65 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
292292
^^^^^^^^^^^^^^^^^^^^^
293293

294294
Gives you SSH access to the instance for manual testing.
295+
296+
Testing with Vagrant
297+
--------------------
298+
299+
Windows/FreeBSD/OpenBSD testing is done with ``kitchen-salt``.
300+
301+
Requirements
302+
^^^^^^^^^^^^
303+
304+
* Ruby
305+
* Virtualbox
306+
* Vagrant
307+
308+
Setup
309+
^^^^^
310+
311+
.. code-block:: bash
312+
313+
$ gem install bundler
314+
$ bundle install --with=vagrant
315+
$ bin/kitchen test [platform]
316+
317+
Where ``[platform]`` is the platform name defined in ``kitchen.vagrant.yml``,
318+
e.g. ``windows-81-latest-py3``.
319+
320+
Note
321+
^^^^
322+
323+
When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:
324+
325+
.. code-block:: bash
326+
327+
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
328+
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
329+
$ bin/kitchen test
330+
331+
Then run the following commands as needed.
332+
333+
``bin/kitchen converge``
334+
^^^^^^^^^^^^^^^^^^^^^^^^
335+
336+
Creates the Vagrant instance and runs the ``packages`` main states, ready for testing.
337+
338+
``bin/kitchen verify``
339+
^^^^^^^^^^^^^^^^^^^^^^
340+
341+
Runs the ``inspec`` tests on the actual instance.
342+
343+
``bin/kitchen destroy``
344+
^^^^^^^^^^^^^^^^^^^^^^^
345+
346+
Removes the Vagrant instance.
347+
348+
``bin/kitchen test``
349+
^^^^^^^^^^^^^^^^^^^^
350+
351+
Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.
352+
353+
``bin/kitchen login``
354+
^^^^^^^^^^^^^^^^^^^^^
355+
356+
Gives you RDP/SSH access to the instance for manual testing.

kitchen.vagrant.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: vagrant
6+
cache_directory: false
7+
customize:
8+
usbxhci: 'off'
9+
gui: false
10+
linked_clone: true
11+
ssh:
12+
shell: /bin/sh
13+
14+
platforms:
15+
- name: windows-81-latest-py3
16+
driver:
17+
box: techneg/win81x64-pro-salt
18+
cache_directory: "/omnibus/cache"
19+
customize: {}
20+
ssh: {}
21+
provisioner:
22+
salt_install: none
23+
# yamllint disable rule:line-length
24+
init_environment: |
25+
# Workaround to allow `kitchen converge` to be used multiple times
26+
# without having to `kitchen destroy` first: remove state files cached by
27+
# Salt during the previous `converge` (if present)
28+
rm -recurse `
29+
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
30+
-ErrorAction SilentlyContinue
31+
exit 0
32+
# yamllint enable rule:line-length
33+
34+
provisioner:
35+
salt_install: bootstrap

kitchen.windows.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
driver:
5+
name: proxy
6+
host: localhost
7+
reset_command: "exit 0"
8+
port: 5985
9+
username: kitchen
10+
password: Pass@word1
11+
12+
platforms:
13+
- name: windows-2019-latest-py3
14+
- name: windows-2016-latest-py3
15+
16+
provisioner:
17+
salt_install: bootstrap
18+
salt_bootstrap_options: -pythonVersion 3

kitchen.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,23 @@ suites:
609609
verifier:
610610
inspec_tests:
611611
- path: test/integration/default
612+
- name: windows
613+
includes:
614+
- windows-81-latest-py3
615+
- windows-2019-latest-py3
616+
- windows-2016-latest-py3
617+
provisioner:
618+
state_top:
619+
base:
620+
'*':
621+
- packages.chocolatey
622+
pillars:
623+
top.sls:
624+
base:
625+
'*':
626+
- packages
627+
pillars_from_files:
628+
packages.sls: test/salt/pillar/windows.sls
629+
verifier:
630+
inspec_tests:
631+
- path: test/integration/windows

pillar.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ packages:
6464

6565
chocolatey:
6666
wanted:
67-
firefox:
68-
install_args: "l=fr-FR"
67+
Firefox:
68+
package_args: "/l:en-GB"
6969
packagename:
7070
version: '12.04'
7171
source: 'mychocolatey/source'
7272
force: true
7373
unwanted:
74-
- googlechrome
74+
- GoogleChrome
7575

7676
snaps:
7777
wanted:

test/integration/default/controls/pkgs_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
held_packages = {
2525
# We use this test for held packages in a list,
2626
# with no version (current version).
27-
'iotop': ''
27+
iotop: ''
2828
}
2929
lock_file = '/etc/yum/pluginconf.d/versionlock.list'
3030
when 'fedora'
3131
platform_packages = ['python3-dnf-plugin-versionlock']
3232
held_packages = {
33-
'alien': '8.95-8.fc29',
34-
'iotop': '0.6-18.fc29'
33+
alien: '8.95-8.fc29',
34+
iotop: '0.6-18.fc29'
3535
}
3636
lock_file = '/etc/dnf/plugins/versionlock.list'
3737
# Adding empty Suse entries, to get tests passing
@@ -43,9 +43,9 @@
4343
when 'debian'
4444
platform_packages = %w[]
4545
held_packages = {
46-
'alien': '8.95',
46+
alien: '8.95',
4747
# To match also ubuntu16's
48-
'iotop': '0.6-'
48+
iotop: '0.6-'
4949
}
5050
lock_file = '/var/lib/dpkg/status'
5151
when 'linux'

0 commit comments

Comments
 (0)