Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build & Publish on Schema Change

on:
push:
branches:
- main
paths:
- "schemas/**"
- "java/**"
- "java/pom.xml"
workflow_dispatch:

jobs:
build-java:
name: Build and Publish Java Package
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

defaults:
run:
working-directory: java

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
cache: "maven"
server-id: "github"
server-username: "${{ github.actor }}"
server-password: "${{ secrets.GITHUB_TOKEN }}"

- name: Read Schema Version
id: schema
run: |
SCHEMA_VERSION=$(cat ../schemas/VERSION | tr -d '\n')
echo "Using schema version: $SCHEMA_VERSION"
echo "schema_version=$SCHEMA_VERSION" >> $GITHUB_OUTPUT

- name: Read Implementation Version
id: impl
run: |
IMPL_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Using implementation version: $IMPL_VERSION"
echo "impl_version=$IMPL_VERSION" >> $GITHUB_OUTPUT

- name: Create Combined Version
id: version
run: |
COMBINED_VERSION="${{ steps.impl.outputs.impl_version }}-schema-${{ steps.schema.outputs.schema_version }}"
echo "Using combined version: $COMBINED_VERSION"
echo "combined_version=$COMBINED_VERSION" >> $GITHUB_OUTPUT

- name: Build with Maven
run: mvn clean package

- name: Rename Artifacts for GitHub Release
run: |
mv target/pacts-${{ steps.impl.outputs.impl_version }}.jar target/pacts-${{ steps.version.outputs.combined_version }}.jar
mv target/pacts-${{ steps.impl.outputs.impl_version }}-sources.jar target/pacts-${{ steps.version.outputs.combined_version }}-sources.jar
mv target/pacts-${{ steps.impl.outputs.impl_version }}-javadoc.jar target/pacts-${{ steps.version.outputs.combined_version }}-javadoc.jar

- name: Publish to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
run: mvn deploy --batch-mode

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: java-v${{ steps.version.outputs.combined_version }}
name: Java Package v${{ steps.version.outputs.combined_version }}
body: |
Java package release for version ${{ steps.version.outputs.combined_version }}

Changes:
- Implementation version: ${{ steps.impl.outputs.impl_version }}
- Schema version: ${{ steps.schema.outputs.schema_version }}
files: |
java/target/pacts-${{ steps.version.outputs.combined_version }}.jar
java/target/pacts-${{ steps.version.outputs.combined_version }}-sources.jar
java/target/pacts-${{ steps.version.outputs.combined_version }}-javadoc.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89 changes: 89 additions & 0 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build & Publish Rust Crate

on:
push:
branches:
- main
paths:
- "schemas/**"
- "rust/**"
- "rust/Cargo.toml"
workflow_dispatch:

jobs:
build-rust:
name: Build and Release Rust Crate
runs-on: ubuntu-latest
permissions:
contents: write

defaults:
run:
working-directory: rust

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable

- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Read Schema Version
id: schema
run: |
SCHEMA_VERSION=$(cat ../schemas/VERSION | tr -d '\n')
echo "Using schema version: $SCHEMA_VERSION"
echo "schema_version=$SCHEMA_VERSION" >> $GITHUB_OUTPUT

- name: Read Implementation Version
id: impl
run: |
IMPL_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "Using implementation version: $IMPL_VERSION"
echo "impl_version=$IMPL_VERSION" >> $GITHUB_OUTPUT

- name: Create Combined Version
id: version
run: |
COMBINED_VERSION="${{ steps.impl.outputs.impl_version }}+schema.${{ steps.schema.outputs.schema_version }}"
echo "Using combined version: $COMBINED_VERSION"
echo "combined_version=$COMBINED_VERSION" >> $GITHUB_OUTPUT

- name: Build
run: cargo build --release

- name: Run tests
run: cargo test

- name: Rename staticlib for GitHub Release
run: |
cp target/release/libpacts.a target/release/libpacts-${{ steps.version.outputs.combined_version }}.a

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: rust-v${{ steps.version.outputs.combined_version }}
name: Rust Crate v${{ steps.version.outputs.combined_version }}
body: |
Rust crate release for version ${{ steps.version.outputs.combined_version }}

Changes:
- Implementation version: ${{ steps.impl.outputs.impl_version }}
- Schema version: ${{ steps.schema.outputs.schema_version }}
files: |
rust/target/release/libpacts-${{ steps.version.outputs.combined_version }}.a
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.hydrius</groupId>
<artifactId>pacts</artifactId>
<version>0.0.4</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Pacts</name>
Expand All @@ -22,6 +22,7 @@
<targetPath>schemas</targetPath>
<includes>
<include>**/*.json</include>
<include>VERSION</include>
</includes>
</resource>
</resources>
Expand All @@ -31,6 +32,7 @@
<targetPath>schemas</targetPath>
<includes>
<include>**/*.json</include>
<include>VERSION</include>
</includes>
</testResource>
</testResources>
Expand Down
6 changes: 4 additions & 2 deletions java/src/main/java/net/hydrius/pacts/core/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import net.hydrius.pacts.model.Envelope;
import net.hydrius.pacts.model.Header;

Expand Down Expand Up @@ -70,7 +70,7 @@ public ValidationResult validate(Envelope envelope) {
ValidationResult dataValidation = validateData(envelope.getData(), schema);
errors.addAll(dataValidation.getErrors());
}

}

} catch (Exception e) {
Expand All @@ -97,6 +97,8 @@ private boolean validateType(JsonNode data, String expectedType) {
data.isTextual();
case "number" ->
data.isNumber();
case "integer" ->
data.isIntegralNumber();
case "boolean" ->
data.isBoolean();
case "null" ->
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pacts"
version = "0.0.3"
version = "0.0.4"
edition = "2021"
build = "build.rs"

Expand Down
12 changes: 11 additions & 1 deletion rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ fn main() {
// Get the directory where the build script is located
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let schemas_dir = Path::new(&manifest_dir).parent().unwrap().join("schemas");
let version_file = schemas_dir.join("VERSION");

// Tell Cargo to rerun this build script if the schemas directory changes
println!("cargo:rerun-if-changed={}", schemas_dir.display());

// Verify schemas directory exists
// Pass schema path into build
if schemas_dir.exists() {
println!("cargo:rustc-env=SCHEMAS_DIR={}", schemas_dir.display());
}

// Read schema version and expose it
if version_file.exists() {
let version = fs::read_to_string(version_file)
.expect("Failed to read schema version file")
.trim()
.to_string();
println!("cargo:rustc-env=SCHEMA_VERSION={}", version);
}
}
1 change: 1 addition & 0 deletions rust/src/core/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl Validator {
"array" => data.is_array(),
"string" => data.is_string(),
"number" => data.is_number(),
"integer" => data.is_i64() || data.is_u64(),
"boolean" => data.is_boolean(),
"null" => data.is_null(),
_ => true,
Expand Down
1 change: 1 addition & 0 deletions schemas/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.2
54 changes: 45 additions & 9 deletions schemas/bees/v1/inventory/inventory_item.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "inventory_item.json",
"type": "object",
"title": "InventoryItem",
"description": "An item in the inventory",
"deprecated": false,
"properties": {
"slot": {
"type": "number",
"description": "The inventory slot number"
"type": "integer",
"description": "The inventory slot number",
"minimum": 0,
"examples": [
0,
1,
4,
20
]
},
"material": {
"type": "string",
"description": "The material/block type of the item"
"description": "The material/block type of the item",
"examples": [
"minecraft:diamond_sword",
"minecraft:dirt"
]
},
"amount": {
"type": "number",
"description": "The quantity of the item"
"description": "The quantity of the item",
"minimum": 1,
"examples": [
64,
32
]
},
"enchantment_data": {
"type": "array",
"type": [
"array",
"null"
],
"description": "Array of enchantments applied to the item",
"items": {
"type": "object",
"properties": {
"enchantment_id": {
"type": "string",
"description": "The enchantment identifier"
"description": "The enchantment identifier",
"examples": [
"minecraft:sharpness",
"minecraft:fire_aspect"
]
},
"enchantment_level": {
"type": "number",
"description": "The level of the enchantment"
"description": "The level of the enchantment",
"minimum": 1,
"examples": [
3,
5
]
}
},
"required": [
Expand All @@ -35,7 +68,10 @@
}
},
"nbt_data": {
"type": "object",
"type": [
"object",
"null"
],
"description": "Custom NBT data for the item",
"properties": {
"id": {
Expand All @@ -61,7 +97,7 @@
"type": "object",
"properties": {
"slot": {
"type": "number",
"type": "integer",
"description": "Nectar slot number"
},
"statistics": {
Expand Down
Loading