Skip to content

Commit 7e3b00e

Browse files
authored
ci: add Github Actions workflow to check convergence in a release PR (#1752)
1 parent 0eb9f4e commit 7e3b00e

4 files changed

Lines changed: 92 additions & 16 deletions

File tree

.github/workflows/dashboard.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ jobs:
1313
with:
1414
java-version: 8
1515
- run: java -version
16-
- run: .kokoro/dashboard.sh
16+
- run: .kokoro/dashboard.sh
17+
env:
18+
JOB_TYPE: dashboard-units-check
19+
dependency-convergence-check:
20+
runs-on: ubuntu-latest
21+
if: github.repository_owner == 'googleapis' && github.head_ref == 'release-please/branches/master'
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-java@v1
25+
with:
26+
java-version: 8
27+
- run: java -version
28+
- run: .kokoro/dashboard.sh
29+
env:
30+
JOB_TYPE: dependency-convergence-check

.kokoro/dashboard.sh

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,44 @@ scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
2020
## cd to the parent directory, i.e. the root of the git repo
2121
cd ${scriptDir}/..
2222

23+
outputFile="$scriptDir/../dashboard/target/tmp/output.txt"
2324
## Move into the dashboard directory
2425
cd dashboard/
2526

2627
echo -e "\n******************** BUILDING THE DASHBOARD ********************"
2728

28-
mvn --fail-at-end clean install
29+
mvn --fail-at-end -DskipTests=true clean install
30+
INSTALL_RETURN_CODE=$?
31+
RETURN_CODE=${INSTALL_RETURN_CODE}
32+
33+
LINE_COUNT=0
34+
set +e
35+
36+
case ${JOB_TYPE} in
37+
dashboard-units-check)
38+
echo -e "\n******************** RUNNING DASHBOARD TESTS ********************"
39+
mvn test
40+
RETURN_CODE=$?
41+
;;
42+
dependency-convergence-check)
43+
echo -e "\n******************** CHECKING DEPENDENCY CONVERGENCE ********************"
44+
mvn exec:java -Dexec.args="-f ../pom.xml -o target/tmp/output.txt"
45+
CONVERGE_RETURN_CODE=$?
46+
if [[ $INSTALL_RETURN_CODE -eq 0 && $CONVERGE_RETURN_CODE -eq 0 ]]
47+
then
48+
while IFS= read -r line; do
49+
echo "$line"
50+
LINE_COUNT=$((LINE_COUNT+1))
51+
done < "$outputFile"
52+
fi
53+
RETURN_CODE=${CONVERGE_RETURN_CODE}
54+
;;
55+
esac
56+
57+
if [[ $RETURN_CODE -ne 0 || $LINE_COUNT -gt 1 ]]
58+
then
59+
RETURN_CODE=1
60+
fi
61+
62+
echo "exiting with ${RETURN_CODE}"
63+
exit ${RETURN_CODE}

dashboard/src/main/java/com/google/cloud/tools/opensource/cloudbomdashboard/DashboardArguments.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ boolean getReport() {
9696
return commandLine.hasOption('r');
9797
}
9898

99+
Path getOutputFile() {
100+
if (!commandLine.hasOption('o')) {
101+
return null;
102+
}
103+
return Paths.get(commandLine.getOptionValue('o').trim()).toAbsolutePath();
104+
}
105+
99106
static DashboardArguments readCommandLine(String... arguments) throws ParseException {
100107
CommandLineParser parser = new DefaultParser();
101108

@@ -144,6 +151,15 @@ private static Options configureOptions() {
144151
.desc("Whether to print the report or build the dashboard")
145152
.build();
146153
options.addOption(reportOption);
154+
155+
Option outputOption =
156+
Option.builder("o")
157+
.longOpt("output-file")
158+
.hasArg()
159+
.desc("Whether to print the report to a file or display on console")
160+
.build();
161+
options.addOption(outputOption);
162+
147163
return options;
148164
}
149165
}

dashboard/src/main/java/com/google/cloud/tools/opensource/cloudbomdashboard/DashboardMain.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.File;
4242
import java.io.FileOutputStream;
4343
import java.io.IOException;
44+
import java.io.OutputStream;
4445
import java.io.OutputStreamWriter;
4546
import java.io.Writer;
4647
import java.net.URISyntaxException;
@@ -89,7 +90,7 @@ public class DashboardMain {
8990
*/
9091
public static void main(String[] arguments)
9192
throws IOException, TemplateException, RepositoryException, URISyntaxException,
92-
ParseException, MavenRepositoryException {
93+
ParseException, MavenRepositoryException {
9394
DashboardArguments dashboardArguments = DashboardArguments.readCommandLine(arguments);
9495

9596
// If looking to edit the dashboard structure, see DashboardMain#generateDashboard.
@@ -110,17 +111,28 @@ public static void main(String[] arguments)
110111
}
111112

112113
if (dashboardArguments.getReport()) {
113-
if (!report(bom)) {
114+
if (!report(bom,System.out)) {
114115
throw new RuntimeException("Failed to converge dependencies");
115116
}
116117
} else {
117118
generate(bom);
118119
}
120+
121+
if (dashboardArguments.getOutputFile() != null) {
122+
Path relativePath = dashboardArguments.getOutputFile();
123+
Files.createDirectories(relativePath.getParent());
124+
File file = new File(String.valueOf(relativePath));
125+
OutputStream outputStream = new FileOutputStream(file);
126+
if (!report(bom,outputStream)) {
127+
throw new RuntimeException("Failed to converge dependencies");
128+
}
129+
outputStream.close();
130+
}
119131
}
120132

121133
private static void generateAllVersions(String versionlessCoordinates)
122134
throws IOException, TemplateException, RepositoryException, URISyntaxException,
123-
MavenRepositoryException {
135+
MavenRepositoryException {
124136
List<String> elements = Splitter.on(':').splitToList(versionlessCoordinates);
125137
checkArgument(
126138
elements.size() == 2,
@@ -178,7 +190,7 @@ private static ArtifactCache buildCache(Bom bom) {
178190
return loadArtifactInfo(managedDependencies);
179191
}
180192

181-
private static boolean report(Bom bom) {
193+
private static boolean report(Bom bom, OutputStream outputStream) throws IOException {
182194
ArtifactCache cache = buildCache(bom);
183195
Map<Artifact, ArtifactInfo> infoMap = cache.getInfoMap();
184196
String cloudBomVersion =
@@ -194,6 +206,7 @@ private static boolean report(Bom bom) {
194206
Multimap<String, String> sharedDepsToLibraries = ArrayListMultimap.create();
195207
ImmutableSortedSet.Builder<ComparableVersion> sharedDepsVersionsBuilder =
196208
ImmutableSortedSet.reverseOrder();
209+
197210
for (Map.Entry<String, String> entry : sharedDependencyVersions.entrySet()) {
198211
if (!entry.getValue().isEmpty()) {
199212
sharedDepsToLibraries.put(entry.getValue(), entry.getKey());
@@ -203,32 +216,30 @@ private static boolean report(Bom bom) {
203216

204217
SortedSet<ComparableVersion> sharedDepsVersions = sharedDepsVersionsBuilder.build();
205218
if (sharedDepsVersions.size() == 1) {
206-
System.out.println("Shared dependencies converge \\o/");
219+
outputStream.write("Shared dependencies converge \\o/\n".getBytes());
207220
return true;
208221
}
209222

210223
// Find the largest shared dependency version
211224
ComparableVersion largest = null;
225+
StringBuilder outputString = new StringBuilder();
212226
for (ComparableVersion version : sharedDepsVersions) {
213227
if (largest == null) {
214228
largest = version;
215-
System.out.println("Greatest shared-dependencies version: " + version.toString());
229+
outputString.append("Greatest shared-dependencies version: ").append(version.toString());
216230
} else {
217231
Collection<String> artifacts = sharedDepsToLibraries.get(version.toString());
218-
System.out.println("-----------------------");
219-
System.out.println(
220-
String.format(
221-
"Found %d artifacts with shared-dependencies version: %s",
222-
artifacts.size(), version.toString()));
223-
;
232+
outputString.append("\n-----------------------");
233+
outputString.append("\nFound " + artifacts.size() + " artifacts with shared dependencies version: "+ version.toString());
234+
224235
for (String artifactKey : artifacts) {
225236
String artifactVersion = currentVersions.get(artifactKey);
226237
String artifact = artifactKey.split(":")[0];
227-
System.out.println(String.format("- %s:%s", artifact, artifactVersion));
238+
outputString.append("\n- " + artifact+":"+artifactVersion);
228239
}
229240
}
241+
outputStream.write(outputString.toString().getBytes());
230242
}
231-
232243
return false;
233244
}
234245

0 commit comments

Comments
 (0)