Skip to content

Commit

Permalink
Issue #186: Add jar execution to the existing workflow for DiffTool
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush kumar sadangi authored and piyush kumar sadangi committed Oct 5, 2024
1 parent 0550966 commit 3b15ef4
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .ci-config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name = "Checker">
<property name="charset" value="UTF-8"/>

<!-- do not change severity to 'error', as that will hide errors caused by exceptions -->
<property name="severity" value="warning"/>

<!-- haltOnException is required for exception fixes and reporting of all exceptions -->
<property name="haltOnException" value="false"/>

<!-- BeforeExecutionFileFilters is required for sources of java9 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$" />
</module>

<module name="TreeWalker">
<!-- as we run on regression even on non-compiled files we need to skip exceptions on them -->
<property name="skipFileOnJavaParseException" value="true"/>
<property name="javaParseExceptionSeverity" value="ignore"/>

<!-- MethodName Check to Intentionally Produce Violations -->
<module name="MethodName">
<!--
The following regex pattern is intentionally restrictive and does not match any valid method names.
This will cause Checkstyle to flag all method names as violations.
-->
<property name="format" value="^[A-Z]{0}$"/>
</module>

<!-- suppress javadoc parsing errors, as we test Check not a parser -->
<module name="SuppressionXpathSingleFilter">
<property name="message" value="Javadoc comment at column \d+ has parse error"/>
</module>

</module>

</module>
35 changes: 35 additions & 0 deletions .ci-config/patch-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<property name="charset" value="UTF-8"/>

<!-- do not change severity to 'error', as that will hide errors caused by exceptions -->
<property name="severity" value="warning"/>

<!-- haltOnException is required for exception fixes and reporting of all exceptions -->
<property name="haltOnException" value="false"/>

<!-- BeforeExecutionFileFilters is required for sources of java9 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<module name="TreeWalker">
<!-- as we run on regression even on non-compiled files we need to skip exceptions on them -->
<property name="skipFileOnJavaParseException" value="true"/>
<property name="javaParseExceptionSeverity" value="ignore"/>

<module name="MethodName">
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
<property name="applyToPublic" value="false"/>
</module>

<!-- suppress javadoc parsing errors, as we test Check not a parser -->
<module name="SuppressionXpathSingleFilter">
<property name="message" value="Javadoc comment at column \d+ has parse error"/>
</module>
</module>
</module>
5 changes: 5 additions & 0 deletions .ci-config/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
projects:
- name: diff-java-tool
scm: git
url: file:///home/runner/work/test-configs/test-configs/diff-java-tool
reference: main
154 changes: 154 additions & 0 deletions .github/workflows/DiffTool-CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: diff-java-tool PR checks

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows manual triggering test changes in checkstyle/test-configs
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
env:
JAVA_VERSION: '21'
CONFIG_DIR: '.ci-config'
DIFFTOOL_JAR: "diff-java-tool.jar"
PATCH_DIFF_TOOL_VERSION: "0.1-SNAPSHOT"
CI_TEMP_DIR: '.ci-temp'

steps:
- name: Create CI Temp Directory
run: mkdir -p "${{ env.CI_TEMP_DIR }}"

- name: Checkout Main Repository into CI Temp Directory
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ env.CI_TEMP_DIR }}/test-configs

- name: Checkout Checkstyle Repository into CI Temp Directory
uses: actions/checkout@v4
with:
repository: checkstyle/checkstyle
path: ${{ env.CI_TEMP_DIR }}/checkstyle

- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

- name: Cache Maven Dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
- name: Build diff-java-tool with Gradle
run: |
cd "${{ env.CI_TEMP_DIR }}/test-configs/diff-java-tool"
./gradlew clean build
- name: List built JAR files
run: |
ls -l "${{ env.CI_TEMP_DIR }}/test-configs/diff-java-tool/build/libs/"
- name: Copy DiffTool JAR to CI Temp Directory
run: |
cp "${{ env.CI_TEMP_DIR }}/test-configs/diff-java-tool/build/libs/diff-java-tool-*.jar" "${{ env.CI_TEMP_DIR }}/${{ env.DIFFTOOL_JAR }}"
- name: Download patch-diff-report-tool JAR
uses: robinraju/[email protected]
with:
repository: "checkstyle/contribution"
tag: "patch-diff-report-tool-${{ env.PATCH_DIFF_TOOL_VERSION }}"
fileName: >-
patch-diff-report-tool-${{ env.PATCH_DIFF_TOOL_VERSION }}-jar-with-dependencies.jar
out-file-path: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}"

- name: Create Temporary Patch Branch
run: |
cd "${{ env.CI_TEMP_DIR }}/checkstyle"
git config user.email "[email protected]"
git config user.name "GitHub Actions"
git checkout -b temp-patch-branch
# Optionally make a minor change to ensure reports are different
echo "// Temporary change" >> dummy.java
git add dummy.java
git commit -m "Temporary change for testing"
- name: Initialize git repository in 'diff-java-tool'
run: |
cd "${{ env.CI_TEMP_DIR }}/test-configs/diff-java-tool"
git init --initial-branch=main
git config user.email "[email protected]"
git config user.name "GitHub Actions"
git add .
git commit -m "Initialize diff-java-tool repository"
- name: Execute DiffTool.jar with config
env:
CONFIG_XML: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/test-configs/${{ env.CONFIG_DIR }}/config.xml"
PROJECTS_YML: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/test-configs/${{ env.CONFIG_DIR }}/project.yml"
DIFFTOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/${{ env.DIFFTOOL_JAR }}"
PATCH_DIFF_TOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/patch-diff-report-tool-${{ env.PATCH_DIFF_TOOL_VERSION }}-jar-with-dependencies.jar"
run: |
REPO="${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/checkstyle"
echo "Running DiffTool.jar in 'diff' mode"
java -jar "${DIFFTOOL_JAR_PATH}" \
--localGitRepo "$REPO" \
--baseBranch master \
--config "${CONFIG_XML}" \
--patchBranch temp-patch-branch \
--listOfProjects "${PROJECTS_YML}" \
--allowExcludes \
--diffToolJarPath "${PATCH_DIFF_TOOL_JAR_PATH}" || { echo "DiffTool execution failed"; exit 1; }
- name: Execute DiffTool.jar with patch config
env:
CONFIG_XML: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/test-configs/${{ env.CONFIG_DIR }}/config.xml"
PATCH_CONFIG_XML: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/test-configs/${{ env.CONFIG_DIR }}/patch-config.xml"
PROJECTS_YML: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/test-configs/${{ env.CONFIG_DIR }}/project.yml"
DIFFTOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/${{ env.DIFFTOOL_JAR }}"
PATCH_DIFF_TOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/patch-diff-report-tool-${{ env.PATCH_DIFF_TOOL_VERSION }}-jar-with-dependencies.jar"
run: |
PR_BRANCH="temp-patch-branch"
REPO="${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/checkstyle"
echo "Running DiffTool.jar with all arguments combined"
java -jar "${DIFFTOOL_JAR_PATH}" \
--localGitRepo "$REPO" \
--baseBranch master \
--patchBranch "$PR_BRANCH" \
--baseConfig "${CONFIG_XML}" \
--patchConfig "${PATCH_CONFIG_XML}" \
--listOfProjects "${PROJECTS_YML}" \
--mode diff \
--shortFilePaths \
--extraMvnRegressionOptions "-Dmaven.test.skip=true" \
--allowExcludes \
--useShallowClone \
--diffToolJarPath "${PATCH_DIFF_TOOL_JAR_PATH}"
- name: Execute DiffTool.jar with Invalid Arguments
env:
DIFFTOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/${{ env.DIFFTOOL_JAR }}"
run: |
echo "Running DiffTool.jar with invalid arguments"
# Disable 'set -e' to prevent the script from exiting on error
set +e
java -jar "${DIFFTOOL_JAR_PATH}" --invalidArg
EXIT_CODE=$?
# Re-enable 'set -e' if necessary
set -e
if [ "$EXIT_CODE" -eq 1 ]; then
echo "Error Exit code was expected."
else
echo "Unexpected exit code: $EXIT_CODE"
exit 1
fi

0 comments on commit 3b15ef4

Please sign in to comment.