Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add Github Actions workflow to check convergence in a release PR #1752

Merged
merged 9 commits into from
Mar 24, 2021
16 changes: 15 additions & 1 deletion .github/workflows/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ jobs:
with:
java-version: 8
- run: java -version
- run: .kokoro/dashboard.sh
- run: .kokoro/dashboard.sh
env:
JOB_TYPE: dashboard-units-check
dependency-convergence-check:
runs-on: ubuntu-latest
if: github.repository_owner == 'googleapis' && github.head_ref == 'release-please/branches/master'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 8
- run: java -version
- run: .kokoro/dashboard.sh
env:
JOB_TYPE: dependency-convergence-check
37 changes: 36 additions & 1 deletion .kokoro/dashboard.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,44 @@ scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))
## cd to the parent directory, i.e. the root of the git repo
cd ${scriptDir}/..

outputFile="$scriptDir/../dashboard/target/tmp/output.txt"
## Move into the dashboard directory
cd dashboard/

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

mvn --fail-at-end clean install
mvn --fail-at-end -DskipTests=true clean install
INSTALL_RETURN_CODE=$?
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
RETURN_CODE=${INSTALL_RETURN_CODE}

LINE_COUNT=0
set +e

case ${JOB_TYPE} in
dashboard-units-check)
echo -e "\n******************** RUNNING DASHBOARD TESTS ********************"
mvn test
RETURN_CODE=$?
;;
dependency-convergence-check)
echo -e "\n******************** CHECKING DEPENDENCY CONVERGENCE ********************"
mvn exec:java -Dexec.args="-f ../pom.xml -o target/tmp/output.txt"
CONVERGE_RETURN_CODE=$?
if [[ $INSTALL_RETURN_CODE -eq 0 && $CONVERGE_RETURN_CODE -eq 0 ]]
then
while IFS= read -r line; do
echo "$line"
LINE_COUNT=$((LINE_COUNT+1))
done < "$outputFile"
Comment on lines +48 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're just counting lines - cat "${outputFile}" | wc -l

fi
RETURN_CODE=${CONVERGE_RETURN_CODE}
;;
esac

if [[ $RETURN_CODE -ne 0 || $LINE_COUNT -gt 1 ]]
then
RETURN_CODE=1
fi

echo "exiting with ${RETURN_CODE}"
exit ${RETURN_CODE}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ boolean getReport() {
return commandLine.hasOption('r');
}

Path getOutputFile() {
if (!commandLine.hasOption('o')) {
return null;
}
return Paths.get(commandLine.getOptionValue('o').trim()).toAbsolutePath();
}

static DashboardArguments readCommandLine(String... arguments) throws ParseException {
CommandLineParser parser = new DefaultParser();

Expand Down Expand Up @@ -144,6 +151,15 @@ private static Options configureOptions() {
.desc("Whether to print the report or build the dashboard")
.build();
options.addOption(reportOption);

Option outputOption =
Option.builder("o")
.longOpt("output-file")
.hasArg()
.desc("Whether to print the report to a file or display on console")
.build();
options.addOption(outputOption);

return options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -89,7 +90,7 @@ public class DashboardMain {
*/
public static void main(String[] arguments)
throws IOException, TemplateException, RepositoryException, URISyntaxException,
ParseException, MavenRepositoryException {
ParseException, MavenRepositoryException {
DashboardArguments dashboardArguments = DashboardArguments.readCommandLine(arguments);

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

if (dashboardArguments.getReport()) {
if (!report(bom)) {
if (!report(bom,System.out)) {
throw new RuntimeException("Failed to converge dependencies");
}
} else {
generate(bom);
}

if (dashboardArguments.getOutputFile() != null) {
Path relativePath = dashboardArguments.getOutputFile();
Files.createDirectories(relativePath.getParent());
File file = new File(String.valueOf(relativePath));
OutputStream outputStream = new FileOutputStream(file);
if (!report(bom,outputStream)) {
throw new RuntimeException("Failed to converge dependencies");
}
outputStream.close();
}
}

private static void generateAllVersions(String versionlessCoordinates)
throws IOException, TemplateException, RepositoryException, URISyntaxException,
MavenRepositoryException {
MavenRepositoryException {
List<String> elements = Splitter.on(':').splitToList(versionlessCoordinates);
checkArgument(
elements.size() == 2,
Expand Down Expand Up @@ -178,7 +190,7 @@ private static ArtifactCache buildCache(Bom bom) {
return loadArtifactInfo(managedDependencies);
}

private static boolean report(Bom bom) {
private static boolean report(Bom bom, OutputStream outputStream) throws IOException {
ArtifactCache cache = buildCache(bom);
Map<Artifact, ArtifactInfo> infoMap = cache.getInfoMap();
String cloudBomVersion =
Expand All @@ -194,6 +206,7 @@ private static boolean report(Bom bom) {
Multimap<String, String> sharedDepsToLibraries = ArrayListMultimap.create();
ImmutableSortedSet.Builder<ComparableVersion> sharedDepsVersionsBuilder =
ImmutableSortedSet.reverseOrder();

for (Map.Entry<String, String> entry : sharedDependencyVersions.entrySet()) {
if (!entry.getValue().isEmpty()) {
sharedDepsToLibraries.put(entry.getValue(), entry.getKey());
Expand All @@ -203,32 +216,30 @@ private static boolean report(Bom bom) {

SortedSet<ComparableVersion> sharedDepsVersions = sharedDepsVersionsBuilder.build();
if (sharedDepsVersions.size() == 1) {
System.out.println("Shared dependencies converge \\o/");
outputStream.write("Shared dependencies converge \\o/\n".getBytes());
return true;
}

// Find the largest shared dependency version
ComparableVersion largest = null;
StringBuilder outputString = new StringBuilder();
for (ComparableVersion version : sharedDepsVersions) {
if (largest == null) {
largest = version;
System.out.println("Greatest shared-dependencies version: " + version.toString());
outputString.append("Greatest shared-dependencies version: ").append(version.toString());
} else {
Collection<String> artifacts = sharedDepsToLibraries.get(version.toString());
System.out.println("-----------------------");
System.out.println(
String.format(
"Found %d artifacts with shared-dependencies version: %s",
artifacts.size(), version.toString()));
;
outputString.append("\n-----------------------");
outputString.append("\nFound " + artifacts.size() + " artifacts with shared dependencies version: "+ version.toString());

for (String artifactKey : artifacts) {
String artifactVersion = currentVersions.get(artifactKey);
String artifact = artifactKey.split(":")[0];
System.out.println(String.format("- %s:%s", artifact, artifactVersion));
outputString.append("\n- " + artifact+":"+artifactVersion);
}
}
outputStream.write(outputString.toString().getBytes());
}

return false;
}

Expand Down