diff --git a/.github/workflows/pr-drools-backward-compatibility.yml b/.github/workflows/pr-drools-backward-compatibility.yml new file mode 100644 index 000000000000..3673ff73117d --- /dev/null +++ b/.github/workflows/pr-drools-backward-compatibility.yml @@ -0,0 +1,50 @@ +name: Drools Backward Compatibility + +on: + pull_request: + paths-ignore: + - 'LICENSE' + - '**/.gitignore' + - '**.md' + - '**.adoc' + - '*.txt' + - 'docsimg/**' + - '.ci/jenkins/**' + +jobs: + drools-build: + concurrency: + group: pr-drools-backward-compatibility_${{ matrix.os }}_${{ matrix.java-version }}_${{ matrix.maven-version }}_${{ github.head_ref }} + cancel-in-progress: true + timeout-minutes: 120 + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + java-version: [11] + maven-version: ['3.8.7'] + fail-fast: false + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / Java-${{ matrix.java-version }} / Maven-${{ matrix.maven-version }} + steps: + - name: Clean Disk Space + uses: kiegroup/kie-ci/.ci/actions/ubuntu-disk-space@main + if: ${{ matrix.os == 'ubuntu-latest' }} + - name: Support long paths + if: ${{ matrix.os == 'windows-latest' }} + uses: kiegroup/kie-ci/.ci/actions/long-paths@main + - name: Checkout + uses: actions/checkout@v3 + - name: Java and Maven Setup + uses: kiegroup/kie-ci/.ci/actions/maven@main + with: + java-version: ${{ matrix.java-version }} + maven-version: ${{ matrix.maven-version }} + cache-key-prefix: ${{ runner.os }}-${{ matrix.java-version }}-maven${{ matrix.maven-version }} + - name: Build Drools + run: mvn -B clean install -DskipTests + - name: Backward Compatibility Test with previous minor version + run: | + CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + PREVIOUS_VERSION=$(script/utils/get_previous_version.sh $CURRENT_VERSION) + mvn -B clean install --file drools-reference-examples/pom.xml -Preference -Dreference.kjar.drools.version=$PREVIOUS_VERSION + shell: bash diff --git a/bom/drools-bom/pom.xml b/bom/drools-bom/pom.xml index 7bc1511fc737..45feef752f83 100644 --- a/bom/drools-bom/pom.xml +++ b/bom/drools-bom/pom.xml @@ -1026,6 +1026,41 @@ ${project.version} sources + + + org.drools + drools-reference-examples-common + ${project.version} + + + org.drools + drools-reference-examples-common + ${project.version} + sources + + + org.drools + drools-reference-examples-kjar + ${project.version} + + + org.drools + drools-reference-examples-kjar + ${project.version} + sources + + + org.drools + drools-reference-examples-runner + ${project.version} + + + org.drools + drools-reference-examples-runner + ${project.version} + sources + + org.drools drools-docs diff --git a/drools-reference-examples/README.md b/drools-reference-examples/README.md new file mode 100644 index 000000000000..b47f8f0bb05e --- /dev/null +++ b/drools-reference-examples/README.md @@ -0,0 +1,11 @@ +`drools-reference-examples` contains internal reference examples which can be used for smoke tests, backward compatibility tests, etc. + +To run the project, enable the `reference` profile: + + cd drools-reference-examples + mvn clean install -Preference + +By default, kjar projects are built with the current project version of `kie-maven-plugin`. To build with a specific version of `kie-maven-plugin`, use `reference.kjar.drools.version` property: + + mvn clean install -Preference -Dreference.kjar.drools.version=8.39.0.Final + diff --git a/drools-reference-examples/drools-reference-examples-common/pom.xml b/drools-reference-examples/drools-reference-examples-common/pom.xml new file mode 100644 index 000000000000..8d5511ecc310 --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-common/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + org.drools + drools-reference-examples + 8.43.0-SNAPSHOT + ../pom.xml + + + org.drools + drools-reference-examples-common + + Drools reference examples :: Common + Pojo classes for kjar and runner + + + org.drools.reference.examples.common + + + diff --git a/drools-reference-examples/drools-reference-examples-common/src/main/java/org/drools/reference/examples/helloworld/Message.java b/drools-reference-examples/drools-reference-examples-common/src/main/java/org/drools/reference/examples/helloworld/Message.java new file mode 100644 index 000000000000..c0a3c27d5c5a --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-common/src/main/java/org/drools/reference/examples/helloworld/Message.java @@ -0,0 +1,47 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.reference.examples.helloworld; + +public class Message { + + public static final int HELLO = 0; + public static final int GOODBYE = 1; + + private String message; + + private int status; + + public Message() { + + } + + public String getMessage() { + return this.message; + } + + public void setMessage(final String message) { + this.message = message; + } + + public int getStatus() { + return this.status; + } + + public void setStatus(final int status) { + this.status = status; + } +} diff --git a/drools-reference-examples/drools-reference-examples-kjar/pom.xml b/drools-reference-examples/drools-reference-examples-kjar/pom.xml new file mode 100644 index 000000000000..c17771602eac --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-kjar/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.drools + drools-reference-examples + 8.43.0-SNAPSHOT + ../pom.xml + + + org.drools + drools-reference-examples-kjar + kjar + + Drools reference examples :: kjar + Reference example kjar + + + org.drools.reference.examples.kjar + + + + + org.drools + drools-reference-examples-common + + + + + org.drools + drools-engine + ${reference.kjar.drools.version} + + + org.drools + drools-model-compiler + ${reference.kjar.drools.version} + + + + ch.qos.logback + logback-classic + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + + no-managed-deps + none + + + + + org.kie + kie-maven-plugin + ${reference.kjar.drools.version} + true + + + + + diff --git a/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/META-INF/kmodule.xml b/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 000000000000..5f956aee86d0 --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/org/drools/reference/examples/helloworld/HelloWorld.drl b/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/org/drools/reference/examples/helloworld/HelloWorld.drl new file mode 100644 index 000000000000..72ffe6194434 --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-kjar/src/main/resources/org/drools/reference/examples/helloworld/HelloWorld.drl @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.reference.examples.helloworld + +import org.drools.reference.examples.helloworld.Message; + +global java.util.List list + +rule "Hello World" + dialect "mvel" + when + m : Message( status == Message.HELLO, message : message ) + then + System.out.println( message ); + list.add( message ); + modify ( m ) { message = "Goodbye cruel world", + status = Message.GOODBYE }; +end + +rule "Good Bye" + dialect "java" + when + Message( status == Message.GOODBYE, message : message ) + then + System.out.println( message ); + list.add( message ); +end diff --git a/drools-reference-examples/drools-reference-examples-runner/pom.xml b/drools-reference-examples/drools-reference-examples-runner/pom.xml new file mode 100644 index 000000000000..66de16a16cdc --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-runner/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + org.drools + drools-reference-examples + 8.43.0-SNAPSHOT + ../pom.xml + + + org.drools + drools-reference-examples-runner + + Drools reference examples :: runner + Reference example runner + + + org.drools.reference.examples.runner + + + + + org.drools + drools-reference-examples-common + + + org.drools + drools-reference-examples-kjar + test + + + org.drools + drools-engine + test + + + org.drools + drools-xml-support + test + + + org.kie + kie-ci + test + + + ch.qos.logback + logback-classic + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core + test + + + + diff --git a/drools-reference-examples/drools-reference-examples-runner/src/test/java/org/drools/reference/examples/helloworld/HelloWorldTest.java b/drools-reference-examples/drools-reference-examples-runner/src/test/java/org/drools/reference/examples/helloworld/HelloWorldTest.java new file mode 100644 index 000000000000..63f47628fea7 --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-runner/src/test/java/org/drools/reference/examples/helloworld/HelloWorldTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.drools.reference.examples.helloworld; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.kie.api.KieServices; +import org.kie.api.builder.ReleaseId; +import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.KieSession; + +import static org.assertj.core.api.Assertions.assertThat; + +class HelloWorldTest { + + @Test + void helloWorld() { + KieServices kieServices = KieServices.get(); + ReleaseId releaseId = kieServices.newReleaseId("org.drools", "drools-reference-examples-kjar", "8.43.0-SNAPSHOT"); + KieContainer kieContainer = kieServices.newKieContainer(releaseId); + KieSession kieSession = kieContainer.newKieSession("HelloWorldKS"); + + List list = new ArrayList<>(); + kieSession.setGlobal( "list", list ); + + Message message = new Message(); + message.setMessage( "Hello World" ); + message.setStatus( Message.HELLO ); + kieSession.insert( message ); + + kieSession.fireAllRules(); + + assertThat(list).containsExactly("Hello World", "Goodbye cruel world"); + + kieSession.dispose(); + } + + +} diff --git a/drools-reference-examples/drools-reference-examples-runner/src/test/resources/logback.xml b/drools-reference-examples/drools-reference-examples-runner/src/test/resources/logback.xml new file mode 100644 index 000000000000..0d8dcdc24394 --- /dev/null +++ b/drools-reference-examples/drools-reference-examples-runner/src/test/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + + %date{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%method:%line - %msg%n + + + + + + + + + + + + + diff --git a/drools-reference-examples/pom.xml b/drools-reference-examples/pom.xml new file mode 100644 index 000000000000..4bc527a3cc3d --- /dev/null +++ b/drools-reference-examples/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.kie + drools-build-parent + 8.43.0-SNAPSHOT + ../build-parent/pom.xml + + + org.drools + drools-reference-examples + pom + + Drools reference examples + Reference examples for smoke tests and backward compatibility tests + + + org.drools.reference.examples + + ${project.version} + + + + + default + + true + + + + + reference + + drools-reference-examples-common + drools-reference-examples-kjar + drools-reference-examples-runner + + + + + diff --git a/pom.xml b/pom.xml index 3535b5af675c..97d67c216dd1 100644 --- a/pom.xml +++ b/pom.xml @@ -204,6 +204,7 @@ jpmml-migration-recipe drools-reliability drools-drlonyaml-parent + drools-reference-examples diff --git a/script/utils/get_previous_version.sh b/script/utils/get_previous_version.sh new file mode 100755 index 000000000000..f176c486e2f4 --- /dev/null +++ b/script/utils/get_previous_version.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +current_version="$1" +major=$(echo "$current_version" | cut -d'.' -f1) +minor=$(echo "$current_version" | cut -d'.' -f2) +micro=$(echo "$current_version" | cut -d'.' -f3 | cut -d'-' -f1) + +# Decrement the minor version. If minor is 0, then we don't decrement +if [ "$minor" -gt 0 ]; then + previous_minor=$((minor - 1)) +else + previous_minor=0 +fi + +# Construct the previous version +previous_version="$major.$previous_minor.0.Final" +echo "$previous_version"