From 421c49c9bf0b1e963b45b64f03fac9f0faabd3c9 Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Tue, 25 Feb 2025 14:14:06 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Backstage=20Entity=20Validati?= =?UTF-8?q?on=20Workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template_backstage_entity_validation.yml | 36 +++++++++ README.md | 16 ++++ schemas/custom-catalog-info.schema.json | 78 +++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 .github/workflows/template_backstage_entity_validation.yml create mode 100644 schemas/custom-catalog-info.schema.json diff --git a/.github/workflows/template_backstage_entity_validation.yml b/.github/workflows/template_backstage_entity_validation.yml new file mode 100644 index 00000000..59bad253 --- /dev/null +++ b/.github/workflows/template_backstage_entity_validation.yml @@ -0,0 +1,36 @@ +name: Backstage Entity Validation + +on: + workflow_call: + inputs: + path: + default: "catalog-info.yaml" + required: false + type: string + custom-schema-url: + default: https://raw.githubusercontent.com/Staffbase/gha-workflows/refs/heads/main/schemas/custom-catalog-info.schema.json + required: false + type: string + +jobs: + validation: + name: Validate Backstage Entities + runs-on: ubuntu-24.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4.2.2 + + # Download the schema file + - name: Download custom schema file + if: ${{ inputs.custom-schema-url }} != "" + run: | + curl -o custom-catalog-info.schema.json ${{ inputs.custom-schema-url }} + # Set the schema file location + echo "schema-file-location=custom-catalog-info.schema.json" >> $GITHUB_OUTPUT + + - name: Validate Backstage Entities + uses: RoadieHQ/backstage-entity-validator@v0.5.0 + with: + path: ${{ inputs.path }} + validationSchemaFileLocation: custom-catalog-info.schema.json diff --git a/README.md b/README.md index 5f44b380..efb5be96 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,22 @@ jobs: +### Backstage Entity Validation + +
+The action can be used to validate the Backstage entity files. + +```yml +name: Backstage Entity Validation +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + validation: + uses: Staffbase/gha-workflows/.github/workflows/template_backstage_entity_validation.yml@v7.2.0 +``` + ### Changeset Check
diff --git a/schemas/custom-catalog-info.schema.json b/schemas/custom-catalog-info.schema.json new file mode 100644 index 00000000..8650b91a --- /dev/null +++ b/schemas/custom-catalog-info.schema.json @@ -0,0 +1,78 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "ApiV1alpha1", + "description": "An API describes an interface that can be exposed by a component. The API can be defined in different formats, like OpenAPI, AsyncAPI, GraphQL, gRPC, or other formats.", + "examples": [ + { + "apiVersion": "backstage.io/v1alpha1", + "kind": "API", + "metadata": { + "name": "artist-api", + "description": "Retrieve artist details", + "labels": { + "product_name": "Random value Generator" + }, + "annotations": { + "docs": "https://github.com/..../tree/develop/doc" + } + }, + "spec": { + "type": "openapi", + "lifecycle": "production", + "system": "artist-engagement-portal", + "definition": "openapi: \"3.0.0\"\ninfo:..." + } + } + ], + "allOf": [ + { + "$ref": "Entity" + }, + { + "type": "object", + "required": ["spec"], + "properties": { + "apiVersion": { + "enum": ["backstage.io/v1alpha1", "backstage.io/v1beta1"] + }, + "kind": { + "enum": ["API"] + }, + "spec": { + "type": "object", + "required": ["type", "lifecycle", "definition"], + "properties": { + "type": { + "type": "string", + "description": "The type of the API definition.", + "examples": ["openapi", "asyncapi", "graphql", "grpc", "trpc"], + "minLength": 1 + }, + "lifecycle": { + "type": "string", + "description": "The lifecycle state of the API.", + "examples": ["experimental", "production", "deprecated"], + "minLength": 1 + }, + "owner": { + "type": "string", + "description": "An entity reference to the owner of the API.", + "examples": ["artist-relations-team", "user:john.johnson"], + "minLength": 1 + }, + "system": { + "type": "string", + "description": "An entity reference to the system that the API belongs to.", + "minLength": 1 + }, + "definition": { + "type": "string", + "description": "The definition of the API, based on the format defined by the type.", + "minLength": 1 + } + } + } + } + } + ] +}