Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vagrant+proxy): add testing via. GitHub Actions #304

Merged
merged 6 commits into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .yamllint
Expand Up @@ -27,7 +27,11 @@ ignore: |
ssf/files/default/.yamllint
ssf/files/default/inspec/inspec.yml
ssf/files/default/kitchen.yml
ssf/files/default/kitchen.vagrant.yml
ssf/files/default/kitchen.windows.yml
ssf/files/default/.github/workflows/kitchen.yml
ssf/files/default/.github/workflows/kitchen.vagrant.yml
ssf/files/default/.github/workflows/kitchen.windows.yml
ssf/files/tofs_arvados-formula/.travis.yml
ssf/files/tofs_ssf-formula/.yamllint

Expand Down
14 changes: 13 additions & 1 deletion ssf/config/formulas.sls
Expand Up @@ -13,6 +13,9 @@
{#- Use shorter variables to make the code a little easier to follow #}
{%- set context = semrel_formula_specs.context %}
{%- set inspec_suites_kitchen = context.inspec_suites_kitchen %}
{%- set testing_freebsd = context.testing_freebsd %}
{%- set testing_openbsd = context.testing_openbsd %}
{%- set testing_windows = context.testing_windows %}
{%- set use_cirrus_ci = context.use_cirrus_ci %}
{%- set use_github_actions = context.use_github_actions %}
{%- set use_libsaltcli = context.use_libsaltcli %}
Expand Down Expand Up @@ -114,12 +117,16 @@ prepare-git-branch-for-{{ formula }}:
{#- Likewise, if running the state for TOFS files when `use_tofs` is `False` #}
{#- Also remove the local `CONTRIBUTING` file to use the org-level file instead #}
{#- Furthermore, remove `.travis.yml` for the `ssf-formula` #}
{#- Also: remove both `kitchen.vagrant.yml` files if relevant testing not active #}
{#- Also: remove both `kitchen.windows.yml` files if relevant testing not active #}
{%- if (semrel_file == '.cirrus.yml' and not use_cirrus_ci) or
(semrel_file == '.github/workflows/kitchen.yml' and not use_github_actions) or
(semrel_file == 'formula/libsaltcli.jinja' and not use_libsaltcli) or
(semrel_file in ['docs/TOFS_pattern.rst', 'formula/libtofs.jinja'] and not use_tofs) or
(semrel_file in ['docs/CONTRIBUTING.rst'] and formula not in ['.github', 'ssf-formula']) or
(semrel_file in ['.travis.yml'] and formula in ['ssf-formula'])
(semrel_file in ['.travis.yml'] and formula in ['ssf-formula']) or
(semrel_file.endswith('kitchen.vagrant.yml') and not testing_freebsd.active and not testing_openbsd.active and not testing_windows.active) or
(semrel_file.endswith('kitchen.windows.yml') and not testing_windows.active)
%}
{%- set add_or_rm = ['rm', 'remove', 'absent'] %}
{%- endif %}
Expand Down Expand Up @@ -173,15 +180,20 @@ remove-previous-file-location-for-{{ formula }}-{{ dest_file }}:
platforms: {{ context.platforms | yaml }}
platforms_matrix: {{ context.platforms_matrix | yaml }}
platforms_matrix_commented_includes: {{ context.platforms_matrix_commented_includes | yaml }}
proxyplatformswindows: {{ ssf.proxyplatformswindows | yaml }}
rubocop: {{ context.rubocop | yaml }}
salt_lint: {{ context.salt_lint | yaml }}
saltimages: {{ ssf.saltimages | yaml }}
script_kitchen: {{ context.script_kitchen | yaml }}
shellcheck: {{ context.shellcheck | yaml }}
suite: {{ suite | yaml }}
testing_freebsd: {{ testing_freebsd | yaml }}
testing_openbsd: {{ testing_openbsd | yaml }}
testing_windows: {{ testing_windows | yaml }}
travis: {{ context.travis | yaml }}
use_cirrus_ci: {{ use_cirrus_ci }}
use_github_actions: {{ use_github_actions }}
vagrantboxes: {{ ssf.vagrantboxes | yaml }}
yamllint: {{ context.yamllint | yaml }}
{%- endif %}
{%- if ssf.git.states.prepare.active %}
Expand Down
49 changes: 47 additions & 2 deletions ssf/defaults.yaml
Expand Up @@ -62,8 +62,8 @@ ssf_node_anchors:
# An alternative method could be to use:
# `git describe --abbrev=0 --tags`
# yamllint disable rule:line-length rule:quoted-strings
title: "test: standardise use of '`'share'`' suite & '`'_mapdata'`' state [skip ci]"
body: '* Automated using https://github.com/myii/ssf-formula/pull/302'
title: "ci: enable Vagrant-based testing using GitHub Actions"
body: '* Semi-automated using https://github.com/myii/ssf-formula/pull/304'
# yamllint enable rule:line-length rule:quoted-strings
github:
owner: 'saltstack-formulas'
Expand Down Expand Up @@ -185,6 +185,36 @@ ssf_node_anchors:
post: []
shellcheck:
exclude_paths: []
testing_freebsd:
active: false
testing_openbsd:
active: false
vagrant:
platforms:
driver:
ssh:
shell: '/bin/ksh'
testing_windows:
active: false
github:
driver:
name: 'proxy'
host: 'localhost'
reset_command: '"exit 0"'
port: '5985'
username: 'kitchen'
password: 'Pass@word1'
platforms:
provisioner:
salt_install: 'bootstrap'
salt_bootstrap_options: '-pythonVersion 3'
vagrant:
platforms:
driver:
box: 'techneg/win81x64-pro-salt'
gui: 'false'
linked_clone: 'true'
winrepo_ng: []
travis:
addons: {}
dist: 'bionic'
Expand Down Expand Up @@ -275,6 +305,18 @@ ssf:
create_PR:
active: false
source: 'salt://ssf/files/default/git/git_30_create_PR.sh'
proxyplatformswindows:
### `windows`
- [windows , 2019 , latest, 3] # wind-2019-latest-py3
- [windows , 2016 , latest, 3] # wind-2016-latest-py3
vagrantboxes:
### `freebsd`
- [freebsd , 12.2 , latest, 3] # fbsd-12.2-latest-py3
- [freebsd , 11.4 , latest, 3] # fbsd-11.4-latest-py3
### `openbsd`
- [openbsd , 6.8 , latest, 3] # obsd-06.8-latest-py3
### `windows`
- [windows , 8.1 , latest, 3] # wind-08.1-latest-py3
saltimages:
### `tiamat-py3`
- [debian , 10 , tiamat, 3] # debi-10.0-tiamat-py3
Expand Down Expand Up @@ -986,6 +1028,9 @@ ssf:
9:
<<: *isk_suite_default
name: 'gentoo'
10:
<<: *isk_suite_default
name: 'windows'
php:
<<: *formula_default
context:
Expand Down
54 changes: 54 additions & 0 deletions ssf/files/default/.github/workflows/kitchen.vagrant.yml
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
{%- from tplroot ~ "/libcimatrix.jinja" import format_ci_matrix with context %}

{#- Concatenate active platforms #}
{%- set active_platforms = [] %}
{%- if testing_freebsd.active %}
{%- do active_platforms.append("FreeBSD") %}
{%- endif %}
{%- if testing_openbsd.active %}
{%- do active_platforms.append("OpenBSD") %}
{%- endif %}
{%- if testing_windows.active %}
{%- do active_platforms.append("Windows") %}
{%- endif %}
{#- https://stackoverflow.com/questions/30083949/how-to-join-list-in-python-but-make-the-last-separator-different/30084022 #}
{%- if active_platforms | length == 1 %}
{%- set active_platforms_concat = active_platforms[0] %}
{%- else %}
{%- set active_platforms_concat = " & ".join([", ".join(active_platforms[:-1]), active_platforms[-1]]) %}
{%- endif %}
name: '{{ "Kitchen Vagrant ({})".format(active_platforms_concat) }}'
'on': ['push', 'pull_request']

env:
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'

jobs:
test:
runs-on: 'macos-10.15'
strategy:
fail-fast: false
matrix:
instance:
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=10, use_github_format=True, use_vagrant_platforms=True) }}
{%- raw %}
steps:
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
{%- endraw %}
66 changes: 66 additions & 0 deletions ssf/files/default/.github/workflows/kitchen.windows.yml
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
{%- from tplroot ~ "/libcimatrix.jinja" import format_ci_matrix with context %}
name: 'Kitchen (Windows)'
'on': ['push', 'pull_request']

env:
machine_user: {{ testing_windows.github.driver.username }}
machine_pass: {{ testing_windows.github.driver.password }}
machine_port: {{ testing_windows.github.driver.port }}
KITCHEN_LOCAL_YAML: 'kitchen.windows.yml'

jobs:
{%- for platform in proxyplatformswindows %}
{#- set os = platform[0] | d('') #}
{%- set os_ver = platform[1] | d('') %}
{#- set salt_ver = platform[2] | d('') #}
{#- set py_ver = platform[3] | d('') #}
test-{{ os_ver }}:
runs-on: 'windows-{{ os_ver }}'
strategy:
fail-fast: false
matrix:
instance:
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=10, use_github_format=True, use_proxy_platforms_windows=platform) }}
{%- raw %}
steps:
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Install Chef'
uses: 'actionshub/chef-install@1.1.0'
with:
project: 'chef'
version: '16.10.8'
- name: 'Add Chef bindir to PATH'
uses: 'myci-actions/export-env-var-powershell@1'
with:
name: 'PATH'
value: "C:\\opscode\\chef\\bin;\
C:\\opscode\\chef\\embedded\\bin;$env:PATH"
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Set up test user'
run: |
$password = ConvertTo-SecureString $env:machine_pass -AsPlainText -Force
New-LocalUser $env:machine_user -Password $password
Add-LocalGroupMember -Group "Administrators" -Member $env:machine_user
- name: 'Set up WinRM'
run: >
Set-WSManQuickConfig -Force;
Set-WSManInstance -ResourceURI winrm/config/service
-ValueSet @{AllowUnencrypted="true"}
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
run: 'bundle exec kitchen verify ${{ matrix.instance }}'
{%- endraw %}
{%- endfor %}
10 changes: 6 additions & 4 deletions ssf/files/default/.github/workflows/kitchen.yml
Expand Up @@ -23,12 +23,13 @@ jobs:
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=10, use_github_format=True) }}
{%- raw %}
steps:
- uses: 'actions/checkout@v2'
- uses: 'actions/cache@v1'
- name: 'Check out code'
uses: 'actions/checkout@v2'
- name: 'Set up Bundler cache'
uses: 'actions/cache@v1'
with:
path: 'vendor/bundle'
key: |
${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
restore-keys: "${{ runner.os }}-gems-"
- name: 'Install Bundler'
run: |
Expand All @@ -37,6 +38,7 @@ jobs:
--quiet --no-document
- name: 'Run Bundler'
run: |
ruby --version
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: 'Run Test Kitchen'
Expand Down
2 changes: 1 addition & 1 deletion ssf/files/default/Gemfile
Expand Up @@ -12,7 +12,7 @@ gem 'kitchen-docker', git: 'https://gitlab.com/saltstack-formulas/infrastructure
# rubocop:enable Layout/LineLength
gem 'kitchen-inspec', '>= 2.2.1'
gem 'kitchen-salt', '>= 0.6.3'
{%- if semrel_formula in ['openssh', 'openvpn', 'postgres', 'salt'] %}
{%- if semrel_formula in ['openssh', 'openvpn', 'packages', 'postgres', 'salt'] %}
{%- if semrel_formula in ['openvpn'] %}
gem 'rspec-retry'
{%- endif %}
Expand Down
63 changes: 63 additions & 0 deletions ssf/files/default/kitchen.vagrant.yml
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
driver:
name: vagrant
cache_directory: false
customize:
usbxhci: 'off'
gui: false
linked_clone: true
ssh:
shell: /bin/sh

platforms:
{%- for platform in vagrantboxes %}
{%- set os = platform[0] | d('') %}
{%- set os_ver = platform[1] | d('') %}
{%- set salt_ver = platform[2] | d('') %}
{%- set py_ver = platform[3] | d('') %}
{#- Go to the next platform where not set as active #}
{%- if (os == 'freebsd' and not testing_freebsd.active) or
(os == 'openbsd' and not testing_openbsd.active) or
(os == 'windows' and not testing_windows.active) %}
{%- continue %}
{%- endif %}
- name: {{ os | replace('/', '-') }}-{{ os_ver | replace('.', '') }}-{{ salt_ver | replace('.', '-') }}-py{{ py_ver }}
driver:
{%- if os == 'freebsd' %}
box: {{ 'bento/{}-{}'.format(os, os_ver) }}
{%- elif os == 'openbsd' %}
box: {{ 'generic/{}{}'.format(os, os_ver | int) }}
ssh:
{{ testing_openbsd.vagrant.platforms.driver.ssh | yaml(False) | indent(8) }}
{%- elif os == 'windows' %}
box: {{ testing_windows.vagrant.platforms.driver.box }}
cache_directory: "/omnibus/cache"
customize: {}
ssh: {}
{%- endif %}
{%- if os == 'windows' %}
provisioner:
salt_install: none
# yamllint disable rule:line-length
init_environment: |
# Workaround to allow `kitchen converge` to be used multiple times
# without having to `kitchen destroy` first: remove state files cached by
# Salt during the previous `converge` (if present)
rm -recurse `
C:\Users\vagrant\AppData\Local\Temp\kitchen\var\cache\salt\minion\files\base `
-ErrorAction SilentlyContinue
{%- for pkg in testing_windows.winrepo_ng %}
salt-call --local state.single file.managed `
C:\Users\vagrant\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\{{ pkg }}.sls `
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/{{ pkg }}.sls `
skip_verify=True makedirs=True
{%- endfor %}
exit 0
# yamllint enable rule:line-length
{%- endif %}
{%- endfor %}

provisioner:
salt_install: bootstrap
35 changes: 35 additions & 0 deletions ssf/files/default/kitchen.windows.yml
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
driver:
name: {{ testing_windows.github.driver.name }}
host: {{ testing_windows.github.driver.host }}
reset_command: {{ testing_windows.github.driver.reset_command }}
port: {{ testing_windows.github.driver.port }}
username: {{ testing_windows.github.driver.username }}
password: {{ testing_windows.github.driver.password }}

platforms:
{%- for platform in proxyplatformswindows %}
{%- set os = platform[0] | d('') %}
{%- set os_ver = platform[1] | d('') %}
{%- set salt_ver = platform[2] | d('') %}
{%- set py_ver = platform[3] | d('') %}
- name: {{ os | replace('/', '-') }}-{{ os_ver | replace('.', '') }}-{{ salt_ver | replace('.', '-') }}-py{{ py_ver }}
{%- endfor %}

provisioner:
salt_install: {{ testing_windows.github.platforms.provisioner.salt_install }}
salt_bootstrap_options: {{ testing_windows.github.platforms.provisioner.salt_bootstrap_options }}
{#- This template needs this `if` block since `init_environment` may not be needed at all #}
{%- if testing_windows.winrepo_ng %}
# yamllint disable rule:line-length
init_environment: |
{%- for pkg in testing_windows.winrepo_ng %}
C:\salt\salt-call --local state.single file.managed `
C:\Users\kitchen\AppData\Local\Temp\kitchen\srv\salt\win\repo-ng\{{ pkg }}.sls `
source=https://github.com/saltstack/salt-winrepo-ng/raw/master/{{ pkg }}.sls `
skip_verify=True makedirs=True
{%- endfor %}
# yamllint enable rule:line-length
{%- endif %}