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

feat: add dependency versions script #741

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
945f7d1
Update ci.yaml
salehsquared Jul 24, 2020
d80399b
Check version of google-cloud-shared-config
salehsquared Jul 24, 2020
afc4204
Update pom.xml
salehsquared Jul 24, 2020
98282ff
Update ci.yaml
salehsquared Jul 24, 2020
1861d3b
Update pom.xml
salehsquared Jul 24, 2020
438e5fa
Update ci.yaml
salehsquared Jul 24, 2020
02e35fb
Update ci.yaml
salehsquared Jul 24, 2020
77be68a
Updating permissions on versions script
Jul 24, 2020
ed61410
deps: update dependency com.google.cloud:google-cloud-logging-logback…
salehsquared Jul 24, 2020
9f1fb9a
deps: update dependency com.google.cloud:google-cloud-firestore-bom t…
salehsquared Jul 24, 2020
e224876
Reverting pom.xml after testing changes
Jul 24, 2020
0edb0e5
Merge branch 'master' of https://github.com/salehsquared/java-cloud-bom
Jul 24, 2020
ed33def
Reverting POM version
Jul 24, 2020
b1fe397
Reverting POM version
Jul 24, 2020
14c43ec
Fixing formatting change on ci file
Jul 24, 2020
1150208
Fixing formatting change on ci file
Jul 24, 2020
2616081
Fix for formatting end of file
Jul 24, 2020
b164f1a
Updated dependencies scripts. Separated out, so one script checks for…
Jul 29, 2020
1ad1ae1
Setting ci.yaml file back to original
Jul 29, 2020
807140c
Merge branch 'dependency-versions' of https://github.com/salehsquared…
Jul 30, 2020
9ad1268
Updates to make deps-finder more stable, including using regex. Also …
Jul 30, 2020
8affd08
Updated deps-finder according to comments from Stephanie, Elliotte, a…
Jul 30, 2020
ebbdf93
Updating pom.xml to master branch
Jul 30, 2020
8310661
Merge branch 'master' into dependency-versions
salehsquared Jul 30, 2020
7d745a5
Formatting and curl fixes
Jul 30, 2020
0c7f9b6
Merge branch 'dependency-versions' of https://github.com/salehsquared…
Jul 30, 2020
9d30f20
Merge branch 'master' of https://github.com/googleapis/java-cloud-bom…
Jul 31, 2020
741029e
Separate script for helper functions, conventionalized syntax, verbos…
Jul 31, 2020
39a4c5e
Updated release-versions to match conventions & be more stable readin…
Aug 2, 2020
3039986
Merge branch 'master' into dependency-versions
stephaniewang526 Aug 4, 2020
00f6482
Merge branch 'master' into dependency-versions
stephaniewang526 Aug 4, 2020
0b51040
Merge branch 'master' into dependency-versions
salehsquared Aug 5, 2020
df19e1c
Reformatted comments and added licensing
Aug 5, 2020
518f622
Last commenting format change
Aug 5, 2020
806be9d
Reformatted to IntelliJ standards
Aug 5, 2020
0c0e543
Removing extra words in comment
Aug 5, 2020
ca0ec24
Merge branch 'master' into dependency-versions
salehsquared Aug 9, 2020
4009c11
Place checkLibrary into shared-deps-helper.sh. Fixed comment and argu…
Aug 10, 2020
c0ce06f
Place checkLibrary into shared-deps-helper.sh. Fixed comment and argu…
Aug 10, 2020
f25db57
Merge branch 'dependency-versions' of https://github.com/salehsquared…
Aug 10, 2020
bdaa2e9
Removes shared-deps-helper dependence on separated lines
Aug 10, 2020
26c6b6b
No longer depending on spacing or line breaks.
Aug 11, 2020
782176b
Merge branch 'master' into dependency-versions
salehsquared Aug 11, 2020
02b6eb1
Merge branch 'master' into dependency-versions
stephaniewang526 Aug 16, 2020
61e3153
Removed bash scripts and replaced with dependency convergence script …
Aug 18, 2020
b772048
Added POM File Change for DependencyUpdateTest & Removed Bash Scripts
Aug 18, 2020
043e903
Fixed accidental removal of dependencies.sh
Aug 18, 2020
fc11734
Removed deps-finder.sh
Aug 18, 2020
1c56168
Cleaned up pom.xml file
Aug 18, 2020
44b422a
Cleaned up and removed unnecessary code
Aug 18, 2020
7f7a55e
Cleaned code significantly using enum
Aug 18, 2020
dc0a76e
Removed unnecessary import
Aug 18, 2020
61e5c26
Styling and removed unnecessary imports
Aug 18, 2020
6324604
Merge branch 'master' into dependency-versions
salehsquared Aug 18, 2020
8810d5f
Added JUnit Testing and updated Arguments link
Aug 18, 2020
048ed26
Merge branch 'dependency-versions' of https://github.com/salehsquared…
Aug 18, 2020
4dbc17b
Fixes for Jeff's & Elliotte's comments. Now wrapped in Bash script, n…
Aug 19, 2020
87f8c8d
Placed into com.google.cloud. More descriptive error messages. Slight…
Aug 19, 2020
fab9af0
Slight change to dependencies script
Aug 19, 2020
f07dd58
Merge branch 'master' into dependency-versions
salehsquared Aug 20, 2020
9dc9352
Fixed styling, added new test
Aug 20, 2020
125592c
Styling changes
Aug 20, 2020
535b378
Merge branch 'master' into dependency-versions
salehsquared Aug 20, 2020
9edb579
Merge branch 'master' into dependency-versions
salehsquared Aug 25, 2020
ce9f1a1
Merge branch 'master' into dependency-versions
salehsquared Aug 26, 2020
4098f96
Merge branch 'master' into dependency-versions
stephaniewang526 Aug 27, 2020
26b4049
Merge branch 'master' into dependency-versions
salehsquared Sep 15, 2020
ea188ac
Update RecentCommitCheckTest.java
salehsquared Sep 15, 2020
034fdca
Merge branch 'master' into dependency-versions
salehsquared Sep 15, 2020
d63bce8
Merge branch 'master' into dependency-versions
stephaniewang526 Sep 16, 2020
9ec29e2
Merge branch 'master' into dependency-versions
salehsquared Sep 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .kokoro/shared-dependencies-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Print out Java
java -version

# Get the directory of the build script
scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}"))

# Returns 0 if this is a release branch
function isReleaseBranch() {
# Check if we're currently on a non-SNAPSHOT release branch.
currBranch=$(git rev-parse --abbrev-ref HEAD | grep "release-v")
snapShotCheck=$(echo ${currBranch} | grep "\-SNAPSHOT")
# Return 1 (failure) if this is not a release branch
if [[ -z ${currBranch} ]] || [[ ! -z ${snapShotCheck} ]]; then
return 1
fi
echo ${currBranch}
return 0
}

# Returns 0 if a library update commit was found, and 1 otherwise.
# Echos commit message (if found) before completion.
function getLibraryUpdateCommit() {
currentCommitNumber=$(git rev-parse HEAD)

# Check if we're updating a dependency including shared-dependencies.
currentCommitMessage=$(git log -1 ${currentCommitNumber} | grep "deps: update dependency com.google.cloud:google-cloud-")

if [[ -z ${currentCommitMessage} ]]; then
return 1
fi

echo ${currentCommitMessage}
return 0
}

runRelease=$(isReleaseBranch)
returnValue=$?
# If this is a release branch
if [[ ${returnValue} -eq 0 ]]; then
# go to the dependency-convergence directory, i.e. our container for the script
pushd "${scriptDir}/../dependency-convergence"
mvn clean install -DskipTests
# Single quotes around double quotes so that the branch name is counted as only one argument
mvn exec:java -Dexec.args="'${runRelease}'"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest we break these into separate checks (rather than re-using the same check). We can run these from GitHub actions and skip if the commit does not match what we expect.

exitCode=$?
popd
exit ${exitCode}
fi

libraryUpdate=$(getLibraryUpdateCommit)
returnValue=$?

if [[ ${returnValue} -eq 0 ]]; then
# go to the dependency-convergence directory, i.e. our container for the script
pushd "${scriptDir}/../dependency-convergence"
mvn clean install -DskipTests
mvn exec:java -e -Dexec.args="'${libraryUpdate}'"
exitCode=$?
popd
exit ${exitCode}
fi

echo "No release or library updates found! Assuming no error."
salehsquared marked this conversation as resolved.
Show resolved Hide resolved
exit 0
61 changes: 61 additions & 0 deletions dependency-convergence/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.cloud.tools</groupId>
<artifactId>dependencies-parent</artifactId>
<version>1.5.0</version>
</parent>
<groupId>com.google.cloud.tools</groupId>
<artifactId>google-cloud-bom-dependencies-check</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>Google Cloud BOM Dependencies Check</name>
<organization>
<name>Google LLC.</name>
<url>https://www.google.com</url>
</organization>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>dependencies</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<mainClass>cloudbomcommitcheck.RecentCommitCheck</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cloudbomcommitcheck;
salehsquared marked this conversation as resolved.
Show resolved Hide resolved

import java.nio.file.Path;
import java.nio.file.Paths;
import javax.annotation.Nullable;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/**
* Command-line option for {@link RecentCommitCheck}. The tool takes either a pom.xml file path or
* Maven coordinates for a BOM.
*
* @see <a href="https://github.com/googleapis/java-cloud-bom/blob/master/dashboard/src/main/java/com/google/cloud/tools/opensource/cloudbomdashboard/DashboardArguments.java"</a>
*/
final class Arguments {

private static final Options options = configureOptions();
private static final HelpFormatter helpFormatter = new HelpFormatter();

private final CommandLine commandLine;

private Arguments(CommandLine commandLine) {
this.commandLine = commandLine;
}

/**
* Returns true if the argument for a file is specified. False if the argument for coordinates is
* specified.
*
* <p>It is guaranteed that either a file path or Maven coordinates for a BOM are available.
*/
boolean hasFile() {
return commandLine.hasOption('f');
}

/**
* Returns true if the argument for a versionless coordinates is specified; otherwise false.
*
* <p>It is guaranteed that either a file path or Maven coordinates for a BOM are available.
*/
boolean hasVersionlessCoordinates() {
return commandLine.hasOption('a');
}

/**
* Returns an absolute path to pom.xml file of a BOM. Null if file is not specified.
*/
@Nullable
Path getBomFile() {
if (!commandLine.hasOption('f')) {
return null;
}
// Trim the value so that maven exec plugin can pass arguments with exec.arguments="-f pom.xml"
return Paths.get(commandLine.getOptionValue('f').trim()).toAbsolutePath();
}

/**
* Returns the Maven coordinates of a BOM. Null if coordinates are not specified.
*/
@Nullable
String getBomCoordinates() {
if (!commandLine.hasOption('c')) {
return null;
}
return commandLine.getOptionValue('c').trim();
}

/**
* Returns the versionless Maven coordinates of a BOM. Null if versionless coordinates are not
* specified.
*/
@Nullable
String getVersionlessCoordinates() {
if (!commandLine.hasOption('a')) {
return null;
}
return commandLine.getOptionValue('a').trim();
}

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

try {
// Throws ParseException if required option group ('-f' or '-c') is not specified
return new Arguments(parser.parse(options, arguments));
} catch (ParseException ex) {
helpFormatter.printHelp("DashboardMain", options);
throw ex;
}
}

private static Options configureOptions() {
Options options = new Options();
OptionGroup inputGroup = new OptionGroup();
inputGroup.setRequired(true);

Option inputFileOption =
Option.builder("f").longOpt("bom-file").hasArg().desc("File to a BOM (pom.xml)").build();
inputGroup.addOption(inputFileOption);

Option inputCoordinatesOption =
Option.builder("c")
.longOpt("bom-coordinates")
.hasArg()
.desc(
"Maven coordinates of a BOM. For example, com.google.cloud:libraries-bom:1.0.0")
.build();
inputGroup.addOption(inputCoordinatesOption);

Option versionlessCoordinatesOption =
Option.builder("a")
.longOpt("all-versions")
.hasArg()
.desc(
"Maven coordinates of a BOM without version. "
+ "For example, com.google.cloud:libraries-bom")
.build();
inputGroup.addOption(versionlessCoordinatesOption);

options.addOptionGroup(inputGroup);
return options;
}
}
Loading