Skip to content

Commit 2cbd2db

Browse files
authored
manage versions in root build.sbt and update script (#1013)
1 parent 50768f6 commit 2cbd2db

5 files changed

Lines changed: 62 additions & 6 deletions

File tree

build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name := "codepropertygraph"
2+
3+
// parsed by project/Versions.scala, updated by updateDependencies.sh
4+
val overflowdbVersion = "1.19"
5+
26
inThisBuild(
37
List(
48
organization := "io.shiftleft",

domainClasses/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "codepropertygraph-domain-classes"
22

3-
libraryDependencies += "io.shiftleft" %% "overflowdb-traversal" % "1.19"
3+
libraryDependencies += "io.shiftleft" %% "overflowdb-traversal" % Versions.overflowdb
44
dependsOn(Projects.schema)
55

66
lazy val mergeSchemaTask = taskKey[File]("Merge schemas")

project/Utils.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
object Versions {
2-
val scalatest = "3.1.1"
3-
val antlr = "4.7.2"
4-
}
5-
61
object GitLFSUtils {
72
def isGitLFSEnabled(): Boolean = {
83
import scala.sys.process._

project/Versions.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* reads version declarations from /build.sbt so that we can declare them in one place */
2+
object Versions {
3+
val overflowdb = parseVersion("overflowdbVersion")
4+
val scalatest = "3.1.1"
5+
val antlr = "4.7.2"
6+
7+
private def parseVersion(key: String): String = {
8+
val versionRegexp = s""".*val $key[ ]+=[ ]?"(.*?)"""".r
9+
val versions: List[String] = scala.io.Source
10+
.fromFile("build.sbt")
11+
.getLines
12+
.filter(_.contains(s"val $key"))
13+
.collect { case versionRegexp(version) => version }
14+
.toList
15+
assert(
16+
versions.size == 1,
17+
s"""unable to extract $key from build.sbt, expected exactly one line like `val $key= "0.0.0-SNAPSHOT"`.""")
18+
versions.head
19+
}
20+
21+
}

updateDependencies.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
NON_INTERACTIVE_OPTION=$1
3+
DEPENDENCY=$2
4+
5+
function update {
6+
local NAME=$1
7+
local REPO=$2
8+
9+
local HIGHEST_TAG=`git ls-remote --tags $REPO | awk -F"/" '{print $3}' | grep '^v[0-9]*\.[0-9]*' | grep -v {} | sort --version-sort | tail -n1`
10+
# drop initial v from git tag
11+
local VERSION=${HIGHEST_TAG:1}
12+
local SEARCH="val ${NAME}Version\([ ]*\)= .*"
13+
local REPLACE="val ${NAME}Version\1= \"$VERSION\""
14+
15+
if [ "$NON_INTERACTIVE_OPTION" == "--non-interactive" ]; then
16+
echo "non-interactive mode, auto-updating the ${NAME} dependency"
17+
sed -i "s/$SEARCH/$REPLACE/" build.sbt
18+
else
19+
echo "set version for $NAME to $VERSION? [Y/n]"
20+
read ANSWER
21+
if [ -z $ANSWER ] || [ "y" == $ANSWER ] || [ "Y" == $ANSWER ]; then
22+
sed -i "s/$SEARCH/$REPLACE/" build.sbt
23+
fi
24+
fi
25+
}
26+
27+
if [ "$DEPENDENCY" == "" ]; then
28+
update overflowdb git@github.com:ShiftLeftSecurity/overflowdb.git
29+
else
30+
DEPENDENCY="${DEPENDENCY#--only=}"
31+
if [ "$DEPENDENCY" == "overflowdb" ]; then
32+
update overflowdb git@github.com:ShiftLeftSecurity/overflowdb.git
33+
else
34+
echo "Unknown dependency: $DEPENDENCY. Aborting."
35+
fi
36+
fi

0 commit comments

Comments
 (0)