-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(maint) add workflow for acceptance testing
- Loading branch information
Showing
7 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# output task execution | ||
unless Rake.application.options.trace | ||
setup = ->(task, *_args) do | ||
puts "\e[36m==> rake #{task}\e[0m" | ||
end | ||
|
||
task :log_hooker do | ||
Rake::Task.tasks.reject { |t| t.to_s == 'log_hooker' }.each do |a_task| | ||
a_task.actions.prepend(setup) | ||
end | ||
end | ||
Rake.application.top_level_tasks.prepend(:log_hooker) | ||
end | ||
|
||
# serial acceptance task | ||
namespace :litmus do | ||
desc "Run tests against all nodes in the litmus inventory\n(defaults: tag=nil)" | ||
task :acceptance, [:tag] do |_task, args| | ||
args.with_defaults(tag: nil) | ||
|
||
Rake::Task.tasks.select { |t| t.to_s =~ %r{^litmus:acceptance:(?!(localhost|parallel)$)} }.each do |litmus_task| | ||
puts "Running task #{litmus_task}" | ||
litmus_task.invoke(*args) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
--- | ||
name: "Acceptance Test" | ||
|
||
inputs: | ||
docker_image: | ||
required: true | ||
type: string | ||
repo: | ||
required: true | ||
type: string | ||
ref: | ||
type: string | ||
provision_task: | ||
required: true | ||
default: "docker" | ||
type: string | ||
provision_module: | ||
description: 'override provision module in .fixtures.yml' | ||
type: string | ||
puppet_agent_module: | ||
description: 'override puppet_agent module in .fixtures.yml' | ||
type: string | ||
ruby_version: | ||
required: true | ||
default: "2.7" | ||
type: string | ||
path: | ||
description: 'working directory (default ${github.workspace}/acceptance_test)' | ||
type: string | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- id: vars | ||
shell: bash | ||
run: | | ||
echo "working-directory=${{ inputs.path != '' && inputs.path || format('{0}/acceptance_test', github.workspace) }}" >> "${GITHUB_OUTPUT}" | ||
- name: Checkout Module (Act) | ||
if: github.actor == 'nektos/act' | ||
shell: bash | ||
run: git clone https://github.com/${{ inputs.repo }} ${{ steps.vars.outputs.working-directory }} | ||
|
||
- name: Checkout Module (Github) | ||
if: github.actor != 'nektos/act' | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ inputs.repo }} | ||
ref: ${{ inputs.ref }} | ||
path: ${{ steps.vars.outputs.working-directory }} | ||
|
||
- name: Setup Ruby | ||
uses: "ruby/setup-ruby@v1" | ||
with: | ||
ruby-version: ${{ inputs.ruby_version }} | ||
bundler-cache: true | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
|
||
- name: Custom fixtures | ||
if: (inputs.provision_module != '' || inputs.puppet_agent_module != '') | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
shell: ruby {0} | ||
run: | | ||
require 'yaml' | ||
require 'json' | ||
input = {} | ||
input['provision'] = <<INPUT | ||
${{ inputs.provision_module }} | ||
INPUT | ||
input['puppet_agent'] = <<INPUT | ||
${{ inputs.puppet_agent_module }} | ||
INPUT | ||
input.transform_values! do |v| | ||
JSON.parse(v) | ||
rescue | ||
v.chomp | ||
end.reject! { |_, v| v.empty? } | ||
project = YAML.load_file('.fixtures.yml') | ||
project['fixtures']['repositories'].merge!(input) | ||
File.write('.fixtures.yml', project.to_yaml) | ||
- name: Prepare | ||
shell: bash | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
run: | | ||
mkdir -p rakelib | ||
cp ${{ github.action_path }}/action.rake rakelib/litmusimage_$$.rake | ||
bundle exec rake spec_prep | ||
- name: Provision | ||
id: provision | ||
shell: bash | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
run: | | ||
bundle exec rake litmus:provision[${{ inputs.provision_task }},${{ inputs.docker_image }}] | ||
bundle exec bolt inventory show --detail -i spec/fixtures/litmus_inventory.yaml | ||
- name: Install Agent | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
shell: bash | ||
run: bundle exec rake litmus:install_agent | ||
|
||
- name: Install Module | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
shell: bash | ||
run: | | ||
bundle exec rake litmus:install_module | ||
bundle exec bolt command run 'puppet module list' -t all -i spec/fixtures/litmus_inventory.yaml | ||
- name: Run | ||
id: run | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
shell: bash | ||
run: bundle exec rake litmus:acceptance | ||
|
||
- name: Cleanup | ||
if: always() | ||
shell: bash | ||
working-directory: ${{ steps.vars.outputs.working-directory }} | ||
run: | | ||
set +e | ||
if [[ "${{ steps.provision.outcome }}" == "success" ]] ; then | ||
if [[ "${{ steps.run.outcome }}" != "success" ]] ; then | ||
bundle exec bolt inventory show --detail -i spec/fixtures/litmus_inventory.yaml | ||
docker ps -a --format '{{.ID}}' | xargs -n1 docker logs | ||
fi | ||
bundle exec rake litmus:tear_down | ||
fi | ||
# ALWAYS exit based on the outcode of the smoke test provision | ||
exit ${{ steps.run.outcome != 'success' && '1' || '0' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ inputs: | |
type: string | ||
ruby_version: | ||
required: true | ||
default: "3.2" | ||
default: "2.7" | ||
type: string | ||
|
||
runs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
name: Test Module | ||
run-name: > | ||
${{ inputs.image && format('image={0}', inputs.image) || '' }} | ||
${{ inputs.repo && format('repo={0}', inputs.repo) || '' }} | ||
${{ inputs.ref && format('ref={0}', inputs.ref) || '' }} | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
image: | ||
required: true | ||
description: Litmus image:tag | ||
type: string | ||
default: "debian:10" | ||
repo: | ||
description: repo of module to acceptance test | ||
type: string | ||
default: "puppetlabs/puppetlabs-stdlib" | ||
ref: | ||
description: module git ref (optional) | ||
type: string | ||
provision_task: | ||
description: provision task | ||
type: choice | ||
default: docker | ||
options: | ||
- docker | ||
- docker_exp | ||
latest_modules: | ||
description: patch module fixtures with latest Puppet Litmus required modules | ||
type: boolean | ||
default: true | ||
provision_module: | ||
description: provision module overrides (JSON Hash) | ||
type: string | ||
puppet_agent_module: | ||
description: puppet_agent module overrides (JSON Hash) | ||
type: string | ||
|
||
env: | ||
REGISTRY: ${{ vars.DOCKER_REGISTRY != '' && vars.DOCKER_REGISTRY || 'ghcr.io' }} | ||
REPOSITORY: ${{ vars.DOCKER_REPOSITORY != '' && vars.DOCKER_REPOSITORY || github.repository }} | ||
BOLT_GEM: 1 | ||
|
||
jobs: | ||
acceptance: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Vars | ||
id: vars | ||
run: | | ||
if [[ "${{ inputs.latest_modules }}" != "false" ]] ; then | ||
echo 'provision_module="https://github.com/puppetlabs/provision.git"' >> "${GITHUB_OUTPUT}" | ||
echo 'puppet_agent_module="https://github.com/puppetlabs/puppetlabs-puppet_agent.git"' >> "${GITHUB_OUTPUT}" | ||
fi | ||
if [[ -n "${{ inputs.provision_module }}" ]] ; then | ||
echo 'provision_module=${{ inputs.provision_module }}' >> "${GITHUB_OUTPUT}" | ||
fi | ||
if [[ -n "${{ inputs.puppet_agent_module }}" ]] ; then | ||
echo 'puppet_agent_module=${{ inputs.puppet_agent_module }}' >> "${GITHUB_OUTPUT}" | ||
fi | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Test | ||
uses: ./.github/actions/acceptance-test | ||
with: | ||
docker_image: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ inputs.image }} | ||
repo: ${{ inputs.repo }} | ||
ref: ${{ inputs.ref }} | ||
provision_task: ${{ inputs.provision_task }} | ||
provision_module: ${{ steps.vars.outputs.provision_module }} | ||
puppet_agent_module: ${{ steps.vars.outputs.puppet_agent_module }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters