Data contracts WIP #1
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
| name: contracts-publish-sdk (CI-first, g8 + optional avsc) | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| organization: | ||
| description: "Scala organization (e.g., com.acme)" | ||
| required: true | ||
| package: | ||
| description: "Base package (e.g., com.acme.contracts)" | ||
| required: true | ||
| domain: | ||
| description: "Domain name (e.g., sales)" | ||
| required: true | ||
| entity: | ||
| description: "Entity name (e.g., TransactionsV1)" | ||
| required: true | ||
| version: | ||
| description: "SemVer (e.g., 1.0.0)" | ||
| required: true | ||
| fieldsJson: | ||
| description: "Fields array JSON (e.g., [{\"name\":\"id\",\"type\":\"string\",\"nullable\":false}])" | ||
| required: true | ||
| generateAvsc: | ||
| description: "Generate .avsc artifact" | ||
| required: false | ||
| default: 'true' | ||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Java (Temurin) | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '17' | ||
| - name: Render case class (g8 scaffold) | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| ORG='${{ inputs.organization }}' | ||
| PKG='${{ inputs.package }}' | ||
| DOMAIN='${{ inputs.domain }}' | ||
| ENTITY='${{ inputs.entity }}' | ||
| VERSION='${{ inputs.version }}' | ||
| FJSON='${{ inputs.fieldsJson }}' | ||
| # Minimal proof-of-concept: create a case class file under modules/contracts-sdk/src/main/scala/ | ||
| BASE="modules/contracts-sdk/src/main/scala/"$(echo "$PKG" | tr '.' '/')"/$DOMAIN" | ||
| mkdir -p "$BASE" | ||
| FILE="$BASE/${ENTITY}.scala" | ||
| echo "Generating $FILE" | ||
| # Parse fieldsJson minimally (name/type/nullable) — in production use a small script | ||
| # Here we just hardwrite a simple two-field sample for safety | ||
| cat > "$FILE" <<EOF | ||
| package $PKG.$DOMAIN | ||
| final case class $ENTITY( | ||
| id: String, | ||
| amount: Double | ||
| ) | ||
| object ${ENTITY}Contract { | ||
| type Repr = shapeless.LabelledGeneric[$ENTITY]#Repr | ||
| } | ||
| EOF | ||
| - name: Optionally render .avsc (flag) | ||
| if: ${{ inputs.generateAvsc == 'true' }} | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| DOMAIN='${{ inputs.domain }}' | ||
| ENTITY='${{ inputs.entity }}' | ||
| VERSION='${{ inputs.version }}' | ||
| OUT="contracts/avro/${DOMAIN}" | ||
| mkdir -p "$OUT" | ||
| AVSC="$OUT/${ENTITY}.v${VERSION}.avsc" | ||
| echo "Writing $AVSC" | ||
| cat > "$AVSC" <<AV | ||
| { | ||
| "type": "record", | ||
| "name": "$ENTITY", | ||
| "namespace": "${{ inputs.package }}.$DOMAIN", | ||
| "fields": [ | ||
| { "name": "id", "type": "string" }, | ||
| { "name": "amount", "type": "double" } | ||
| ] | ||
| } | ||
| AV | ||
| - name: Compile SDK | ||
| run: sbt -no-colors "contracts-sdk/compile" | ||
| - name: (Optional) Publish SDK (stub) | ||
| if: ${{ false }} | ||
| run: echo "Publish step here (Maven/GitHub Packages)" | ||