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 Sep 29, 2024
1 parent 5c1fd3f commit e7c9e18
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .ci-config/base-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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="AbstractClassName"/>

<!-- 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>
33 changes: 33 additions & 0 deletions .ci-config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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="AbstractClassName"/>

<!-- 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>
37 changes: 37 additions & 0 deletions .ci-config/patch-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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="AbstractClassName"/>

<!-- 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>

<!-- Additional module added for testing -->
<module name="LineLength">
<property name="max" value="100"/>
</module>
</module>
</module>
1 change: 1 addition & 0 deletions .ci-config/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
guava|git|https://github.com/google/guava|v28.2||
174 changes: 174 additions & 0 deletions .github/workflows/java-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: CI/CD for DiffTool

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allows manual triggering

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"

steps:
# 1. Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
clean: true
fetch-depth: 1

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

# 3. Cache Maven dependencies
- name: Cache Maven Dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-
# 4. Build the project with Gradle
- name: Build with Gradle
run: |
cd diff-java-tool
./gradlew clean build
# 5. Run unit tests
- name: Run Unit Tests
run: |
cd diff-java-tool
./gradlew test
# 6. Create checkstyle-tester directory within the workspace
- name: Create checkstyle-tester directory
run: mkdir -p "${{ github.workspace }}/checkstyle-tester"

# 7. Copy DiffTool JAR to checkstyle-tester directory
- name: Copy DiffTool JAR to checkstyle-tester directory
run: |
cp diff-java-tool/build/libs/diff-java-tool-*-all.jar "${{ github.workspace }}/checkstyle-tester/${{ env.DIFFTOOL_JAR }}"
# 8. Download patch-diff-report-tool JAR
- name: Download patch-diff-report-tool JAR
uses: robinraju/release-downloader@v1.8
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 }}/checkstyle-tester"

# 9. Clone Checkstyle Repository
- name: Clone Checkstyle Repository
run: |
git clone https://github.com/checkstyle/checkstyle.git "${{ github.workspace }}/checkstyle"
# 10. Create Temporary Patch Branch
- name: Create Temporary Patch Branch
run: |
cd "${{ github.workspace }}/checkstyle"
git config user.email "github-actions@github.com"
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"
# 11. Execute DiffTool.jar in 'diff' mode
- name: Execute DiffTool.jar in Diff Mode
env:
CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/config.xml"
PROJECTS_PROPERTIES: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/project.properties"
run: |
CHECKSTYLE_TESTER_DIR="${{ github.workspace }}/checkstyle-tester"
cd "$CHECKSTYLE_TESTER_DIR" || { echo "Failed to change directory to $CHECKSTYLE_TESTER_DIR"; exit 1; }
REPO="${{ github.workspace }}/checkstyle"
echo "Running DiffTool.jar in 'diff' mode"
java -jar "${{ env.DIFFTOOL_JAR }}" \
--localGitRepo "$REPO" \
--baseBranch master \
--config "${CONFIG_XML}" \
--patchBranch temp-patch-branch \
--listOfProjects "${PROJECTS_PROPERTIES}" \
--allowExcludes || { echo "DiffTool execution failed"; exit 1; }
# 12. Execute DiffTool.jar with all arguments
- name: Execute DiffTool.jar with all arguments
env:
BASE_CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/base-config.xml"
PATCH_CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/patch-config.xml"
PROJECTS_PROPERTIES: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/project.properties"
run: |
CHECKSTYLE_TESTER_DIR="${{ github.workspace }}/checkstyle-tester"
cd "$CHECKSTYLE_TESTER_DIR" || exit 1
PR_BRANCH="temp-patch-branch"
REPO="${{ github.workspace }}/checkstyle"
echo "Running DiffTool.jar with all arguments combined"
java -jar "${{ env.DIFFTOOL_JAR }}" \
--localGitRepo "$REPO" \
--baseBranch master \
--patchBranch "$PR_BRANCH" \
--baseConfig "${BASE_CONFIG_XML}" \
--patchConfig "${PATCH_CONFIG_XML}" \
--listOfProjects "${PROJECTS_PROPERTIES}" \
--mode diff \
--shortFilePaths \
--extraMvnRegressionOptions "-Dmaven.test.skip=true" \
--allowExcludes \
--useShallowClone
# 13. Delete Temporary Patch Branch in Checkstyle Repository
- name: Delete Temporary Patch Branch
run: |
cd "${{ github.workspace }}/checkstyle"
git checkout master
git branch -D temp-patch-branch
# 14. Execute DiffTool.jar with Invalid Arguments
- name: Execute DiffTool.jar with Invalid Arguments
run: |
cd "${{ github.workspace }}/checkstyle-tester" || exit 1
echo "Running DiffTool.jar with invalid arguments"
java -jar "${{ env.DIFFTOOL_JAR }}" --invalidArg || echo "Handled invalid arguments gracefully"
# 15. Verify no exceptions occurred during DiffTool execution
- name: Verify DiffTool Execution
run: |
echo "DiffTool executed successfully."
# 16. Upload build reports and logs on failure
- name: Upload Build Reports on Failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-reports
path: |
diff-java-tool/build/reports
diff-java-tool/build/test-results
checkstyle-tester
# 17. Cleanup (optional)
- name: Cleanup Temporary Files
if: always()
run: |
rm -rf checkstyle-tester
rm -rf checkstyle

0 comments on commit e7c9e18

Please # to comment.