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

Refactor github actions workflow #3

Merged
merged 5 commits into from
Feb 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: "ci"

on:
pull_request:
types:
- opened
- labeled
- synchronize
branches:
- "main"
paths-ignore:
Expand All @@ -11,13 +15,44 @@ on:
- 'CODEOWNERS'
- 'AUTHORS'
workflow_dispatch:

inputs:
debug:
description: "Debug"
type: boolean
required: false
default: true
run_spec:
description: "Run Spec job"
type: boolean
required: false
default: true
run_acceptance:
description: "Run Acceptance job"
type: boolean
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Matrix:
uses: ./.github/workflows/matrix.yml
Spec:
uses: "./.github/workflows/module_unit.yml"
secrets: "inherit"

if: ${{ github.event_name == 'pull_request' || inputs.run_spec == 'true' }}
needs: Matrix
uses: ./.github/workflows/module_spec.yml
secrets: inherit
with:
debug: ${{ github.events.inputs.debug == 'true' || contains(github.event.pull_request.labels.*.name, 'debug') }}
matrix: ${{ needs.Matrix.outputs.spec_matrix }}
Acceptance:
needs: Spec
uses: "./.github/workflows/module_acceptance.yml"
secrets: "inherit"
if: ${{ github.event_name == 'pull_request' || inputs.run_acceptance == 'true' }}
needs: [ Matrix, Spec ]
uses: ./.github/workflows/module_acceptance.yml
secrets: inherit
with:
debug: ${{ github.events.inputs.debug == 'true' || contains(github.event.pull_request.labels.*.name, 'debug') }}
matrix: ${{ needs.Matrix.outputs.acceptance_matrix }}
runs_on: ubuntu-20.04 # TODO: cgroupv1 containers do not provision on ubuntu-latest
49 changes: 49 additions & 0 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
on:
workflow_call:
inputs:
runs_on:
description: "The operating system used for the runner."
required: false
default: "ubuntu-latest"
type: "string"
flags:
description: "Additional flags to pass to matrix_from_metadata_v2."
required: false
default: ''
type: "string"
outputs:
spec_matrix:
description: "Spec matrix from metadata"
value: ${{ jobs.generate-json-matrix.outputs.spec_matrix }}
acceptance_matrix:
description: "Acceptance matrix from metadata"
value: ${{ jobs.generate-json-matrix.outputs.acceptance_matrix }}

jobs:
generate-json-matrix:
name: Generate
runs-on: ${{ inputs.runs_on }}
outputs:
spec_matrix: ${{ steps.get-matrix.outputs.spec_matrix }}
acceptance_matrix: ${{ steps.get-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Activate Ruby 2.7
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
- name: Setup Test Matrix
id: get-matrix
run: |
bundle exec matrix_from_metadata_v2 ${{ inputs.flags }}
echo ::group::spec matrix
sed -n 's/^spec_matrix=\(.*\)/\1/p' $GITHUB_OUTPUT | jq
echo ::endgroup::
echo ::group::acceptance matrix
sed -n 's/^matrix=\(.*\)/\1/p' $GITHUB_OUTPUT | jq
echo ::endgroup::
160 changes: 91 additions & 69 deletions .github/workflows/module_acceptance.yml
Original file line number Diff line number Diff line change
@@ -1,106 +1,128 @@
# This is a generic workflow for Puppet module acceptance operations.
name: "Module Acceptance Tests"
name: "Module Acceptance"

on:
workflow_call:
inputs:
runs_on:
description: "The operating system used for the runner."
matrix:
description: "JSON matrix"
type: "string"
required: true
debug:
description: "Run jobs with debug steps and flags enabled"
type: "boolean"
required: false
default: "ubuntu-latest"
default: false
puppet_version:
description: "Version of Puppet used to run tests"
type: "string"
required: false
default: "~> 7.24"
ruby_version:
description: "Version of Ruby to install"
type: "string"
flags:
description: "Additional flags to pass to matrix_from_metadata_v2."
required: false
default: "--exclude-platforms '[\"ubuntu-22.04-arm\"]'"
default: "2.7"
runs_on:
description: "The operating system used for the runner"
type: "string"
required: false
default: "ubuntu-latest"

jobs:

setup_matrix:
name: "Setup Test Matrix"
runs-on: ${{ inputs.runs_on }}
outputs:
acceptance_matrix: ${{ steps.get-matrix.outputs.matrix }}

steps:

- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Setup ruby"
uses: "ruby/setup-ruby@v1"
with:
ruby-version: "2.7"
bundler-cache: true

- name: "Bundle environment"
run: |
echo ::group::bundler environment
bundle env
echo ::endgroup::

- name: Setup Test Matrix
id: get-matrix
run: |
bundle exec matrix_from_metadata_v2 ${{ inputs.flags }}

acceptance:
name: "Acceptance tests (${{matrix.platforms.label}}, ${{matrix.collection}})"
needs: "setup_matrix"
Test:
name: "Test ${{ matrix.platforms.label }} with ${{ matrix.collection }}"
runs-on: ${{ inputs.runs_on }}
timeout-minutes: 180
strategy:
fail-fast: false
matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance_matrix ) }}

matrix: ${{ fromJson(inputs.matrix) }}
env:
PUPPET_GEM_VERSION: '~> 7.24'
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?

PUPPET_GEM_VERSION: ${{ inputs.puppet_version }}
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main'
BOLT_GEM: 1
steps:
- name: Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Setup ruby"
uses: "ruby/setup-ruby@v1"
- name: Activate Ruby ${{ inputs.ruby_version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
ruby-version: ${{ inputs.ruby_version }}
bundler-cache: true

- name: "Bundle environment"
- name: Debug
if: ${{ inputs.debug == true }}
run: |
echo ::group::bundler environment
bundle env
echo ::endgroup::

- name: "Provision environment"
echo ::group::docker info
docker info
echo ::endgroup::
echo "RSPEC_DEBUG=1" >> $GITHUB_ENV
echo "DEBUG=1" >> $GITHUB_ENV

- name: Cache fixture modules
id: cache-fixtures
uses: actions/cache@v4
env:
cache-name: cache-fixtures-modules
with:
path: spec/fixtures/modules
key: test-${{ env.cache-name }}-${{ hashFiles('metadata.json', '.fixtures.yml') }}
restore-keys: |
test-${{ env.cache-name }}-
test-

- name: Provision test environment
id: provision-environment
continue-on-error: ${{ contains(fromJson('["provision_service"]'), matrix.platforms.provider) }}
run: |
if [[ "${{matrix.platforms.provider}}" == "docker" ]]; then
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
else
DOCKER_RUN_OPTS=''
fi
bundle exec rake "litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]"
# Redact password
bundle exec rake 'litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }}]'
FILE='spec/fixtures/litmus_inventory.yaml'
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
if [ "${{ inputs.debug }}" == "true" ] ; then
while read CN ; do
echo ::group::docker container $CN
docker inspect "$CN"
echo ::endgroup::
done < <(docker ps --format '{{.Names}}')
fi

- name: "Install Puppet agent"
- name: Install agent
if: ${{ steps.provision-environment.outcome == 'success' }}
run: |
echo ::group::agent
bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]'
echo ::endgroup::

- name: "Install module"
run: |
bundle exec rake 'litmus:install_modules_from_fixtures'
- name: Install module
if: ${{ steps.provision-environment.outcome == 'success' }}
run: bundle exec rake 'litmus:install_module'

- name: "Run acceptance tests"
- name: Run acceptance tests
if: ${{ steps.provision-environment.outcome == 'success' }}
id: run-acceptance
run: bundle exec rake 'litmus:acceptance'

- name: Failure Logs
if: ${{ failure() && steps.run-acceptance.outcome == 'failure' }}
continue-on-error: true
run: |
bundle exec rake 'litmus:acceptance:parallel'
echo ::group::last 100 lines in runner journal
journalctl -n 100
echo ::endgroup::
echo ::group::last 100 lines in container journal
bundle exec bolt command run 'journalctl -n 100' -t all -i spec/fixtures/litmus_inventory.yaml
echo ::endgroup::
echo ::group::last 50 lines of puppetlabs logs
bundle exec bolt command run 'tail -n 50 /var/log/puppetlabs/*/*.log' -t all -i spec/fixtures/litmus_inventory.yaml
echo ::endgroup::

- name: "Remove test environment"
if: ${{ always() }}
- name: Tear down
if: ${{ always() && steps.provision-environment.outcome == 'success' }}
continue-on-error: true
run: |
if [[ -f spec/fixtures/litmus_inventory.yaml ]]; then
Expand Down
Loading
Loading