Skip to content

Commit ed4791c

Browse files
committed
Add new custom workflow
Signed-off-by: Hoo Sooyean (何書淵) <[email protected]>
1 parent 488c7e3 commit ed4791c

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
46+
jobs:
47+
48+
setup_matrix:
49+
name: "Setup Test Matrix"
50+
runs-on: ${{ inputs.runs_on }}
51+
outputs:
52+
acceptance_matrix: ${{ steps.get-matrix.outputs.matrix }}
53+
ruby_version: ${{ steps.get-puppet_ruby_version.outputs.ruby_version }}
54+
puppet_version: ${{ steps.get-puppet_ruby_version.outputs.puppet_version }}
55+
56+
env:
57+
BUNDLE_WITHOUT: release_prep
58+
59+
steps:
60+
61+
- name: "Checkout"
62+
uses: "actions/checkout@v4"
63+
with:
64+
ref: ${{ github.event.pull_request.head.sha }}
65+
66+
- name: "Setup ruby"
67+
uses: "ruby/setup-ruby@v1"
68+
with:
69+
ruby-version: "2.7"
70+
bundler-cache: true
71+
72+
- name: "Bundle environment"
73+
run: |
74+
echo ::group::bundler environment
75+
bundle env
76+
echo ::endgroup::
77+
78+
- name: Setup Test Matrix
79+
id: get-matrix
80+
run: |
81+
bundle exec matrix_from_metadata_v2 ${{ inputs.flags }}
82+
83+
- name: Setup Ruby Version and Setup Puppet Version
84+
id: get-puppet_ruby_version
85+
run: |
86+
echo ${{ toJSON(steps.get-matrix.outputs.spec_matrix ) }} | jq -r '.include | .[0] | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_OUTPUT
87+
88+
acceptance:
89+
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}} "
90+
needs: "setup_matrix"
91+
runs-on: ${{ inputs.runs_on }}
92+
timeout-minutes: 180
93+
strategy:
94+
fail-fast: false
95+
matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance_matrix ) }}
96+
97+
env:
98+
BUNDLE_WITHOUT: release_prep
99+
PUPPET_GEM_VERSION: ${{needs.setup_matrix.outputs.puppet_version}}
100+
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
101+
102+
steps:
103+
104+
- name: "Checkout"
105+
uses: "actions/checkout@v4"
106+
with:
107+
ref: ${{ github.event.pull_request.head.sha }}
108+
109+
- name: "Disable Apparmor"
110+
if: ${{ inputs.disable_apparmor }}
111+
run: |
112+
if command -v apparmor_parser >/dev/null ; then
113+
sudo find /etc/apparmor.d/ -maxdepth 1 -type f -exec ln -sf {} /etc/apparmor.d/disable/ \;
114+
sudo apparmor_parser -R /etc/apparmor.d/disable/* || true
115+
sudo systemctl disable apparmor
116+
sudo systemctl stop apparmor
117+
fi
118+
119+
- name: "Setup ruby"
120+
uses: "ruby/setup-ruby@v1"
121+
with:
122+
ruby-version: ${{needs.setup_matrix.outputs.ruby_version}}
123+
bundler-cache: true
124+
125+
- name: "Bundle environment"
126+
run: |
127+
echo ::group::bundler environment
128+
bundle env
129+
echo ::endgroup::
130+
131+
- name: "Provision environment"
132+
run: |
133+
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then
134+
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}"
135+
else
136+
DOCKER_RUN_OPTS=''
137+
fi
138+
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake "${{ inputs.provision_environment__task }}[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]"
139+
# Redact password
140+
FILE='spec/fixtures/litmus_inventory.yaml'
141+
if [[ -f $FILE ]] ; then
142+
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true ;
143+
fi
144+
145+
- name: "Install Puppet agent"
146+
run: |
147+
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake '${{ inputs.install_agent__task }}[${{ matrix.collection }}]'
148+
149+
- name: "Install module"
150+
run: |
151+
[ -z "${{ inputs.install_module__task }}" ] || bundle exec rake '${{ inputs.install_module__task }}'
152+
153+
- name: "Run acceptance tests"
154+
run: |
155+
[ -z "${{ inputs.acceptance__task }}" ] || bundle exec rake '${{ inputs.acceptance__task }}'
156+
157+
- name: "Remove test environment"
158+
if: ${{ always() }}
159+
continue-on-error: true
160+
run: |
161+
if [[ -f spec/fixtures/litmus_inventory.yaml ]] ; then
162+
[ -z "${{ inputs.tear_down__task }}" ] || bundle exec rake '${{ inputs.tear_down__task }}'
163+
fi

0 commit comments

Comments
 (0)