Skip to content

Commit

Permalink
Improve integration test setup (#1427)
Browse files Browse the repository at this point in the history
Summary of changes:
- Configure Renovate to update AssertJ and fmt-maven-plugin version
  references in patch files and shell scripts any time those
  dependencies are updated in the top-level `pom.xml`.
- Enhance the `--sync` flag such that it also updates the initial patch
  file, avoiding drift due to line shifts.
  • Loading branch information
Stephan202 authored Nov 20, 2024
1 parent 1668546 commit dc87aed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .renovaterc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
"extends": [
"helpers:pinGitHubActionDigests"
],
"customManagers": [
{
"customType": "regex",
"fileMatch": [
"^integration-tests/.*(-init\\.patch|\\.sh)$"
],
"matchStrings": [
"\\b(?<packageName>[a-z0-9_.-]+?:[a-z0-9_.-]+?):(?<currentValue>[^:]+?):[a-zA-Z0-9_-]+\\b",
"<version>(?<currentValue>.*?)<!-- Renovate: (?<packageName>.*?) --></version>"
],
"datasourceTemplate": "maven"
}
],
"packageRules": [
{
"matchPackagePatterns": [
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/checkstyle-init.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>${assertj.version}</version>
+ <version>3.26.3<!-- Renovate: org.assertj:assertj-bom --></version>
+ <scope>test</scope>
+ </dependency>
<dependency>
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/checkstyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ test_name="$(basename "${0}" .sh)"
project='checkstyle'
repository='https://github.com/checkstyle/checkstyle.git'
revision='checkstyle-10.20.1'
# XXX: Configure Renovate to manage the AssertJ version declared here.
additional_build_flags='-Perror-prone-compile,error-prone-test-compile -Dassertj.version=3.24.2 -Dmaven.compiler.failOnError=true'
additional_build_flags='-Perror-prone-compile,error-prone-test-compile -Dmaven.compiler.failOnError=true'
additional_source_directories='${project.basedir}${file.separator}src${file.separator}it${file.separator}java,${project.basedir}${file.separator}src${file.separator}xdocs-examples${file.separator}java'
patch_error_prone_flags=''
validation_error_prone_flags=''
Expand All @@ -33,4 +32,4 @@ fi
"${patch_error_prone_flags}" \
"${validation_error_prone_flags}" \
"${validation_build_flags}" \
$@
${@}
26 changes: 15 additions & 11 deletions integration-tests/run-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ shared_build_flags="
${additional_build_flags}
"

# XXX: Configure Renovate to manage the fmt-maven-plugin version declared here.
# XXX: Once GitHub actions uses Maven 3.9.2+, we can inline this variable with
# version reference `${fmt.version}`, and `-Dfmt.version=2.21.1` added to
# `shared_build_flags`.
format_goal='com.spotify.fmt:fmt-maven-plugin:2.21.1:format'
format_goal='com.spotify.fmt:fmt-maven-plugin:2.25:format'

error_prone_shared_flags='-XepExcludedPaths:(\Q${project.basedir}${file.separator}src${file.separator}\E(it|test|xdocs-examples)\Q${file.separator}resources\E|\Q${project.build.directory}${file.separator}\E).*'

Expand Down Expand Up @@ -124,14 +120,22 @@ pushd "${project_root}"
git config user.email || git config user.email '[email protected]'
git config user.name || git config user.name 'Integration Test'

# Prepare the code for analysis by (a) applying the minimal set of changes
# required to run Error Prone with Error Prone Support and (b) formatting the
# code using the same method by which it will be formatted after each
# compilation round. The initial formatting operation ensures that subsequent
# modifications can be rendered in a clean manner.
# Prepare the code for analysis by applying the minimal set of changes required
# to run Error Prone with Error Prone Support.
initial_patch="${integration_test_root}/${test_name}-init.patch"
git clean -fdx
git apply < "${integration_test_root}/${test_name}-init.patch"
git apply < "${initial_patch}"
git commit -m 'dependency: Introduce Error Prone Support' .
if [ -n "${do_sync}" ]; then
# The initial patch applied successfully, but if it was created against a
# different version, then offsets may have changed. Here we update the patch
# to exactly match the new state.
git diff HEAD~1 | "${grep_command}" -vP '^(diff|index)' > "${initial_patch}"
fi

# Format the patched code using the same method by which it will be formatted
# after each compilation round. This initial formatting operation ensures that
# subsequent modifications can be rendered in a clean manner.
mvn ${shared_build_flags} "${format_goal}"
git commit -m 'minor: Reformat using Google Java Format' .
diff_base="$(git rev-parse HEAD)"
Expand Down

0 comments on commit dc87aed

Please sign in to comment.