-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #186: Add jar execution to the existing workflow for DiffTool
- Loading branch information
piyush kumar sadangi
authored and
piyush kumar sadangi
committed
Sep 21, 2024
1 parent
56b601b
commit de403a4
Showing
3 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
guava|git|https://github.com/google/guava|v28.2|| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
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' | ||
POM_URL: "https://raw.githubusercontent.com/checkstyle/test-configs/f08a12ee4dc34892b0438d1f69f447ed8db2c60c/checkstyle-tester/pom.xml" | ||
DIFF_TOOL_VERSION: "1.0-SNAPSHOT-all" | ||
PATCH_DIFF_TOOL_VERSION: "0.1-SNAPSHOT" | ||
|
||
steps: | ||
# 1. Checkout the repository (Updated) | ||
- 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. Download pom.xml | ||
- name: Download pom.xml | ||
run: | | ||
curl --fail-with-body -L -o \ | ||
"${{ github.workspace }}/checkstyle-tester/pom.xml" "${{ env.POM_URL }}" | ||
# 8. Download DiffTool JAR | ||
- name: Download DiffTool JAR | ||
uses: robinraju/release-downloader@v1.8 | ||
with: | ||
repository: "relentless-pursuit/test-configs" | ||
tag: "diff-java-tool-${{ env.DIFF_TOOL_VERSION }}" | ||
fileName: "diff-java-tool-${{ env.DIFF_TOOL_VERSION }}.jar" | ||
out-file-path: "${{ github.workspace }}/checkstyle-tester" | ||
|
||
# 9. 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" | ||
|
||
- name: Clone Checkstyle Repository | ||
run: | | ||
git clone https://github.com/checkstyle/checkstyle.git "${{ github.workspace }}/checkstyle" | ||
- name: Create Temporary Patch Branch | ||
run: | | ||
cd "${{ github.workspace }}/checkstyle" | ||
git config --global user.email "github-actions@github.com" | ||
git config --global 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 (Updated) | ||
- name: Execute DiffTool.jar in Diff Mode | ||
run: | | ||
# Define the directory where DiffTool.jar expects resources | ||
CHECKSTYLE_TESTER_DIR="${{ github.workspace }}/checkstyle-tester" | ||
cd "$CHECKSTYLE_TESTER_DIR" || { echo "Failed to change directory to $CHECKSTYLE_TESTER_DIR"; exit 1; } | ||
# Define necessary variables based on event type | ||
PR_BRANCH="master" # Use the default branch for push events | ||
REPO="${{ github.workspace }}/checkstyle" | ||
CONFIG_XML="${{ github.workspace }}/${{ env.CONFIG_DIR }}/config.xml" | ||
PROJECTS_PROPERTIES="${{ github.workspace }}/${{ env.CONFIG_DIR }}/project.properties" | ||
DIFFTOOL_JAR="diff-java-tool-${{ env.DIFF_TOOL_VERSION }}.jar" | ||
echo "Contents of checkstyle-tester directory:" | ||
ls -la | ||
# Log variables | ||
echo "PR_BRANCH: $PR_BRANCH" | ||
echo "REPO: $REPO" | ||
echo "CONFIG_XML: $CONFIG_XML" | ||
echo "PROJECTS_PROPERTIES: $PROJECTS_PROPERTIES" | ||
echo "DIFFTOOL_JAR: $DIFFTOOL_JAR" | ||
# Ensure the localGitRepo exists | ||
if [ ! -d "$REPO/.git" ]; then | ||
echo "Cloning checkstyle repository into $REPO" | ||
git clone https://github.com/checkstyle/checkstyle.git "$REPO" || { echo "Failed to clone repository"; exit 1; } | ||
fi | ||
echo "Running DiffTool.jar in 'diff' mode" | ||
java -jar "$DIFFTOOL_JAR" \ | ||
--localGitRepo "$REPO" \ | ||
--baseBranch master \ | ||
--config "$CONFIG_XML" \ | ||
--patchBranch temp-patch-branch \ | ||
--listOfProjects "$PROJECTS_PROPERTIES" \ | ||
--allowExcludes || { echo "DiffTool execution failed"; exit 1; } | ||
# 13. Delete Temporary Patch Branch in Checkstyle Repository | ||
- name: Delete Temporary Patch Branch | ||
run: | | ||
cd "${{ github.workspace }}/checkstyle" | ||
git checkout master # Switch back to 'master' branch in checkstyle repository | ||
git branch -D temp-patch-branch | ||
# 12. Execute DiffTool.jar with invalid arguments to print help | ||
- name: Execute DiffTool.jar with Invalid Arguments | ||
run: | | ||
cd "${{ github.workspace }}/checkstyle-tester" | ||
DIFFTOOL_JAR="diff-java-tool-${{ env.DIFF_TOOL_VERSION }}.jar" | ||
# Execute with invalid arguments to test error handling | ||
echo "Running DiffTool.jar with invalid arguments" | ||
java -jar "$DIFFTOOL_JAR" --invalidArg || echo "Handled invalid arguments gracefully" | ||
# 13. Verify no exceptions occurred during DiffTool execution | ||
- name: Verify DiffTool Execution | ||
run: | | ||
echo "DiffTool executed successfully." | ||
# 14. 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/patch-diff-report-tool-${{ env.PATCH_DIFF_TOOL_VERSION }}-jar-with-dependencies.jar | ||
# 15. Cleanup (optional) | ||
- name: Cleanup Temporary Files | ||
if: always() | ||
run: | | ||
rm -rf checkstyle-tester | ||
# Additional Debugging Steps (Optional) | ||
- name: Check Permissions and Directory Structure | ||
run: | | ||
echo "Checking 'checkstyle-tester' directory structure after DiffTool.jar execution:" | ||
ls -la "${{ github.workspace }}/checkstyle-tester" | ||
ls -la "${{ github.workspace }}/checkstyle-tester/src/main/java" | ||
ls -la "${{ github.workspace }}/checkstyle-tester/repositories" | ||
ls -la "${{ github.workspace }}/checkstyle-tester/reports/diff" | ||
echo "Checking write permissions:" | ||
touch "${{ github.workspace }}/checkstyle-tester/src/main/java/testfile" && echo "Write permission OK" || echo "Write permission FAILED" |