-
Notifications
You must be signed in to change notification settings - Fork 15
197 lines (170 loc) · 7.08 KB
/
check-deps.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
192
193
194
195
196
197
name: Check for dependency changes
on:
workflow_dispatch:
schedule:
- cron: '*/60 * * * *'
jobs:
check-for-dependency-changes:
outputs:
hasChanged: ${{ steps.compareDependencyChanges.outputs.hasChanged }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: 8
distribution: 'temurin'
cache: 'maven'
- name: Set settings.xml
uses: s4u/[email protected]
with:
servers: |
[{
"id": "mks-private-repo",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-private",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-public-snapshots",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-public-releases",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-private-snapshots",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-private-releases",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
}]
- name: Check for dependency changes
id: compareDependencyChanges
shell: bash
run: |
#!/usr/bin/env bash
set -e
# Download the remote dependency report
remoteRepoUrl=https://nexus.mekomsolutions.net/repository/maven-public
# Get the list of sub-modules
modules=$(mvn -q -Pprod --also-make exec:exec -Dexec.executable="echo" -Dexec.args='${project.build.directory}')
echo "Modules to check"
echo "$modules"
# Build the local dependency report
echo "Compile a local dependency report..."
mvn clean compile -P prod
# Iterate over each module
for module in $modules; do
modulePath=$(echo $module | sed 's/\\/\//g')
# Navigate to the module directory
cd $(dirname $modulePath)
# Get the groupId, artifactId, and version
groupId=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
classifier=$(mvn help:evaluate -Dexpression=dependencyReportClassifier -q -DforceStdout)
artifact="${groupId}":"${artifactId}":"${version}":txt:"${classifier}"
# Module details
echo "Module: $module"
echo "GroupId: $groupId"
echo "ArtifactId: $artifactId"
echo "Version: $version"
echo ""
filename=${artifactId}-${version}-${classifier}.txt
absolutePath=/tmp/$filename
# Remove previous file if any
rm -f "${absolutePath}"
# Fetch the remote dependency report
echo "Fetch remote dependency report..."
set +e
mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:get -DremoteRepositories=${remoteRepoUrl} -Dartifact=${artifact} -Dtransitive=false
mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:copy -Dartifact=${artifact} -DoutputDirectory=/tmp/ -Dmdep.useBaseVersion=true
set -e
# If no dependency report was fetched, create an empty one.
if [ ! -f "$absolutePath" ]; then
echo "Remote dependency file is not found at '${absolutePath}'. Creating an empty one and continue."
touch "${absolutePath}"
else
echo "Remote dependency file saved at '${absolutePath}'."
fi
# Compare the 2 files. Will exit with 0 if no change, 1 if changes
echo "Compare both dependency reports..."
set +e
if [ -f ./target/"${filename}" ]; then
diff "${absolutePath}" ./target/"${filename}"
diff_rc=$?
if [ $diff_rc -eq 0 ]; then
echo "No dependency change. Exit (0)"
elif [ $diff_rc -eq 1 ]; then
echo "One or more dependency has changed. Exit (1)"
else
echo "Unknown error occured."
fi
# Export result code to be used in later steps of the GitHub worklow.
set +e
echo ::set-env name=hasChanged::$diff_rc
echo hasChanged=$diff_rc >> "$GITHUB_OUTPUT"
set -e
else
echo "File ./target/${filename} does not exist."
fi
set -e
# Navigate back to the parent directory
cd -
done
exit 0
build:
needs: check-for-dependency-changes
if: ${{ needs.check-for-dependency-changes.outputs.hasChanged == '1' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ inputs.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.java-version }}
distribution: ${{ inputs.java-distribution }}
cache: 'maven'
- name: Set settings.xml
uses: s4u/[email protected]
with:
servers: |
[{
"id": "mks-private-repo",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-public-snapshots",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-public-releases",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-private-snapshots",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
},
{
"id": "mks-nexus-private-releases",
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}",
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}"
}]
- name: Build
run: "mvn --batch-mode clean package ${{ inputs.maven-args }}"