From dd48631ad0cfe867a0e307979ea75c238883ab0d Mon Sep 17 00:00:00 2001
From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com>
Date: Sat, 19 Oct 2024 13:06:50 +0200
Subject: [PATCH] Single point version definition (#285)
* Remove iguana version number from script
* Remove old files
* Move ontology file to resource folder and set version as variable
* Update deployment
* Separate ontology version from project version
* Add github action for checking ontology version
* Update file permissions
* Update ontology version
* Add a version command line option
* Fix resources configuration
* Change version information format
* Fix version output
Closes #278
---
.github/scripts/check_schema_version.sh | 19 ++++++++++++++
.github/workflows/check_version.yml | 3 ++-
.github/workflows/deploy.yml | 17 +++++++-----
graalvm/generate-config.sh | 1 +
graalvm/generate-profile.sh | 6 ++---
pom.xml | 17 ++++++++++++
.../iguana/cc/controller/MainController.java | 26 ++++++++++++++++++-
{schema => src/main/resources}/iguana.owx | 4 +--
src/main/resources/version.properties | 2 ++
9 files changed, 82 insertions(+), 13 deletions(-)
create mode 100755 .github/scripts/check_schema_version.sh
rename {schema => src/main/resources}/iguana.owx (99%)
create mode 100644 src/main/resources/version.properties
diff --git a/.github/scripts/check_schema_version.sh b/.github/scripts/check_schema_version.sh
new file mode 100755
index 000000000..819aea80e
--- /dev/null
+++ b/.github/scripts/check_schema_version.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
+ONTOLOGY_VERSION=$(mvn help:evaluate -Dexpression=ontology.version -q -DforceStdout)
+
+# Check for changes and compare versions
+if git diff --quiet "main:$(git ls-tree -r --name-only main | grep 'iguana.owx')" 'src/main/resources/iguana.owx'; then
+ DIFF_STATUS=0
+else
+ DIFF_STATUS=1
+fi
+
+if [ $DIFF_STATUS = '1' ] && [ "$PROJECT_VERSION" != "$ONTOLOGY_VERSION" ];
+then
+ echo "Schema has changed, update ontology version to the project version inside the pom!"
+ exit 1
+fi
+
+exit 0
diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml
index 770bf137c..f15f65cba 100644
--- a/.github/workflows/check_version.yml
+++ b/.github/workflows/check_version.yml
@@ -8,4 +8,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- - run: .github/scripts/tagcheck.sh v$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
\ No newline at end of file
+ - run: .github/scripts/tagcheck.sh v$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
+ - run: .github/scripts/check_schema_version.sh
\ No newline at end of file
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 47949ee79..f24fe45fd 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -69,7 +69,7 @@ jobs:
deploy_docs:
name: Deploy Documentation
runs-on: ubuntu-latest
- needs: find_version
+ needs: deploy_to_maven
env:
RELEASE_VERSION: ${{ needs.find_version.outputs.RELEASE_VERSION }}
steps:
@@ -121,15 +121,20 @@ jobs:
publish_dir: ./javadoc/${{ env.RELEASE_VERSION }}/apidocs
destination_dir: ./javadoc/latest
+ - name: Fetch Ontologies
+ run: git fetch && git checkout origin/gh-pages ontology/
- name: Find Ontology Version
- run: echo "ONTOLOGY_VERSION=$(grep 'versionIRI' schema/iguana.owx | grep -Po '[0-9]+.[0-9]+.[0-9]+')" >> $GITHUB_OUTPUT
+ run: echo "ONTOLOGY_VERSION=$(grep 'versionIRI' artifacts/iguana.owx | grep -Po '[0-9]+.[0-9]+.[0-9]+')" >> $GITHUB_OUTPUT
id: find_ontology_version
+ - name: Download artifacts from previous jobs
+ uses: actions/download-artifact@v4
+ with:
+ path: artifacts/
+ merge-multiple: true
- - name: Fetch Ontologies
- run: git fetch && git checkout origin/gh-pages ontology/
- run: mkdir -p ontology/${{ steps.find_ontology_version.outputs.ONTOLOGY_VERSION }}
- - run: cp schema/iguana.owx ontology/${{ steps.find_ontology_version.outputs.ONTOLOGY_VERSION }}/iguana.owx
- - run: cp schema/iguana.owx ontology/iguana.owx
+ - run: cp artifacts/iguana.owx ontology/${{ steps.find_ontology_version.outputs.ONTOLOGY_VERSION }}/iguana.owx
+ - run: cp artifacts/iguana.owx ontology/iguana.owx
- name: Deploy Ontology to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
diff --git a/graalvm/generate-config.sh b/graalvm/generate-config.sh
index fdd4625f2..d018f5f4c 100755
--- a/graalvm/generate-config.sh
+++ b/graalvm/generate-config.sh
@@ -44,6 +44,7 @@ fi
# Run through multiple different execution paths, so that the tracing agent can generate complete configuration files.
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --help > /dev/null
+"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --version > /dev/null
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --dry-run -is "$SUITE" > /dev/null
"$GRAALVM_HOME"/bin/java -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/ -jar "$TARGET_DIR"/iguana.jar --dry-run "$SUITE" > /dev/null
diff --git a/graalvm/generate-profile.sh b/graalvm/generate-profile.sh
index 8822f673b..93ee37266 100755
--- a/graalvm/generate-profile.sh
+++ b/graalvm/generate-profile.sh
@@ -40,21 +40,21 @@ if [ -z "$SUITE" ]; then
fi
# Instrument the application
-"$GRAALVM_HOME"/bin/native-image --pgo-instrument "$ARGUMENTS" -jar ./target/iguana.jar -o "./target/iguana-4.1.0-instrumented"
+"$GRAALVM_HOME"/bin/native-image --pgo-instrument "$ARGUMENTS" -jar ./target/iguana.jar -o "./target/iguana-instrumented"
if [ $? -ne 0 ]; then
echo "Error while instrumenting the application."
exit 1
fi
# Generate the profile
-./target/iguana-4.1.0-instrumented -XX:ProfilesDumpFile=custom.iprof "$SUITE"
+./target/iguana-instrumented -XX:ProfilesDumpFile=custom.iprof "$SUITE"
if [ $? -ne 0 ]; then
echo "Error while generating the profile."
exit 1
fi
# Compile the application with the profile
-"$GRAALVM_HOME"/bin/native-image --pgo=custom.iprof "$ARGUMENTS" -jar ./target/iguana.jar -o "./target/iguana-4.1.0-pgo"
+"$GRAALVM_HOME"/bin/native-image --pgo=custom.iprof "$ARGUMENTS" -jar ./target/iguana.jar -o "./target/iguana-pgo"
if [ $? -ne 0 ]; then
echo "Error while compiling the application."
exit 1
diff --git a/pom.xml b/pom.xml
index eccbad943..f0c186f06 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,8 @@
1
0
+ 4.1.0
+
17
5.1.0
UTF-8
@@ -146,6 +148,20 @@
+
+
+ src/main/resources
+ version.properties
+ true
+
+
+ src/main/resources
+
+ version.properties
+
+ false
+
+
org.apache.maven.plugins
@@ -227,6 +243,7 @@
${project.basedir}/src/main/resources/
start-iguana.sh
+ iguana.owx
true
diff --git a/src/main/java/org/aksw/iguana/cc/controller/MainController.java b/src/main/java/org/aksw/iguana/cc/controller/MainController.java
index 1190f84e3..b806d3ea5 100644
--- a/src/main/java/org/aksw/iguana/cc/controller/MainController.java
+++ b/src/main/java/org/aksw/iguana/cc/controller/MainController.java
@@ -8,6 +8,7 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Objects;
/**
@@ -36,6 +37,9 @@ public Path convert(String value) {
@Parameter(description = "suite file {yml,yaml,json}", arity = 1, required = true, converter = PathConverter.class)
private Path suitePath;
+
+ @Parameter(names = {"--version", "-v"}, description = "Outputs the version number of the program and result ontology.")
+ private boolean version;
}
private static final Logger LOGGER = LoggerFactory.getLogger(MainController.class);
@@ -45,7 +49,7 @@ public Path convert(String value) {
*
* @param argc The command line arguments that are passed to the program.
*/
- public static void main(String[] argc) {
+ public static void main(String[] argc) throws IOException {
// Configurator.reconfigure(URI.create("log4j2.yml"));
var args = new Args();
@@ -55,6 +59,13 @@ public static void main(String[] argc) {
try {
jc.parse(argc);
} catch (ParameterException e) {
+ // The exception is also thrown when no suite file is provided. In the case where only the version option
+ // is provided, this would still throw. Therefore, we need to check if the version option is provided.
+ if (args.version) {
+ outputVersion();
+ System.exit(0);
+ }
+
System.err.println(e.getLocalizedMessage());
jc.usage();
System.exit(0);
@@ -63,6 +74,10 @@ public static void main(String[] argc) {
jc.usage();
System.exit(1);
}
+ if (args.version) {
+ outputVersion();
+ System.exit(0);
+ }
try {
Suite parse = IguanaSuiteParser.parse(args.suitePath, !args.ignoreShema);
@@ -74,4 +89,13 @@ public static void main(String[] argc) {
System.exit(0);
}
+ private static void outputVersion() throws IOException {
+ ClassLoader classloader = MainController.class.getClassLoader();
+ String properties = new String(Objects.requireNonNull(classloader.getResourceAsStream("version.properties")).readAllBytes());
+ String[] lines = properties.split("\\n");
+ String projectVersion = lines[0].split("=")[1].trim();
+ String ontologyVersion = lines[1].split("=")[1].trim();
+ System.out.printf("IGUANA version: %s (result ontology version: %s)%n", projectVersion, ontologyVersion);
+ }
+
}
diff --git a/schema/iguana.owx b/src/main/resources/iguana.owx
similarity index 99%
rename from schema/iguana.owx
rename to src/main/resources/iguana.owx
index d5f18e6f6..4bd4448b4 100644
--- a/schema/iguana.owx
+++ b/src/main/resources/iguana.owx
@@ -6,7 +6,7 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
ontologyIRI="https://vocab.dice-research.org/iguana/"
- versionIRI="https://vocab.dice-research.org/iguana/4.1.0/">
+ versionIRI="https://vocab.dice-research.org/iguana/${ontology.version}/">
@@ -48,7 +48,7 @@
- 4.1.0
+ ${ontology.version}
diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties
new file mode 100644
index 000000000..340f91eff
--- /dev/null
+++ b/src/main/resources/version.properties
@@ -0,0 +1,2 @@
+version=${project.version}
+ontology_version=${ontology.version}
\ No newline at end of file