-
Notifications
You must be signed in to change notification settings - Fork 6
263 lines (256 loc) · 10.5 KB
/
foreman_plugin.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
---
name: Foreman Plugin
on:
workflow_call:
inputs:
plugin:
description: Plugin name
required: true
type: string
plugin_repository:
description: Plugin repository to use
required: false
type: string
plugin_version:
description: Plugin version to use
required: false
type: string
foreman_version:
description: Foreman version to use
default: 'develop'
required: false
type: string
foreman_repository:
description: Foreman repository to use
default: 'theforeman/foreman'
required: false
type: string
matrix_include:
description: Additional test matrix combinations to include
default: '[]'
required: false
type: string
matrix_exclude:
description: Test matrix combinations to exclude
default: '[]'
required: false
type: string
postgresql_container:
description: PostgreSQL container to use
default: 'postgres'
required: false
type: string
test_existing_database:
description: Test plugin database migrations and seeds on an existing Foreman database
default: true
type: boolean
environment_variables:
description: arbitrary environment variables from caller
required: false
default: ''
type: string
env:
RAILS_ENV: test
NODE_ENV: test
DATABASE_URL: postgresql://postgres:password@localhost/test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
BUNDLE_WITHOUT: "console:development:journald:libvirt"
jobs:
setup_matrix:
name: Setup matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build_matrix.outputs.matrix }}
steps:
- name: Build test matrix
id: build_matrix
uses: theforeman/gha-matrix-builder@v0
with:
repository: ${{ inputs.foreman_repository }}
ref: ${{ inputs.foreman_version }}
include: ${{ inputs.matrix_include }}
exclude: ${{ inputs.matrix_exclude }}
test:
name: "${{ matrix.task }} - Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}"
needs: setup_matrix
runs-on: ubuntu-latest
services:
postgres:
image: '${{ inputs.postgresql_container }}:${{ matrix.postgresql }}'
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_PASSWORD: password
strategy:
fail-fast: false
matrix:
ruby: ${{ fromJson(needs.setup_matrix.outputs.matrix).ruby }}
node: ${{ fromJson(needs.setup_matrix.outputs.matrix).node }}
postgresql: ${{ fromJson(needs.setup_matrix.outputs.matrix).postgresql }}
task:
- 'test:${{ inputs.plugin }}'
- 'db:seed'
- 'plugin:assets:precompile[${{ inputs.plugin }}] RAILS_ENV=production DATABASE_URL=nulldb://nohost'
include: ${{ fromJson(needs.setup_matrix.outputs.matrix).include }}
exclude: ${{ fromJson(needs.setup_matrix.outputs.matrix).exclude }}
steps:
- name: Load environment variables from caller
run: echo "${{ inputs.environment_variables }}" >> $GITHUB_ENV
- run: sudo apt-get update
- run: sudo apt-get install -y build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev
- name: generate artifact suffix
run: echo "ARTIFACT_SUFFIX=$(echo 'ruby-${{ matrix.ruby }}-node-${{ matrix.node }}-pg-${{ matrix.postgresql }}-foreman-${{ inputs.foreman_version }}-${{ matrix.task }}' | tr -cd '[:alnum:]-')" >> "${GITHUB_ENV}"
- name: "Check out Foreman ${{ inputs.foreman_version }}"
uses: actions/checkout@v4
with:
repository: ${{ inputs.foreman_repository }}
ref: ${{ inputs.foreman_version }}
- name: Check out plugin
uses: actions/checkout@v4
with:
repository: ${{ inputs.plugin_repository }}
ref: ${{ inputs.plugin_version }}
path: ${{ inputs.plugin }}
- name: Set up plugin in Foreman
run: |
echo "gemspec name: '${{ inputs.plugin }}', path: '${{ inputs.plugin }}'" > "bundler.d/${{ inputs.plugin }}.local.rb"
if [ -d ${{ inputs.plugin }}/gemfile.d ] ; then
cat ${{ inputs.plugin }}/gemfile.d/*.rb >> bundler.d/${{ inputs.plugin }}.local.rb
fi
- name: "Set up Ruby ${{ matrix.ruby }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Archive Gemfile.lock
uses: actions/upload-artifact@v4
with:
name: Gemfile-${{ env.ARTIFACT_SUFFIX }}.lock
path: Gemfile.lock
- name: "Set up Node ${{ matrix.node }}"
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Setup NPM Cache
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }}
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}-
- name: "Build package-lock.json"
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }}
run: bundle exec npm install --package-lock-only --no-audit
- name: "Install NPM packages"
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }}
run: bundle exec npm ci --no-audit
- name: Archive package-lock.json
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && !contains(matrix.task, 'seed') }}
uses: actions/upload-artifact@v4
with:
name: package-lock-${{ env.ARTIFACT_SUFFIX }}.json
path: |
package-lock.json
${{ format('{0}/package-lock.json', inputs.plugin) }}
- name: Prepare test env
if: ${{ !contains(matrix.task, 'nulldb') }}
run: |
bundle exec rake db:create
bundle exec rake db:migrate
- name: "Compile webpack"
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && contains(matrix.task, 'test') }}
run:
bundle exec rake webpack:compile
- name: Archive all_react_app_exports
if: ${{ hashFiles(format('{0}/package.json', inputs.plugin), format('{0}/test/integration/**', inputs.plugin)) != '' && contains(matrix.task, 'test') }}
uses: actions/upload-artifact@v4
with:
name: all_react_app_exports-${{ env.ARTIFACT_SUFFIX }}.js
path: webpack/assets/javascripts/all_react_app_exports.js
- name: Add nulldb DB schema
run: cp -f db/schema.rb.nulldb db/schema.rb
if: ${{ contains(matrix.task, 'nulldb') }}
- name: Run rake ${{ matrix.task }}
run: bundle exec rake ${{ matrix.task }}
- name: Upload logs
uses: actions/upload-artifact@v4
if: ${{ failure() && contains(matrix.task, 'test') }}
with:
name: logs-${{ env.ARTIFACT_SUFFIX }}
path: log/*.log
retention-days: 5
# A dummy job that you can mark as a required check instead of each individual test
test-suite:
needs: test
runs-on: ubuntu-latest
name: Test suite
steps:
- run: echo Test suite completed
existing-database:
name: "Existing database - Foreman ${{ inputs.foreman_version }} with Ruby ${{ matrix.ruby }} and Node ${{ matrix.node }} on PostgreSQL ${{ matrix.postgresql }}"
if: ${{ inputs.test_existing_database }}
needs: setup_matrix
runs-on: ubuntu-latest
services:
postgres:
image: '${{ inputs.postgresql_container }}:${{ matrix.postgresql }}'
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_PASSWORD: password
strategy:
fail-fast: false
matrix:
ruby: ${{ fromJson(needs.setup_matrix.outputs.matrix).ruby }}
node: ${{ fromJson(needs.setup_matrix.outputs.matrix).node }}
postgresql: ${{ fromJson(needs.setup_matrix.outputs.matrix).postgresql }}
task:
- 'db:seed'
include: ${{ fromJson(needs.setup_matrix.outputs.matrix).include }}
exclude: ${{ fromJson(needs.setup_matrix.outputs.matrix).exclude }}
steps:
- name: Load environment variables from caller
run: echo "${{ inputs.environment_variables }}" >> $GITHUB_ENV
- run: sudo apt-get update
- run: sudo apt-get install -y build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev
- name: "Check out Foreman ${{ inputs.foreman_version }}"
uses: actions/checkout@v4
with:
repository: ${{ inputs.foreman_repository }}
ref: ${{ inputs.foreman_version }}
- name: "Set up Ruby ${{ matrix.ruby }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Prepare test env
run: |
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
- name: Check out plugin
uses: actions/checkout@v4
with:
repository: ${{ inputs.plugin_repository }}
ref: ${{ inputs.plugin_version }}
path: ${{ inputs.plugin }}
- name: Set up plugin in Foreman
run: |
echo "gemspec name: '${{ inputs.plugin }}', path: '${{ inputs.plugin }}'" > "bundler.d/${{ inputs.plugin }}.local.rb"
if [ -d ${{ inputs.plugin }}/gemfile.d ] ; then
cat ${{ inputs.plugin }}/gemfile.d/*.rb >> bundler.d/${{ inputs.plugin }}.local.rb
fi
- name: Install plugin
run: bundle install
- name: Run plugin db migrations and seeds
run: |
bundle exec rake db:migrate
bundle exec rake db:seed
# A dummy job that you can mark as a required check instead of each individual test
existing-database-suite:
needs: existing-database
runs-on: ubuntu-latest
name: Existing database suite
steps:
- run: echo Test suite completed