-
Notifications
You must be signed in to change notification settings - Fork 4
147 lines (132 loc) · 5.63 KB
/
ci-diff-java-tool.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
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: '.github/workflows'
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 Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- 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 Java 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- 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 diff-java-tool
./gradlew clean build
- name: Copy DiffTool JAR to CI Temp Directory
run: |
cp diff-java-tool/build/libs/diff-java-tool-*-all.jar "${CI_TEMP_DIR}/${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 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 diff-java-tool.jar with config
env:
CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/config.xml"
PROJECTS_YML: "${{ github.workspace }}/${{ 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}"
- name: Execute diff-java-tool.jar with patch config
env:
CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/config.xml"
PATCH_CONFIG_XML: "${{ github.workspace }}/${{ env.CONFIG_DIR }}/patch-config.xml"
PROJECTS_YML: "${{ github.workspace }}/${{ 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 diff-java-tool.jar with with invalid arguments
env:
DIFFTOOL_JAR_PATH: "${{ github.workspace }}/${{ env.CI_TEMP_DIR }}/${{ env.DIFFTOOL_JAR }}"
run: |
echo "Running diff-java-tool.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'
set -e
if [ "$EXIT_CODE" -eq 1 ]; then
echo "Error Exit code was expected."
else
echo "Unexpected exit code: $EXIT_CODE"
exit 1
fi