Skip to content

Commit be31d26

Browse files
committed
fix(tests): changed the expexted format of the config files
Signed-off-by: rostalan <[email protected]>
1 parent 0efa35d commit be31d26

File tree

3 files changed

+88
-34
lines changed

3 files changed

+88
-34
lines changed

.github/workflows/run-plugin-integration-tests.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ name: Run Plugin Integration Tests
22

33
on:
44
workflow_call:
5-
inputs:
6-
workspace-path:
7-
required: true
8-
type: string
95
outputs:
106
success:
117
description: Overall integration test result
@@ -39,8 +35,6 @@ jobs:
3935
password: ${{ secrets.GITHUB_TOKEN }}
4036

4137
- name: Start RHDH with Layered Test Config
42-
env:
43-
WORKSPACE_PATH: ${{ inputs.workspace-path }}
4438
run: |
4539
set -euo pipefail
4640
ls -la ./artifacts/ || true

.github/workflows/workspace-tests.yaml

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
workflow_run:
55
workflows: [Pull Request Actions]
66
types: [completed]
7-
paths:
8-
- 'workspaces/**'
97

108
jobs:
119
resolve:
@@ -80,38 +78,44 @@ jobs:
8078
echo "EOF" >> $GITHUB_OUTPUT
8179
8280
- name: Debug resolved metadata
81+
env:
82+
WORKSPACE: ${{ steps.meta.outputs.workspace }}
83+
PR: ${{ steps.meta.outputs.pr }}
84+
OVERLAY_SHA: ${{ steps.meta.outputs.overlayCommit }}
8385
run: |
84-
echo "Workspace: ${{ steps.meta.outputs.workspace }}"
85-
echo "PR: ${{ steps.meta.outputs.pr }}, Overlay SHA: ${{ steps.meta.outputs.overlayCommit }}"
86+
echo "Workspace: $WORKSPACE"
87+
echo "PR: $PR, Overlay SHA: $OVERLAY_SHA"
8688
8789
prepare-test-config:
8890
needs: resolve
8991
if: ${{ needs.resolve.outputs.workspace != '' }}
9092
runs-on: ubuntu-latest
9193
outputs:
9294
plugins_metadata_complete: ${{ steps.build-dynamic-plugins.outputs.plugins_metadata_complete }}
95+
skip_tests_missing_env: ${{ steps.build-dynamic-plugins.outputs.skip_tests_missing_env }}
9396
steps:
9497
- name: Checkout
9598
uses: actions/checkout@v4
9699
with:
97100
ref: ${{ needs.resolve.outputs.overlayBranch }}
98101
repository: ${{ needs.resolve.outputs.overlayRepo }}
99102

100-
- name: Setup yq
101-
uses: mikefarah/yq@v4
102-
103103
- name: Build dynamic-plugins.test.yaml
104104
id: build-dynamic-plugins
105+
env:
106+
WORKSPACE_PATH: ${{ needs.resolve.outputs.workspace }}
107+
PUBLISHED_EXPORTS: ${{ needs.resolve.outputs.publishedExports }}
105108
run: |
106-
WORKSPACE_PATH="${{ needs.resolve.outputs.workspace }}"
107-
PUBLISHED_EXPORTS="${{ needs.resolve.outputs.publishedExports }}"
108109
PLUGINS_FOUND=0
110+
PLUGINS_SKIPPED_MISSING_ENV=0
109111
TOTAL_PLUGINS=0
110112
PLUGINS_METADATA_COMPLETE="false"
113+
SKIP_TESTS_MISSING_ENV="false"
111114
112115
if [ -z "$PUBLISHED_EXPORTS" ]; then
113116
echo "No published exports provided."
114117
echo "plugins_metadata_complete=$PLUGINS_METADATA_COMPLETE" >> "$GITHUB_OUTPUT"
118+
echo "skip_tests_missing_env=$SKIP_TESTS_MISSING_ENV" >> "$GITHUB_OUTPUT"
115119
exit 0
116120
fi
117121
@@ -128,8 +132,8 @@ jobs:
128132
declare -A META_MAP
129133
for file in "$WORKSPACE_PATH"/metadata/*.yaml; do
130134
[ -e "$file" ] || continue
131-
pkg=$(yq -r '.packageName // ""' "$file")
132-
if [ -n "$pkg" ]; then
135+
pkg=$(yq -r '.spec.packageName // ""' "$file")
136+
if [ -n "$pkg" ] && [ "$pkg" != "null" ]; then
133137
stripped=$(echo "$pkg" | sed 's|^@||; s|/|-|')
134138
META_MAP["$stripped"]="$file"
135139
fi
@@ -138,6 +142,16 @@ jobs:
138142
# Always include the root-level default config
139143
ROOT_CONFIG="$GITHUB_WORKSPACE/tests/app-config.yaml"
140144
[ -f "$ROOT_CONFIG" ] && cp "$ROOT_CONFIG" "$OUT_DIR/app-config.yaml"
145+
146+
# Read workspace-wide test.env if it exists
147+
WORKSPACE_ENV_FILE="$WORKSPACE_PATH/tests/test.env"
148+
WORKSPACE_ENV_CONTENT=""
149+
if [ -f "$WORKSPACE_ENV_FILE" ]; then
150+
echo "Found workspace test.env file: $WORKSPACE_ENV_FILE"
151+
WORKSPACE_ENV_CONTENT=$(cat "$WORKSPACE_ENV_FILE")
152+
else
153+
echo "No workspace test.env file found at: $WORKSPACE_ENV_FILE"
154+
fi
141155
142156
# Start the resulting YAML file
143157
echo "plugins:" > "$OUT_FILE"
@@ -155,24 +169,52 @@ jobs:
155169
continue
156170
fi
157171
158-
PACKAGE_NAME=$(yq -r '.packageName' "$METADATA_FILE")
172+
PACKAGE_NAME=$(yq -r '.spec.packageName' "$METADATA_FILE")
159173
if [ -z "$PACKAGE_NAME" ] || [ "$PACKAGE_NAME" = "null" ]; then
160-
echo "packageName not found in $METADATA_FILE, skipping"
174+
echo "spec.packageName not found in $METADATA_FILE, skipping"
161175
continue
162176
fi
163177
164-
# Extract plugin config block under configs.default
165-
if ! yq -e '.configs.default' "$METADATA_FILE" >/dev/null 2>&1; then
166-
echo "configs.default not found in $METADATA_FILE, skipping"
178+
# First appConfigExamples item is used for testing
179+
CONFIG_CONTENT=$(yq -o=yaml '.spec.appConfigExamples[0].content' "$METADATA_FILE" 2>/dev/null || echo "")
180+
if [ -z "$CONFIG_CONTENT" ] || [ "$CONFIG_CONTENT" = "null" ]; then
181+
echo "spec.appConfigExamples[0].content not found in $METADATA_FILE, skipping"
167182
continue
168183
fi
169184
185+
ENV_VARS=$(echo "$CONFIG_CONTENT" | yq -o=yaml '.dynamicPlugins' 2>/dev/null | grep -oE '\$\{[A-Z_][A-Z0-9_]*\}|\$[A-Z_][A-Z0-9_]*' | sed 's/\${//; s/}//; s/^\$//' | sort -u || true)
186+
187+
if [ -n "$ENV_VARS" ]; then
188+
# Config contains environment variables
189+
if [ -z "$WORKSPACE_ENV_CONTENT" ]; then
190+
echo " ::warning::Config for $PLUGIN_NAME contains environment variables but workspace test.env is missing. Tests will be skipped."
191+
SKIP_TESTS_MISSING_ENV="true"
192+
PLUGINS_SKIPPED_MISSING_ENV=$((PLUGINS_SKIPPED_MISSING_ENV + 1))
193+
continue
194+
else
195+
# Validate all ENVs are present in merged env file
196+
MISSING_ENVS=()
197+
while IFS= read -r env_var; do
198+
[ -z "$env_var" ] && continue
199+
if ! echo "$WORKSPACE_ENV_CONTENT" | grep -qE "^[[:space:]]*${env_var}[[:space:]]*="; then
200+
MISSING_ENVS+=("$env_var")
201+
fi
202+
done <<< "$ENV_VARS"
203+
204+
if [ ${#MISSING_ENVS[@]} -gt 0 ]; then
205+
echo " ::error::Environment variables missing from test.env: ${MISSING_ENVS[*]}"
206+
echo " Config for $PLUGIN_NAME references these environment variables but they are not defined in $WORKSPACE_ENV_FILE."
207+
exit 1
208+
fi
209+
fi
210+
fi
211+
# If no ENVs in config, continue regardless of env file existence
212+
170213
STRIPPED=$(echo "$PACKAGE_NAME" | sed 's|^@||; s|/|-|')
171214
echo "- package: \"oci://ghcr.io/${IMAGE_PATH_AND_PLUGIN}:${NEW_TAG}!${STRIPPED}\"" >> "$OUT_FILE"
172215
echo " disabled: false" >> "$OUT_FILE"
173216
echo " pluginConfig:" >> "$OUT_FILE"
174-
# Append the configs.default block indented by 4 spaces under pluginConfig
175-
yq -o=yaml '.configs.default' "$METADATA_FILE" | sed 's/^/ /' >> "$OUT_FILE"
217+
echo "$CONFIG_CONTENT" | sed 's/^/ /' >> "$OUT_FILE"
176218
PLUGINS_FOUND=$((PLUGINS_FOUND + 1))
177219
else
178220
echo "Export did not match expected format, skipping: $export"
@@ -183,11 +225,17 @@ jobs:
183225
echo "[]" >> "$OUT_FILE"
184226
fi
185227
186-
if [ "$PLUGINS_FOUND" -eq "$TOTAL_PLUGINS" ] && [ "$TOTAL_PLUGINS" -gt 0 ]; then
228+
# Check if all plugins were found (including those skipped due to missing env)
229+
TOTAL_PROCESSED=$((PLUGINS_FOUND + PLUGINS_SKIPPED_MISSING_ENV))
230+
echo "Plugins: $PLUGINS_FOUND/$TOTAL_PLUGINS processed successfully"
231+
[ "${PLUGINS_SKIPPED_MISSING_ENV:-0}" -gt 0 ] && echo "Skipped $PLUGINS_SKIPPED_MISSING_ENV (missing test.env)"
232+
233+
if [ "$TOTAL_PROCESSED" -eq "$TOTAL_PLUGINS" ] && [ "$TOTAL_PLUGINS" -gt 0 ]; then
187234
PLUGINS_METADATA_COMPLETE="true"
188235
fi
189236
190237
echo "plugins_metadata_complete=$PLUGINS_METADATA_COMPLETE" >> "$GITHUB_OUTPUT"
238+
echo "skip_tests_missing_env=$SKIP_TESTS_MISSING_ENV" >> "$GITHUB_OUTPUT"
191239
192240
- name: Upload integration-test artefact
193241
uses: actions/upload-artifact@v4
@@ -200,13 +248,11 @@ jobs:
200248
needs:
201249
- resolve
202250
- prepare-test-config
203-
if: ${{ needs.prepare-test-config.outputs.plugins_metadata_complete == 'true' }}
251+
if: ${{ needs.prepare-test-config.outputs.plugins_metadata_complete == 'true' && needs.prepare-test-config.outputs.skip_tests_missing_env != 'true' }}
204252
uses: ./.github/workflows/run-plugin-integration-tests.yaml
205-
with:
206-
workspace-path: ${{ needs.resolve.outputs.workspace }}
207253

208254
add-skipped-test-comment:
209-
if: ${{ needs.prepare-test-config.outputs.plugins_metadata_complete == 'false' && needs.resolve.outputs.prNumber != 'null' }}
255+
if: ${{ (needs.prepare-test-config.outputs.plugins_metadata_complete == 'false' || needs.prepare-test-config.outputs.skip_tests_missing_env == 'true') && needs.resolve.outputs.prNumber != 'null' }}
210256
needs:
211257
- resolve
212258
- prepare-test-config
@@ -217,15 +263,24 @@ jobs:
217263
steps:
218264
- name: Post skipped-test comment
219265
uses: actions/github-script@v7
266+
env:
267+
INPUT_SKIP_MISSING_ENV: ${{ needs.prepare-test-config.outputs.skip_tests_missing_env }}
268+
INPUT_PR_NUMBER: ${{ needs.resolve.outputs.prNumber }}
220269
with:
221270
script: |
222-
const pr = Number('${{ needs.resolve.outputs.prNumber }}');
271+
const pr = Number(core.getInput('pr_number') || '0');
223272
if (!pr) {
224273
console.log('No PR associated; skipping');
225274
return;
226275
}
227276
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
228-
const body = `:warning: \n[Test workflow](${runUrl}) skipped because some plugin metadata files (\`<workspace>/metadata/*.yaml\`) were not found.\n\nAdd the corresponding metadata files to enable testing for this workspace.\n`;
277+
const skipMissingEnv = core.getInput('skip_missing_env') === 'true';
278+
let body;
279+
if (skipMissingEnv) {
280+
body = `:warning: \n[Test workflow](${runUrl}) skipped because some plugin configurations contain environment variables but the workspace \`tests/test.env\` file is missing.\n\nAdd the required \`test.env\` file to enable testing for this workspace.\n`;
281+
} else {
282+
body = `:warning: \n[Test workflow](${runUrl}) skipped because some plugin metadata files (\`<workspace>/metadata/*.yaml\`) were not found.\n\nAdd the corresponding metadata files to enable testing for this workspace.\n`;
283+
}
229284
await github.rest.issues.createComment({
230285
owner: context.repo.owner,
231286
repo: context.repo.repo,
@@ -234,7 +289,7 @@ jobs:
234289
});
235290
236291
add-test-result-comment:
237-
if: ${{ needs.prepare-test-config.outputs.plugins_metadata_complete == 'true' }}
292+
if: ${{ needs.prepare-test-config.outputs.plugins_metadata_complete == 'true' && needs.prepare-test-config.outputs.skip_tests_missing_env != 'true' }}
238293
needs:
239294
- resolve
240295
- prepare-test-config
@@ -260,7 +315,7 @@ jobs:
260315
script: |
261316
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
262317
const success = process.env.SUCCESS === 'true';
263-
const failed = process.env.FAILED_PLUGINS.trim();
318+
const failed = (process.env.FAILED_PLUGINS || '').trim();
264319
const pr = Number(process.env.PR_NUMBER);
265320
const overlayCommit = process.env.OVERLAY_COMMIT;
266321

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ The repository includes an automated integration testing workflow that verifies
133133

134134
**Testing workflow steps:**
135135
1. **Resolve metadata**: Retrieves published OCI references and PR metadata from the `published-exports` artifact
136-
2. **Prepare test config**: Generates `dynamic-plugins.test.yaml` from plugin metadata and copies other configuration files (`tests/app-config.yaml` and workspace-specific `app-config.test.yaml`, `test.env`)
136+
2. **Prepare test config**: Generates `dynamic-plugins.test.yaml` from plugin metadata and copies other configuration files (`tests/app-config.yaml`, workspace-specific `app-config.test.yaml` and `test.env`)
137137
3. **Run integration tests**: Starts RHDH container with layered configuration, installs dynamic plugins from OCI artifacts, and verifies each plugin loads successfully
138138
4. **Report results**: Posts test status as a commit status check and PR comment with pass/fail results and links to the workflow run
139139

140+
**Environment Variables in Tests:**
141+
If your plugin configuration (in `metadata/*.yaml`) uses environment variables (e.g., `${API_TOKEN}`), you must provide them in a `test.env` file located at `workspaces/<workspace>/tests/test.env`.
142+
- If the `.env` file is missing but required, tests are skipped.
143+
- If the `.env` file exists but is missing variables, the workflow fails.
144+
140145
- **Results** are reported via PR comment and in the status check. The complete container logs are also available, in the `integration-tests/run` step.
141146

142147
#### Manual Testing

0 commit comments

Comments
 (0)