Skip to content

Commit

Permalink
(maint) move smoke test steps to composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed Apr 30, 2024
1 parent f383d74 commit f4c30c4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 64 deletions.
88 changes: 88 additions & 0 deletions .github/actions/smoke-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: "Smoke Test"

inputs:
docker_image:
required: true
type: string
provision_task:
required: true
default: "docker"
type: string
provision_module:
type: string
working_directory:
required: true
default: "tests/smoke"
type: string
ruby_version:
required: true
default: "3.2"
type: string

runs:
using: "composite"
steps:
- name: Setup Ruby
uses: "ruby/setup-ruby@v1"
with:
ruby-version: ${{ inputs.ruby_version }}
bundler-cache: true
working-directory: ${{ inputs.working_directory }}

- name: Custom provision module
if: inputs.provision_module != ''
working-directory: tests/smoke
shell: ruby
run: |
require 'yaml'
require 'json'
input = <<INPUT
${{ inputs.provision_module }}
INPUT
override = JSON.parse(input)
project = YAML.safe_load_file('bolt-project.yaml')
project["modules"].each_with_index do |mod, i|
project["modules"][i].merge!(override) if mod["name"].eql?('puppetlabs/provision')
end
File.write('bolt-project.yaml', project.to_yaml)
- name: Prepare
shell: bash
working-directory: ${{ inputs.working_directory }}
run: |
bundle info puppet_litmus
bundle exec bolt module install
bundle exec bolt module show
- name: Provision ${{ inputs.docker_image }}
shell: bash
working-directory: ${{ inputs.working_directory }}
run: bundle exec rake litmus:provision[${{ inputs.provision_task }},${{ inputs.docker_image }}]

- name: Execute
id: run
continue-on-error: true
working-directory: ${{ inputs.working_directory }}
shell: bash
run: |
echo "testing bolt command"
bundle exec bolt command run 'last' -t all
echo "testing bolt task"
bundle exec bolt task run litmusimage::smoke -t all
- name: Cleanup
if: always()
shell: bash
working-directory: ${{ inputs.working_directory }}
run: |
set +e
if [[ -f spec/fixtures/litmus_inventory.yaml ]] ; then
if [[ "${{ steps.run.outcome }}" != "success" ]] ; then
bundle exec bolt inventory show --detail
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' }}
10 changes: 7 additions & 3 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ run-name: >
${{ inputs.push && format('push={0}', inputs.push) || ''}}
${{ inputs.puppet_litmus && format('puppet_litmus={0}', inputs.puppet_litmus) || '' }}
${{ inputs.provision_module && format('provision_module={0}', inputs.provision_module) || '' }}
${{ inputs.provision_task && format('provision_task={0}', inputs.provision_task) || '' }}
on:
workflow_dispatch:
Expand All @@ -29,9 +30,12 @@ on:
type: boolean
default: true
provision_task:
description: provision task (docker or docker_exp)
type: string
default: "docker"
description: provision task
type: choice
default: docker
options:
- docker
- docker_exp
puppet_litmus:
description: gem options (JSON Hash)
type: string
Expand Down
68 changes: 7 additions & 61 deletions .github/workflows/template_build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
images:
needs: select
name: image (${{ matrix.image_tag }})
timeout-minutes: 5
timeout-minutes: 10
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -186,68 +186,14 @@ jobs:
run: |
docker build --rm --no-cache -t ${IMAGE_TAG} . --label "base_image=${BASE_ID}" -f ${{ matrix.dockerfile }}.dockerfile --build-arg BASE_IMAGE_TAG=${{ matrix.base_tag }} --build-arg OS_TYPE=${{ matrix.base_image }}
- name: Smoke test setup
if: steps.build_image.outcome == 'success' || steps.build_image.conclusion == 'skipped'
id: test_ruby_setup
uses: "ruby/setup-ruby@v1"
- name: Smoke test (${{ inputs.provision_task }})
uses: ./.github/actions/smoke-test
with:
ruby-version: '3.2'
bundler-cache: true
working-directory: tests/smoke
docker_image: ${{ env.IMAGE_TAG }}
provision_task: ${{ inputs.provision_task }}
provision_module: ${{ inputs.provision_module }}

- name: Smoke test with custom provision module
if: steps.test_ruby_setup.outcome == 'success' && inputs.provision_module != ''
working-directory: tests/smoke
shell: ruby {0}
run: |
require 'yaml'
require 'json'
input = <<INPUT
${{ inputs.provision_module }}
INPUT
override = JSON.parse(input)
project = YAML.safe_load_file('bolt-project.yaml')
project["modules"].each_with_index do |mod, i|
project["modules"][i].merge!(override) if mod["name"].eql?('puppetlabs/provision')
end
File.write('bolt-project.yaml', project.to_yaml)
- name: Smoke test
if: steps.test_ruby_setup.outcome == 'success'
id: test_image
continue-on-error: true
working-directory: tests/smoke
timeout-minutes: 4
run: |
bundle info puppet_litmus
echo ::group::bolt module install
bundle exec bolt module install
bundle exec bolt module show
echo ::endgroup::
echo ::group::rake listmus:provision
bundle exec rake litmus:provision[${{ inputs.provision_task }},${IMAGE_TAG}]
echo ::endgroup::
echo "testing bolt command"
bundle exec bolt command run 'last' -t all
echo "testing bolt task"
bundle exec bolt task run litmusimage::smoke -t all
# Previous step should always continue on error
# so docker logs will be added to the output
- name: Smoke test cleanup
if: steps.test_image.conclusion == 'success'
working-directory: tests/smoke
run: |
set +e
echo ::group::Bolt inventory
bundle exec bolt inventory show --detail
echo ::endgroup::
docker ps -a --format '{{.ID}}' | xargs -n1 docker logs
bundle exec rake litmus:tear_down
# ALWAYS exit based on the outcode of the smoke test provision
exit ${{ steps.test_image.outcome != 'success' && '1' || '0' }}
- if: steps.build_image.outcome == 'success' && steps.test_image.outcome == 'success' && needs.select.outputs.push == 'true'
- if: steps.build_image.outcome == 'success' && needs.select.outputs.push == 'true'
name: Push ${{ matrix.image_tag }} to ${{ env.REGISTRY }}/${{ env.REPOSITORY }}
run: |
docker image push $IMAGE_TAG

0 comments on commit f4c30c4

Please sign in to comment.