Skip to content

Commit 7124aa1

Browse files
authored
Add option for automatically updating lockfile (stringbean#31)
* Update sbt, plugins & dependencies * Add option for automatically updating lockfile * Update docs * Update workflow
1 parent f9cfdad commit 7124aa1

File tree

16 files changed

+294
-14
lines changed

16 files changed

+294
-14
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
- uses: actions/setup-java@v2
2020
with:
2121
java-version: ${{matrix.java}}
22-
distribution: adopt
22+
distribution: temurin
2323
- name: Run tests
24-
uses: lokkju/github-action-sbt@master
25-
with:
26-
commands: test scripted headerCheck scapegoat
24+
run: sbt test scripted headerCheck scapegoat

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ libraryDependencies ++= Seq(
1919

2020
libraryDependencies ++= Seq(
2121
"software.purpledragon" %% "text-utils" % "1.3.1",
22-
"org.scalatest" %% "scalatest" % "3.2.9" % Test
22+
"org.scalatest" %% "scalatest" % "3.2.12" % Test
2323
)
2424

2525
organizationName := "Michael Stringer"
@@ -30,7 +30,7 @@ scriptedLaunchOpts := { scriptedLaunchOpts.value ++
3030
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
3131
}
3232

33-
ThisBuild / scapegoatVersion := "1.4.9"
33+
ThisBuild / scapegoatVersion := "1.4.11"
3434

3535
developers := List(
3636
Developer("stringbean", "Michael Stringer", "@the_stringbean", url("https://github.com/stringbean"))

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.5.3
1+
sbt.version=1.6.2

project/plugins.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// publishing
22
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
3-
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.0.15")
4-
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")
3+
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
4+
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.11")
55

66
// code style
7-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
8-
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.1.0")
7+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.7.0")
8+
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.1.1")
99

1010
// documentation
1111
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")

src/main/paradox/settings.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ The different levels of checking available are:
1818

1919
* `CheckDisabled`: no checks will be performed after `update`s.
2020
* `WarnOnError`: a check will be performed after `update`s, and a warning printed if there are any changes.
21-
* `FailOnError`: a check will be performed after `update`s, and the build will fail if there are any changes.
21+
* `FailOnError`: a check will be performed after `update`s, and the build will fail if there are any changes.
22+
* `AutoUpdate`: a check will be performed after `update`s, and the lockfile will be automatically updated if there are
23+
any changes.

src/main/resources/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ lock.status.failed.long=Dependency lock check failed:\n{0}
77

88
update.status.warning=Dependency lockfile is outdated - please run `dependencyLockCheck` for details
99
update.status.error=Dependency lockfile is outdated
10+
update.status.auto=Dependency lockfile is outdated - automatically updating
1011

1112
# lockfile short status - configurations ======================================
1213
lock.status.configs.info=\ \ {0} added and {1} removed

src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package software.purpledragon.sbt.lock
1818

19-
import sbt.Keys._
2019
import sbt._
20+
import sbt.Keys._
2121
import sbt.internal.util.ManagedLogger
2222
import software.purpledragon.sbt.lock.DependencyLockUpdateMode._
2323
import software.purpledragon.sbt.lock.model.{DependencyLockFile, LockFileMatches}
@@ -100,6 +100,12 @@ object DependencyLockPlugin extends AutoPlugin {
100100
case (_, FailOnError) =>
101101
logger.error(MessageUtil.formatMessage("update.status.error"))
102102
sys.error(changes.toLongReport)
103+
case (_, AutoUpdate) =>
104+
logger.warn(MessageUtil.formatMessage("update.status.auto"))
105+
106+
// rewrite the lockfile
107+
val dest = dependencyLockFile.value
108+
DependencyLockIO.writeLockFile(updatedFile, dest)
103109

104110
case _ =>
105111
// scenario shouldn't happen - failed check, but we're not checking...

src/main/scala/software/purpledragon/sbt/lock/DependencyLockUpdateMode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ package software.purpledragon.sbt.lock
1919
object DependencyLockUpdateMode extends Enumeration {
2020
type DependencyLockUpdateMode = Value
2121

22-
val CheckDisabled, WarnOnError, FailOnError = Value
22+
val CheckDisabled, WarnOnError, FailOnError, AutoUpdate = Value
2323
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
scalaVersion := "2.12.10"
2+
3+
libraryDependencies ++= Seq(
4+
"org.apache.commons" % "commons-lang3" % "3.9",
5+
// lockfile has 3.0.8
6+
"org.scalatest" %% "scalatest" % "3.0.7" % Test
7+
)
8+
9+
dependencyLockAutoCheck := DependencyLockUpdateMode.AutoUpdate
10+
11+
val checkLog = taskKey[Unit]("checks the contents of the log")
12+
val checkLockfile = taskKey[Unit]("checks the contents of the lockfile")
13+
14+
checkLog := {
15+
val lastLog = BuiltinCommands.lastLogFile(state.value).get
16+
val last = IO.read(lastLog)
17+
18+
if (!last.contains("Dependency lockfile is outdated")) {
19+
sys.error("check did not contain warning")
20+
}
21+
}
22+
23+
checkLockfile := {
24+
val lockfile = dependencyLockRead.value.getOrElse(sys.error("Failed to read updated lockfile"))
25+
26+
val scalatest = lockfile.dependencies
27+
.find(dep => dep.org == "org.scalatest" && dep.name == "scalatest_2.12")
28+
.getOrElse(sys.error("Failed to find scalatest dependency"))
29+
30+
if (scalatest.version != "3.0.7") {
31+
sys.error("Updated lockfile had incorrect scalatest version")
32+
}
33+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"lockVersion" : 1,
3+
"timestamp" : "2019-11-21T18:42:01.200Z",
4+
"configurations" : [
5+
"compile",
6+
"optional",
7+
"provided",
8+
"runtime",
9+
"test"
10+
],
11+
"dependencies" : [
12+
{
13+
"org" : "org.apache.commons",
14+
"name" : "commons-lang3",
15+
"version" : "3.9",
16+
"artifacts" : [
17+
{
18+
"name" : "commons-lang3.jar",
19+
"hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5"
20+
}
21+
],
22+
"configurations" : [
23+
"test",
24+
"compile",
25+
"runtime"
26+
]
27+
},
28+
{
29+
"org" : "org.scala-lang",
30+
"name" : "scala-library",
31+
"version" : "2.12.10",
32+
"artifacts" : [
33+
{
34+
"name" : "scala-library.jar",
35+
"hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda"
36+
}
37+
],
38+
"configurations" : [
39+
"test",
40+
"compile",
41+
"runtime"
42+
]
43+
},
44+
{
45+
"org" : "org.scala-lang",
46+
"name" : "scala-reflect",
47+
"version" : "2.12.10",
48+
"artifacts" : [
49+
{
50+
"name" : "scala-reflect.jar",
51+
"hash" : "sha1:14cb7beb516cd8e07716133668c427792122c926"
52+
}
53+
],
54+
"configurations" : [
55+
"test"
56+
]
57+
},
58+
{
59+
"org" : "org.scala-lang.modules",
60+
"name" : "scala-xml_2.12",
61+
"version" : "1.2.0",
62+
"artifacts" : [
63+
{
64+
"name" : "scala-xml_2.12.jar",
65+
"hash" : "sha1:5d38ac30beb8420dd395c0af447ba412158965e6"
66+
}
67+
],
68+
"configurations" : [
69+
"test"
70+
]
71+
},
72+
{
73+
"org" : "org.scalactic",
74+
"name" : "scalactic_2.12",
75+
"version" : "3.0.8",
76+
"artifacts" : [
77+
{
78+
"name" : "scalactic_2.12.jar",
79+
"hash" : "sha1:b50559dfc4a691c1089f9c8812e1d6fd17f80277"
80+
}
81+
],
82+
"configurations" : [
83+
"test"
84+
]
85+
},
86+
{
87+
"org" : "org.scalatest",
88+
"name" : "scalatest_2.12",
89+
"version" : "3.0.8",
90+
"artifacts" : [
91+
{
92+
"name" : "scalatest_2.12.jar",
93+
"hash" : "sha1:8493ffa579676977b810a7a9fdc23af9d3c8af7f"
94+
}
95+
],
96+
"configurations" : [
97+
"test"
98+
]
99+
}
100+
]
101+
}

0 commit comments

Comments
 (0)