From 74f624b2dcefc0b20ffb7ff287f91e676f5ddc15 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 9 Jul 2024 16:24:54 -0500 Subject: [PATCH] Add Maven build test A new test has been added to build the code with Maven and Ant then verify that the artifacts are identical. In the future the support for Ant will be dropped. The existing RPM test has been updated to verify that the artifacts built with XMvn and shipped in RPM are identical to the ones built directly with Maven. The build.sh has been updated to provide options to specify the paths to SLF4J and JSS libraries. --- .github/workflows/build-tests.yml | 183 +++++++++++++++++++++++------- build.sh | 33 +++++- 2 files changed, 171 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build-tests.yml b/.github/workflows/build-tests.yml index e87920e..4715995 100644 --- a/.github/workflows/build-tests.yml +++ b/.github/workflows/build-tests.yml @@ -25,8 +25,122 @@ jobs: wait-interval: 30 if: github.event_name == 'pull_request' - build-test: - name: Build Test + maven-test: + name: Maven Test + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'adopt' + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y maven ant + + # get dependencies from Maven + mvn --batch-mode dependency:copy-dependencies + + - name: Build with Maven + run: mvn --batch-mode package + + - name: Build with Ant + run: | + SLF4J_LIB=$(find . -name "slf4j-api-*.jar" -print -quit) + echo "SLF4J_LIB: $SLF4J_LIB" + + JSS_LIB=$(find . -name "jss-base-*.jar" -print -quit) + echo "JSS_LIB: $JSS_LIB" + + ./build.sh \ + --slf4j-lib=$SLF4J_LIB \ + --jss-lib=$JSS_LIB \ + dist + + - name: Compare ldapjdk.jar + run: | + jar tvf java-sdk/ldapjdk/target/ldapjdk.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | grep -v '^META-INF/maven/' \ + | tee maven.out + jar tvf ~/build/ldapjdk/packages/ldapjdk.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | tee ant.out + diff maven.out ant.out + + - name: Compare ldapbeans.jar + run: | + jar tvf java-sdk/ldapbeans/target/ldapbeans.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | grep -v '^META-INF/maven/' \ + | tee maven.out + jar tvf ~/build/ldapjdk/packages/ldapbeans.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | tee ant.out + diff maven.out ant.out + + - name: Compare ldapfilter.jar + run: | + jar tvf java-sdk/ldapfilter/target/ldapfilter.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | grep -v '^META-INF/maven/' \ + | tee maven.out + jar tvf ~/build/ldapjdk/packages/ldapfilt.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | tee ant.out + diff maven.out ant.out + + - name: Compare ldapsp.jar + run: | + jar tvf java-sdk/ldapsp/target/ldapsp.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | grep -v '^META-INF/maven/' \ + | tee maven.out + jar tvf ~/build/ldapjdk/packages/ldapsp.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | tee ant.out + diff maven.out ant.out + + - name: Compare ldaptools.jar + run: | + jar tvf java-sdk/ldaptools/target/ldaptools.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | grep -v '^META-INF/maven/' \ + | tee maven.out + jar tvf ~/build/ldapjdk/packages/ldaptools.jar \ + | awk '{print $8;}' \ + | sort \ + | grep -v '/$' \ + | tee ant.out + diff maven.out ant.out + + # TODO: Run examples + + rpm-test: + name: RPM Test needs: wait-for-build runs-on: ubuntu-latest env: @@ -51,100 +165,83 @@ jobs: IMAGE: ldapjdk-builder HOSTNAME: ldapjdk.example.com - - name: Build with Ant + - name: Install RPMs run: | - docker exec ldapjdk ./build.sh - - - name: Install JSS into local Maven repo - run: | - # get JSS .. version - JSS_VERSION=$(docker exec ldapjdk rpm -q --qf "%{version}" dogtag-jss) - - docker exec ldapjdk mvn install:install-file \ - -Dfile=/usr/lib/java/jss.jar \ - -DgroupId=org.dogtagpki.jss \ - -DartifactId=jss-base \ - -Dversion=$JSS_VERSION-SNAPSHOT \ - -Dpackaging=jar \ - -DgeneratePom=true + docker exec ldapjdk bash -c "dnf localinstall -y build/RPMS/*.rpm" - name: Build with Maven run: | - docker exec ldapjdk mvn package + docker exec ldapjdk mvn --batch-mode package - name: Compare ldapjdk.jar run: | docker exec ldapjdk \ - jar tvf /root/build/ldapjdk/packages/ldapjdk.jar \ + jar tvf /usr/share/java/ldapjdk/ldapjdk.jar \ | awk '{print $8;}' \ | sort \ - | tee ldapjdk.ant + | tee rpm.out docker exec ldapjdk \ jar tvf java-sdk/ldapjdk/target/ldapjdk.jar \ | awk '{print $8;}' \ - | grep -v '^META-INF/maven/' \ | sort \ - | tee ldapjdk.maven - diff ldapjdk.ant ldapjdk.maven + | tee maven.out + diff rpm.out maven.out - name: Compare ldapbeans.jar run: | docker exec ldapjdk \ - jar tvf /root/build/ldapjdk/packages/ldapbeans.jar \ + jar tvf /usr/share/java/ldapjdk/ldapbeans.jar \ | awk '{print $8;}' \ | sort \ - | tee ldapbeans.ant + | tee rpm.out docker exec ldapjdk \ jar tvf java-sdk/ldapbeans/target/ldapbeans.jar \ | awk '{print $8;}' \ - | grep -v '^META-INF/maven/' \ | sort \ - | tee ldapbeans.maven - diff ldapbeans.ant ldapbeans.maven + | tee maven.out + diff rpm.out maven.out - name: Compare ldapfilter.jar run: | docker exec ldapjdk \ - jar tvf /root/build/ldapjdk/packages/ldapfilt.jar \ + jar tvf /usr/share/java/ldapjdk/ldapfilter.jar \ | awk '{print $8;}' \ | sort \ - | tee ldapfilt.ant + | tee rpm.out docker exec ldapjdk \ jar tvf java-sdk/ldapfilter/target/ldapfilter.jar \ | awk '{print $8;}' \ - | grep -v '^META-INF/maven/' \ | sort \ - | tee ldapfilt.maven - diff ldapfilt.ant ldapfilt.maven + | tee maven.out + diff rpm.out maven.out - name: Compare ldapsp.jar run: | docker exec ldapjdk \ - jar tvf /root/build/ldapjdk/packages/ldapsp.jar \ + jar tvf /usr/share/java/ldapjdk/ldapsp.jar \ | awk '{print $8;}' \ | sort \ - | tee ldapsp.ant + | tee rpm.out docker exec ldapjdk \ jar tvf java-sdk/ldapsp/target/ldapsp.jar \ | awk '{print $8;}' \ - | grep -v '^META-INF/maven/' \ | sort \ - | tee ldapsp.maven - diff ldapsp.ant ldapsp.maven + | tee maven.out + diff rpm.out maven.out - name: Compare ldaptools.jar run: | - docker exec ldapjdk jar tvf /root/build/ldapjdk/packages/ldaptools.jar \ + docker exec ldapjdk \ + jar tvf /usr/share/java/ldapjdk/ldaptools.jar \ | awk '{print $8;}' \ | sort \ - | tee ldaptools.ant + | tee rpm.out docker exec ldapjdk \ jar tvf java-sdk/ldaptools/target/ldaptools.jar \ | awk '{print $8;}' \ - | grep -v '^META-INF/maven/' \ | sort \ - | tee ldaptools.maven - diff ldaptools.ant ldaptools.maven + | tee maven.out + diff rpm.out maven.out - name: Install RPMInspect run: | diff --git a/build.sh b/build.sh index 1008a26..4dbf171 100755 --- a/build.sh +++ b/build.sh @@ -15,6 +15,10 @@ WORK_DIR= JAVA_LIB_DIR="/usr/share/java" JAVADOC_DIR="/usr/share/javadoc" MAVEN_POM_DIR="/usr/share/maven-poms" + +SLF4J_LIB= +JSS_LIB= + INSTALL_DIR= SOURCE_TAG= @@ -40,6 +44,8 @@ usage() { echo " --java-lib-dir= Java library directory (default: $JAVA_LIB_DIR)." echo " --javadoc-dir= Javadoc directory (default: $JAVADOC_DIR)." echo " --maven-pom-dir= Maven POM directory (default: $MAVEN_POM_DIR)." + echo " --slf4j-lib= Path to SLF4J library" + echo " --jss-lib= Path to JSS library" echo " --install-dir= Installation directory." echo " --source-tag= Generate RPM sources from a source tag." echo " --spec= Use the specified RPM spec (default: $SPEC_TEMPLATE)." @@ -187,6 +193,12 @@ while getopts v-: arg ; do maven-pom-dir=?*) MAVEN_POM_DIR="$(readlink -f "$LONG_OPTARG")" ;; + slf4j-lib=?*) + SLF4J_LIB="$(readlink -f "$LONG_OPTARG")" + ;; + jss-lib=?*) + JSS_LIB="$(readlink -f "$LONG_OPTARG")" + ;; install-dir=?*) INSTALL_DIR="$(readlink -f "$LONG_OPTARG")" ;; @@ -225,7 +237,8 @@ while getopts v-: arg ; do '') break # "--" terminates argument processing ;; - name* | work-dir* | java-lib-dir* | javadoc-dir* | maven-pom-dir* | install-dir* | source-tag* | spec* | version* | release* | dist*) + name* | work-dir* | java-lib-dir* | javadoc-dir* | maven-pom-dir* | slf4j-lib* | jss-lib | \ + install-dir* | source-tag* | spec* | version* | release* | dist*) echo "ERROR: Missing argument for --$OPTARG option" >&2 exit 1 ;; @@ -260,6 +273,8 @@ if [ "$DEBUG" = true ] ; then echo "JAVA_LIB_DIR: $JAVA_LIB_DIR" echo "JAVADOC_DIR: $JAVADOC_DIR" echo "MAVEN_POM_DIR: $MAVEN_POM_DIR" + echo "SLF4J_LIB: $SLF4J_LIB" + echo "JSS_LIB: $JSS_LIB" echo "INSTALL_DIR: $INSTALL_DIR" echo "BUILD_TARGET: $BUILD_TARGET" fi @@ -296,7 +311,21 @@ if [ "$BUILD_TARGET" = "dist" ] ; then fi pushd $SRC_DIR/java-sdk - ant -Ddist=$WORK_DIR dist + + OPTIONS=() + + OPTIONS+=(-Ddist="$WORK_DIR") + + if [ "$SLF4J_LIB" != "" ] ; then + OPTIONS+=(-Dslf4j.lib="$SLF4J_LIB") + fi + + if [ "$JSS_LIB" != "" ] ; then + OPTIONS+=(-Djss.lib="$JSS_LIB") + fi + + ant "${OPTIONS[@]}" dist + popd echo