Skip to content

Commit e982609

Browse files
committed
Remove hardcoder version of ruby and puppet and replaced with values
generated by matrix_from_metadata_v2 Add new custom workflow Signed-off-by: Hoo Sooyean (何書淵) <[email protected]> Add in a new input: matrix_from_metadata default to matrix_from_metadata_v2 Clean up some spaces in *custom.yaml
1 parent b98f1f1 commit e982609

File tree

2 files changed

+178
-3
lines changed

2 files changed

+178
-3
lines changed

.github/workflows/module_acceptance.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
runs-on: ${{ inputs.runs_on }}
3131
outputs:
3232
acceptance_matrix: ${{ steps.get-matrix.outputs.matrix }}
33+
ruby_version: ${{ steps.get-puppet_ruby_version.outputs.ruby_version }}
34+
puppet_version: ${{ steps.get-puppet_ruby_version.outputs.puppet_version }}
3335

3436
env:
3537
BUNDLE_WITHOUT: release_prep
@@ -56,8 +58,13 @@ jobs:
5658
run: |
5759
bundle exec matrix_from_metadata_v2 ${{ inputs.flags }}
5860
61+
- name: Setup Ruby Version and Setup Puppet Version
62+
id: get-puppet_ruby_version
63+
run: |
64+
echo ${{ toJSON(steps.get-matrix.outputs.spec_matrix ) }} | jq -r '.include | .[0] | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_OUTPUT
65+
5966
acceptance:
60-
name: "Acceptance tests (${{matrix.platforms.label}}, ${{matrix.collection}})"
67+
name: "Acceptance tests (${{matrix.platforms.label}}, ${{matrix.collection}}) - ruby: ${{needs.setup_matrix.outputs.ruby_version}} puppet: ${{needs.setup_matrix.outputs.puppet_version}} "
6168
needs: "setup_matrix"
6269
runs-on: ${{ inputs.runs_on }}
6370
timeout-minutes: 180
@@ -67,7 +74,7 @@ jobs:
6774

6875
env:
6976
BUNDLE_WITHOUT: release_prep
70-
PUPPET_GEM_VERSION: '~> 7.24'
77+
PUPPET_GEM_VERSION: ${{needs.setup_matrix.outputs.puppet_version}}
7178
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
7279

7380
steps:
@@ -88,7 +95,7 @@ jobs:
8895
- name: "Setup ruby"
8996
uses: "ruby/setup-ruby@v1"
9097
with:
91-
ruby-version: "2.7"
98+
ruby-version: ${{needs.setup_matrix.outputs.ruby_version}}
9299
bundler-cache: true
93100

94101
- name: "Bundle environment"
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# This is a generic workflow for Puppet module acceptance operations custom versions.
2+
name: "Module Acceptance Custom"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
runs_on:
8+
description: "The operating system used for the runner."
9+
required: false
10+
default: "ubuntu-latest"
11+
type: "string"
12+
flags:
13+
description: "Additional flags to pass to matrix_from_metadata_v2."
14+
required: false
15+
default: ''
16+
type: "string"
17+
kernel_modules:
18+
description: "Volume map host kernel /lib/modules into docker container"
19+
default: true
20+
type: boolean
21+
disable_apparmor:
22+
description: "Disable and stop apparmor"
23+
default: false
24+
type: boolean
25+
provision_environment__task:
26+
description: 'Task for the step "Provision environment"'
27+
default: 'litmus:provision'
28+
type: "string"
29+
install_agent__task:
30+
description: 'Task for the step "Install Puppet agent"'
31+
default: 'litmus:install_agent'
32+
type: "string"
33+
install_module__task:
34+
description: 'Task for the step "Install module"'
35+
default: 'litmus:install_module'
36+
type: "string"
37+
acceptance__task:
38+
description: 'Task for the step "Run acceptance tests"'
39+
default: 'litmus:acceptance:parallel'
40+
type: "string"
41+
tear_down__task:
42+
description: 'Task for the step "Remove test environment"'
43+
default: 'litmus:tear_down'
44+
type: "string"
45+
matrix_from_metadata:
46+
description: 'Commands to run to get the test matrix'
47+
default: 'matrix_from_metadata_v2'
48+
type: "string"
49+
50+
51+
jobs:
52+
53+
setup_matrix:
54+
name: "Setup Test Matrix"
55+
runs-on: ${{ inputs.runs_on }}
56+
outputs:
57+
acceptance_matrix: ${{ steps.get-matrix.outputs.matrix }}
58+
ruby_version: ${{ steps.get-puppet_ruby_version.outputs.ruby_version }}
59+
puppet_version: ${{ steps.get-puppet_ruby_version.outputs.puppet_version }}
60+
61+
env:
62+
BUNDLE_WITHOUT: release_prep
63+
64+
steps:
65+
66+
- name: "Checkout"
67+
uses: "actions/checkout@v4"
68+
with:
69+
ref: ${{ github.event.pull_request.head.sha }}
70+
71+
- name: "Setup ruby"
72+
uses: "ruby/setup-ruby@v1"
73+
with:
74+
ruby-version: "2.7"
75+
bundler-cache: true
76+
77+
- name: "Bundle environment"
78+
run: |
79+
echo ::group::bundler environment
80+
bundle env
81+
echo ::endgroup::
82+
83+
- name: Setup Test Matrix
84+
id: get-matrix
85+
run: |
86+
bundle exec ${{ inputs.matrix_from_metadata }} ${{ inputs.flags }}
87+
88+
- name: Setup Ruby Version and Setup Puppet Version
89+
id: get-puppet_ruby_version
90+
run: |
91+
echo ${{ toJSON(steps.get-matrix.outputs.spec_matrix ) }} | jq -r '.include | .[0] | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_OUTPUT
92+
93+
acceptance:
94+
name: "Acceptance tests (${{matrix.platforms.label}} => ${{matrix.platforms.image}}, ${{matrix.collection}}) - ruby: ${{needs.setup_matrix.outputs.ruby_version}} puppet: ${{needs.setup_matrix.outputs.puppet_version}} "
95+
needs: "setup_matrix"
96+
runs-on: ${{ inputs.runs_on }}
97+
timeout-minutes: 180
98+
strategy:
99+
fail-fast: false
100+
matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance_matrix ) }}
101+
102+
env:
103+
BUNDLE_WITHOUT: release_prep
104+
PUPPET_GEM_VERSION: ${{needs.setup_matrix.outputs.puppet_version}}
105+
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
106+
107+
steps:
108+
109+
- name: "Checkout"
110+
uses: "actions/checkout@v4"
111+
with:
112+
ref: ${{ github.event.pull_request.head.sha }}
113+
114+
- name: "Disable Apparmor"
115+
if: ${{ inputs.disable_apparmor }}
116+
run: |
117+
if command -v apparmor_parser >/dev/null ; then
118+
sudo find /etc/apparmor.d/ -maxdepth 1 -type f -exec ln -sf {} /etc/apparmor.d/disable/ \;
119+
sudo apparmor_parser -R /etc/apparmor.d/disable/* || true
120+
sudo systemctl disable apparmor
121+
sudo systemctl stop apparmor
122+
fi
123+
124+
- name: "Setup ruby"
125+
uses: "ruby/setup-ruby@v1"
126+
with:
127+
ruby-version: ${{needs.setup_matrix.outputs.ruby_version}}
128+
bundler-cache: true
129+
130+
- name: "Bundle environment"
131+
run: |
132+
echo ::group::bundler environment
133+
bundle env
134+
echo ::endgroup::
135+
136+
- name: "Provision environment"
137+
run: |
138+
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
139+
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
140+
else
141+
DOCKER_RUN_OPTS=''
142+
fi
143+
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake "${{ inputs.provision_environment__task }}[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]"
144+
# Redact password
145+
FILE='spec/fixtures/litmus_inventory.yaml'
146+
if [[ -f $FILE ]] ; then
147+
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true ;
148+
fi
149+
150+
- name: "Install Puppet agent"
151+
run: |
152+
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake '${{ inputs.install_agent__task }}[${{ matrix.collection }}]'
153+
154+
- name: "Install module"
155+
run: |
156+
[ -z "${{ inputs.install_module__task }}" ] || bundle exec rake '${{ inputs.install_module__task }}'
157+
158+
- name: "Run acceptance tests"
159+
run: |
160+
[ -z "${{ inputs.acceptance__task }}" ] || bundle exec rake '${{ inputs.acceptance__task }}'
161+
162+
- name: "Remove test environment"
163+
if: ${{ always() }}
164+
continue-on-error: true
165+
run: |
166+
if [[ -f spec/fixtures/litmus_inventory.yaml ]] ; then
167+
[ -z "${{ inputs.tear_down__task }}" ] || bundle exec rake '${{ inputs.tear_down__task }}'
168+
fi

0 commit comments

Comments
 (0)