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
4 changes: 3 additions & 1 deletion .github/contract-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gephi-plugins-tests.version>1.1.0</gephi-plugins-tests.version>
<gephi-plugins-tests.version>1.2.0</gephi-plugins-tests.version>
</properties>

<!-- Align the plugin's Gephi/NetBeans dependencies on the current gephi.version, so plugins
Expand Down Expand Up @@ -61,6 +61,8 @@
<!-- Only test implementations from the plugin's own jar, not the ones its
dependencies (e.g. core layout-plugin) register -->
<gephi.plugins.tests.jar>${plugin.artifactId}-${plugin.version}.jar</gephi.plugins.tests.jar>
<!-- Where the tests write their warnings (checks that don't fail the build), read by run.sh -->
<gephi.plugins.tests.warnings>${project.build.directory}/contract-warnings.tsv</gephi.plugins.tests.warnings>
</systemPropertyVariables>
<dependenciesToScan>
<dependency>org.gephi:gephi-plugins-tests</dependency>
Expand Down
68 changes: 66 additions & 2 deletions .github/contract-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#
# With no arguments, every module in the root pom.xml's <modules> list is tested. Otherwise only
# NBM modules under the given folders are; a folder outside the reactor (e.g. a disabled plugin)
# is skipped with a warning. Modules must be installed in the local Maven repository first
# is skipped with a warning. Checks that are only advisory (e.g. a layout adding nodes) don't fail
# the run: they are reported as warning annotations, and in the job summary when running on GitHub
# Actions. Modules must be installed in the local Maven repository first
# (mvn install): a module that is missing there, or was rebuilt since, fails instead of testing a
# stale jar.
set -euo pipefail
Expand Down Expand Up @@ -75,6 +77,44 @@ if [ ${#TARGETS[@]} -eq 0 ]; then
exit 0
fi

# Advisory test warnings, one "plugin<TAB>check<TAB>message" entry each
WARNINGS_FILE="$HARNESS_DIR/target/contract-warnings.tsv"
WARNINGS=()

# Workflow command data can't contain %, the warnings are single lines already
annotation_escape() {
printf '%s' "$1" | sed -e 's/%/%25/g'
}

# Plugin names and messages come from the plugin's code, so don't let them format the summary
markdown_escape() {
printf '%s' "$1" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/|/\\|/g' -e 's/`/\\`/g'
}

collect_warnings() {
[ -f "$WARNINGS_FILE" ] || return 0
local check message
while IFS=$'\t' read -r check message; do
WARNINGS+=("$1"$'\t'"$check"$'\t'"$message")
echo "::warning title=SPI contract test warning::$(annotation_escape "$1: $check: $message")"
done < "$WARNINGS_FILE"
}

# The jars of the modules that depend on the one being tested, installed in the local repository. A plugin split in
# modules keeps parts of it (e.g. its user interface) in modules that depend on the main one, and the tests look
# those up too.
dependent_jars() {
local packaging group artifact version basedir repo jar
while IFS='|' read -r packaging group artifact version basedir _ repo; do
[ "$packaging" = nbm ] || continue
[ "$artifact" != "$1" ] || continue
grep -q "<artifactId>$1</artifactId>" "$basedir/pom.xml" || continue
jar="$repo/${group//.//}/$artifact/$version/$artifact-$version.jar"
[ -f "$jar" ] && echo "$jar"
done <<< "$PROJECTS"
return 0
}

PASSED=()
FAILED=()
for target in "${TARGETS[@]}"; do
Expand All @@ -92,20 +132,44 @@ for target in "${TARGETS[@]}"; do
continue
fi

EXTRA_ARGS=()
EXTRA_JARS=$(dependent_jars "$artifact" | paste -sd, -)
if [ -n "$EXTRA_JARS" ]; then
EXTRA_ARGS=(-Dmaven.test.additionalClasspath="$EXTRA_JARS")
fi

rm -rf "$HARNESS_DIR/target"
echo "::group::Contract tests: $gav"
if mvn -B -ntp -f "$HARNESS_DIR/pom.xml" test -Dgephi.version="$GEPHI_VERSION" \
-Dplugin.groupId="$group" -Dplugin.artifactId="$artifact" -Dplugin.version="$version"; then
-Dplugin.groupId="$group" -Dplugin.artifactId="$artifact" -Dplugin.version="$version" \
${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}; then
echo "::endgroup::"
else
echo "::endgroup::"
echo "::error::SPI contract tests failed for $gav"
collect_warnings "$gav"
FAILED+=("$gav")
continue
fi
collect_warnings "$gav"
PASSED+=("$gav")
done

if [ ${#WARNINGS[@]} -gt 0 ] && [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
{
echo "### SPI contract test warnings"
echo
echo "These checks don't fail the build, but are worth a look in review."
echo
echo "| Plugin | Check | Warning |"
echo "| --- | --- | --- |"
for warning in "${WARNINGS[@]}"; do
IFS=$'\t' read -r gav check message <<< "$warning"
echo "| $(markdown_escape "$gav") | $(markdown_escape "$check") | $(markdown_escape "$message") |"
done
} >> "$GITHUB_STEP_SUMMARY"
fi

if [ ${#PASSED[@]} -gt 0 ]; then
echo "SPI contract tests passed for: ${PASSED[*]}"
fi
Expand Down
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Requires JDK 17 and Maven.
- Build/test a single plugin module: `mvn -pl modules/<ModuleName> clean package`
- Run a single module's unit tests only: `mvn -pl modules/<ModuleName> test`
- Run the SPI contract tests CI runs (from `gephi-plugins-tests`) on a module, after `mvn install`:
`.github/contract-tests/run.sh modules/<ModuleName>`
`.github/contract-tests/run.sh modules/<ModuleName>`. A failing check fails the run; advisory checks
(e.g. a layout adding nodes) only print `::warning::` lines and, in CI, a job summary table.
- Run Gephi with the module(s) installed (build first): `mvn org.gephi:gephi-maven-plugin:run`
- IDE run/debug configs are defined in `nbactions.xml`; the IntelliJ debug setup (remote debugger +
`-Drun.params.debug` VM option) is documented in `README.md`.
Expand Down
Loading