-
-
Notifications
You must be signed in to change notification settings - Fork 191
Ship versioned native XSD schemas with governance CI #6528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+763
−32
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
69108b3
[feature] Add schema governance CI; enforce XSD @version bumps on sem…
duncdrum 05904fd
[feature] Add schemaVersion attribute to canonical config instances; …
duncdrum b867e64
[feature] Ship native XSD schemas in all distribution layouts
duncdrum fe93ede
[ignore] Simplify SchemaVersionSyncTest map init to Map.of
duncdrum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env bash | ||
| # Pure git plumbing for schema governance — everything else (pairing, | ||
| # version comparison, the GitHub annotations, failing the build) happens in | ||
| # a single Saxon XSLT 2.0 transform (schema/governance.xsl) driven by | ||
| # `mvn xml:transform@schema-governance`. This script's only job is to put | ||
| # the git state that transform needs onto disk as plain files/XML, so the | ||
| # stylesheet never has to shell out itself. | ||
| set -euo pipefail | ||
| cd "$(git rev-parse --show-toplevel)" | ||
|
|
||
| WORKSPACE="${1:?workspace required}" | ||
| OUT="${2:-${WORKSPACE}/target/governance}" | ||
| mkdir -p "${OUT}/base" | ||
|
|
||
| if [[ -n "${GITHUB_BASE_REF:-}" ]]; then | ||
| git fetch --depth=1 origin "${GITHUB_BASE_REF}" 2>/dev/null || true | ||
| BASE="$(git merge-base HEAD "origin/${GITHUB_BASE_REF}")" | ||
| elif [[ -n "${GITHUB_EVENT_BEFORE:-}" && "${GITHUB_EVENT_BEFORE}" != "0000000000000000000000000000000000000000" ]]; then | ||
| BASE="${GITHUB_EVENT_BEFORE}" | ||
| else | ||
| BASE="$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD)" | ||
| fi | ||
|
|
||
| # Every tracked schema/*.xsd's content as it existed at BASE, one file per | ||
| # schema named after its basename. A missing file at $OUT/base/<name> means | ||
| # "didn't exist at BASE" (new schema) — governance.xsl checks for that with | ||
| # doc-available() rather than this script trying to distinguish "new file" | ||
| # from "tool failure" itself. | ||
| git ls-tree -r --name-only HEAD -- schema | grep '\.xsd$' | while read -r f; do | ||
| out="${OUT}/base/$(basename "${f}")" | ||
| git show "${BASE}:${f}" > "${out}" 2>/dev/null || rm -f "${out}" | ||
| done | ||
|
|
||
| # One path per line; governance.xsl reads this with unparsed-text() + tokenize(), | ||
| # so no XML-escaping of path characters is needed anywhere in this pipeline. | ||
| git diff --name-only "${BASE}" -- \ | ||
| schema \ | ||
| exist-distribution/src/main/config \ | ||
| exist-jetty-config/src/main/resources/webapp/WEB-INF/controller-config.xml \ | ||
| exist-core/src/main/resources/org/exist/util/mime-types.xml \ | ||
| exist-core/src/main/java/org/exist/util/SchemaVersion.java \ | ||
| > "${OUT}/changed.txt" 2>/dev/null || true | ||
|
|
||
| cat > "${OUT}/context.xml" <<EOF | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <g:ctx xmlns:g="http://exist-db.org/ns/schema-governance" | ||
| workspace="${WORKSPACE}" | ||
| base-dir="${OUT}/base" | ||
| base-ref="${BASE}" | ||
| changed-file="${OUT}/changed.txt"/> | ||
| EOF | ||
|
|
||
| echo "Governance context: ${OUT}/context.xml (base ${BASE})" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Schema checks | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'schema/**' | ||
| - 'exist-distribution/src/main/config/**' | ||
| - 'exist-jetty-config/src/main/resources/webapp/WEB-INF/controller-config.xml' | ||
|
line-o marked this conversation as resolved.
|
||
| - 'exist-core/src/main/resources/org/exist/util/mime-types.xml' | ||
| - 'exist-core/src/main/java/org/exist/util/SchemaVersion.java' | ||
| push: | ||
| branches: [develop] | ||
| paths: | ||
| - 'schema/**' | ||
| - 'exist-distribution/src/main/config/**' | ||
| - 'exist-jetty-config/src/main/resources/webapp/WEB-INF/controller-config.xml' | ||
|
line-o marked this conversation as resolved.
|
||
| - 'exist-core/src/main/resources/org/exist/util/mime-types.xml' | ||
| - 'exist-core/src/main/java/org/exist/util/SchemaVersion.java' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| MAVEN_OPTS: -DtrimStackTrace=false | ||
| DEV_JDK: '21' | ||
|
|
||
| jobs: | ||
| schema: | ||
| name: Native XSD checks | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: temurin | ||
| java-version: ${{ env.DEV_JDK }} | ||
|
|
||
| - uses: ./.github/actions/maven-cache | ||
|
|
||
| - name: Validate canonical templates against XSD | ||
| run: mvn -V -B --no-transfer-progress validate -Ddependency-check.skip=true -Ddocker=false | ||
|
|
||
| - name: Prepare governance context | ||
| env: | ||
| GITHUB_BASE_REF: ${{ github.base_ref }} | ||
| GITHUB_EVENT_BEFORE: ${{ github.event.before }} | ||
| run: | | ||
| chmod +x .github/scripts/prepare-governance-context.sh | ||
| .github/scripts/prepare-governance-context.sh "${{ github.workspace }}" | ||
|
|
||
| - name: Run schema governance (XSLT 2.0 / Saxon) | ||
| run: mvn -N -B --no-transfer-progress xml:transform@schema-governance -Ddependency-check.skip=true -Ddocker=false | ||
|
|
||
| - name: Verify SchemaVersion.java matches XSD versions | ||
| run: mvn -B --no-transfer-progress test -pl exist-core -Dtest=org.exist.util.SchemaVersionSyncTest -Ddependency-check.skip=true -Ddocker=false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
exist-core/src/main/java/org/exist/util/SchemaVersion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * eXist-db Open Source Native XML Database | ||
| * Copyright (C) 2001 The eXist-db Authors | ||
| * | ||
| * info@exist-db.org | ||
| * http://www.exist-db.org | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| */ | ||
| package org.exist.util; | ||
|
|
||
| import org.apache.logging.log4j.Logger; | ||
| import org.w3c.dom.Element; | ||
|
|
||
| /** | ||
| * Optional {@code schemaVersion} on native config instance documents — mirrors | ||
| * {@code xs:schema/@version} on the paired XSD (native schema semver, not eXist product version). | ||
| */ | ||
| public final class SchemaVersion { | ||
|
|
||
| public static final String ATTRIBUTE = "schemaVersion"; | ||
|
|
||
| /** Paired {@code xs:schema/@version} values for canonical templates (keep in sync with {@code schema/*.xsd}). */ | ||
| public static final String CONF = "2.1.1"; | ||
| public static final String COLLECTION_XCONF = "1.2.1"; | ||
| public static final String DESCRIPTOR = "1.2.1"; | ||
| public static final String MIME_TYPES = "1.2.1"; | ||
| public static final String CONTROLLER_CONFIG = "1.1.1"; | ||
|
|
||
| private SchemaVersion() { | ||
| } | ||
|
|
||
| /** | ||
| * Log when {@code schemaVersion} is missing (legacy) or differs from the schema version this build expects. | ||
| */ | ||
| public static void logDocumentVersion(final Logger log, final Element root, | ||
| final String expectedVersion, final String documentDescription) { | ||
| logDocumentVersion(log, root != null ? root.getAttribute(ATTRIBUTE) : "", expectedVersion, documentDescription); | ||
| } | ||
|
|
||
| /** | ||
| * SAX variant when only the attribute value is available. | ||
| */ | ||
| public static void logDocumentVersion(final Logger log, final String declaredVersion, | ||
| final String expectedVersion, final String documentDescription) { | ||
| if (declaredVersion == null || declaredVersion.isEmpty()) { | ||
| log.debug("{} has no {} attribute (legacy document)", documentDescription, ATTRIBUTE); | ||
| return; | ||
| } | ||
| if (!declaredVersion.equals(expectedVersion)) { | ||
| log.warn("{} declares {}=\"{}\" but this eXist build expects \"{}\"", | ||
| documentDescription, ATTRIBUTE, declaredVersion, expectedVersion); | ||
| } else { | ||
| log.debug("{} {}=\"{}\"", documentDescription, ATTRIBUTE, declaredVersion); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.