Skip to content

Commit 67b355d

Browse files
committed
feat(validate-metadata): take in account image tag prefix in metadata validation logic.
The validation logic is enhanced to skip the tag check when the prefix is set to "next__", accommodating backstage-incompatible workspaces. Assisted-by: Cursor Signed-off-by: David Festal <dfestal@redhat.com>
1 parent c53dd49 commit 67b355d

6 files changed

Lines changed: 78 additions & 11 deletions

File tree

.github/workflows/export-dynamic.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,4 @@ jobs:
413413
plugins-root: ${{ github.workspace }}/source-repo/${{inputs.plugins-root}}
414414
target-backstage-version: ${{ inputs.target-backstage-version }}
415415
image-repository-prefix: ${{ steps.set-image-tag-name.outputs.IMAGE_REPOSITORY_PREFIX }}
416+
image-tag-prefix: ${{ inputs.image-tag-prefix }}

.github/workflows/test-validate-metadata.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,41 @@ jobs:
398398
file: 'plugins-list.yaml',
399399
message: 'plugins-list.yaml must be a YAML dictionary with plugin paths as keys'
400400
});
401+
402+
test-validation-next-prefix-skips-tag:
403+
name: Test Validation (next__ prefix skips OCI tag check)
404+
runs-on: ubuntu-latest
405+
steps:
406+
- name: Checkout repository
407+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
408+
409+
- name: Setup Node.js 24.x
410+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
411+
with:
412+
node-version: 24.x
413+
414+
- name: Run Validate Metadata with next__ prefix
415+
id: validate
416+
uses: ./validate-metadata
417+
with:
418+
overlay-root: ${{ env.TEST_DIR }}/cases/next-prefix-skip
419+
plugins-root: ${{ env.TEST_DIR }}/source
420+
target-backstage-version: ${{ env.TARGET_BACKSTAGE_VERSION }}
421+
image-repository-prefix: ${{ env.IMAGE_REPOSITORY_PREFIX }}
422+
image-tag-prefix: next__
423+
424+
- name: Verify validation passed despite stale OCI tag
425+
env:
426+
VALIDATION_PASSED: ${{ steps.validate.outputs.validation-passed }}
427+
VALIDATION_ERROR_COUNT: ${{ steps.validate.outputs.validation-error-count }}
428+
VALIDATION_ERRORS: ${{ steps.validate.outputs.validation-errors }}
429+
shell: node {0}
430+
run: |
431+
import assert from 'node:assert/strict';
432+
const { VALIDATION_PASSED, VALIDATION_ERROR_COUNT, VALIDATION_ERRORS } = process.env;
433+
434+
// Metadata has bs_1.40.0__1.0.0 which doesn't match target 1.42.5,
435+
// but with next__ prefix the OCI tag check is skipped
436+
assert.equal(VALIDATION_PASSED, 'true');
437+
assert.equal(VALIDATION_ERROR_COUNT, '0');
438+
assert.equal(VALIDATION_ERRORS, '[]');

validate-metadata/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: Repository prefix for validating OCI reference format in dynamicArtifact
1515
required: false
1616
default: ""
17+
image-tag-prefix:
18+
description: OCI image tag prefix used by the export (e.g., "bs_1.48.3__", "next__", "pr_42__"). When "next__", OCI tag validation is skipped since the workspace is backstage-incompatible.
19+
required: false
20+
default: ""
1721

1822
outputs:
1923
validation-passed:
@@ -38,6 +42,7 @@ runs:
3842
INPUTS_PLUGINS_ROOT: ${{ inputs.plugins-root }}
3943
INPUTS_TARGET_BACKSTAGE_VERSION: ${{ inputs.target-backstage-version }}
4044
INPUTS_IMAGE_REPOSITORY_PREFIX: ${{ inputs.image-repository-prefix }}
45+
INPUTS_IMAGE_TAG_PREFIX: ${{ inputs.image-tag-prefix }}
4146
run: |
4247
npm install
4348
node validate-metadata.ts
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: extensions.backstage.io/v1alpha1
2+
kind: Package
3+
metadata:
4+
name: test-plugin
5+
namespace: rhdh
6+
spec:
7+
packageName: '@test-org/plugin-test'
8+
dynamicArtifact: oci://ghcr.io/test-org/test-repo/test-org-plugin-test:bs_1.40.0__1.0.0!test-org-plugin-test
9+
version: 1.0.0
10+
backstage:
11+
role: frontend-plugin
12+
supportedVersions: 1.42.5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
plugins/test-plugin:
2+
plugins/test-backend:

validate-metadata/validate-metadata.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const OVERLAY_ROOT = process.env.INPUTS_OVERLAY_ROOT;
7878
const PLUGINS_ROOT = process.env.INPUTS_PLUGINS_ROOT;
7979
const TARGET_BACKSTAGE_VERSION = process.env.INPUTS_TARGET_BACKSTAGE_VERSION;
8080
const IMAGE_REPOSITORY_PREFIX = process.env.INPUTS_IMAGE_REPOSITORY_PREFIX || '';
81+
const IMAGE_TAG_PREFIX = process.env.INPUTS_IMAGE_TAG_PREFIX || '';
8182

8283
// Validate required environment variables
8384
if (!OVERLAY_ROOT) {
@@ -360,19 +361,27 @@ function validateOciReference(
360361
packageName: string
361362
): void {
362363
const { reference, tag } = parseOciReference(dynamicArtifact);
363-
const expectedTag = `bs_${TARGET_BACKSTAGE_VERSION}__${pluginVersion}`;
364364

365-
if (tag !== expectedTag) {
366-
errors.push({
367-
kind: 'mismatch',
368-
file: metadataFilePath,
369-
field: 'dynamicArtifact.tag',
370-
expected: expectedTag,
371-
actual: tag,
372-
message: `OCI tag mismatch: expected "${expectedTag}" but got "${tag}"`
373-
});
365+
// When the export uses next__ (workspace is backstage-incompatible),
366+
// skip the tag prefix check -- the metadata tag is a remnant from the
367+
// last compatible state and will self-correct on the next compatible update.
368+
if (IMAGE_TAG_PREFIX !== 'next__') {
369+
const expectedTag = IMAGE_TAG_PREFIX
370+
? `${IMAGE_TAG_PREFIX}${pluginVersion}`
371+
: `bs_${TARGET_BACKSTAGE_VERSION}__${pluginVersion}`;
372+
373+
if (tag !== expectedTag) {
374+
errors.push({
375+
kind: 'mismatch',
376+
file: metadataFilePath,
377+
field: 'dynamicArtifact.tag',
378+
expected: expectedTag,
379+
actual: tag,
380+
message: `OCI tag mismatch: expected "${expectedTag}" but got "${tag}"`
381+
});
382+
}
374383
}
375-
384+
376385
// Validate reference format: <image-repository-prefix>/<package name with @ and / replaced by ->
377386
if (!IMAGE_REPOSITORY_PREFIX) {
378387
return;

0 commit comments

Comments
 (0)