-
Notifications
You must be signed in to change notification settings - Fork 4
191 lines (163 loc) · 7.32 KB
/
java-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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"