Skip to content

Commit

Permalink
Merge pull request #17 from hmrc/update
Browse files Browse the repository at this point in the history
Remove nscala-time and update org.eclipse.jgit
  • Loading branch information
colin-lamed authored Nov 21, 2024
2 parents 879607d + f8f058a commit 7a6e3a7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,47 @@ Since major version 6, this plugin is cross compiled for sbt 1.x (specifically 1

Add the following to your `project/plugins.sbt`:

```
```scala
resolvers += Resolver.url("hmrc-sbt-plugin-releases",
url("https://dl.bintray.com/hmrc/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-git-stamp" % "INSERT_VERSION")
```
```

Add the following near the top of your `build.sbt` file (if you are using a full build config, I'm sure you can figure
it out):
Add the following near the top of your `build.sbt` file:

import uk.gov.hmrc.gitstamp.GitStampPlugin._
```scala
import uk.gov.hmrc.gitstamp.GitStampPlugin._
```

Then, add this lower down:

Seq( gitStampSettings: _* )
```scala
Seq(gitStampSettings: _*)
```

Then, just build as normal. This plugin won't add any tasks, or otherwise change the way you interact with SBT.

Your artifacts will just come out with a `MANIFEST.MF` file that looks something like this:

Manifest-Version: 1.0
Implementation-Vendor: My-Company
Implementation-Title: My Project
Implementation-Version: 0.1
Implementation-Vendor-Id: My-Company
Specification-Vendor: My-Company
Git-Repo-Is-Clean: false
Git-Branch: gitstamp
Specification-Title: My Company
Git-Build-Date: 2013-04-26T17:22:58.538-07:00
Specification-Version: 0.1
Git-Head-Rev: b0d5a67d59dc7c0133aecce2e2ceb18fc8d23597
Git-Describe: release/0.3.5-b0d5a67
```
Manifest-Version: 1.0
Implementation-Vendor: My-Company
Implementation-Title: My Project
Implementation-Version: 0.1
Implementation-Vendor-Id: My-Company
Specification-Vendor: My-Company
Git-Repo-Is-Clean: false
Git-Branch: gitstamp
Specification-Title: My Company
Git-Build-Date: 2013-04-26T17:22:58.538-07:00
Specification-Version: 0.1
Git-Head-Rev: b0d5a67d59dc7c0133aecce2e2ceb18fc8d23597
Git-Describe: release/0.3.5-b0d5a67
```

The entries starting with `Git-` were added by this plugin.

## License ##

This code is open source software licensed under the [Apache 2.0 License]("http://www.apache.org/licenses/LICENSE-2.0.html").
5 changes: 2 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ lazy val root = Project("sbt-git-stamp", file("."))
majorVersion := 6,
isPublicArtefact := true,
organization := "uk.gov.hmrc",
scalaVersion := "2.12.18",
scalaVersion := "2.12.20",
libraryDependencies ++=
Seq(
"com.github.nscala-time" %% "nscala-time" % "2.22.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.9.201909030838-r",
"org.eclipse.jgit" % "org.eclipse.jgit" % "7.0.0.202409031743-r",
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"com.vladsch.flexmark" % "flexmark-all" % "0.64.8" % Test
)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.9
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2")
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.19.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
14 changes: 9 additions & 5 deletions src/main/scala/uk/gov/hmrc/gitstamp/GitStamp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

package uk.gov.hmrc.gitstamp

import com.github.nscala_time.time.Imports._
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Constants._
import org.eclipse.jgit.lib.{ObjectId, Repository}
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.joda.time.format.ISODateTimeFormat._

import java.time.{Instant, ZoneId}
import java.time.format.DateTimeFormatter
import scala.jdk.CollectionConverters._

object GitStamp{
object GitStamp {

private val formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").withZone(ZoneId.systemDefault)

def gitStamp: Map[String, String] =
gitStamp(new FileRepositoryBuilder().readEnvironment.findGitDir.build)
Expand All @@ -38,7 +42,7 @@ object GitStamp{
val headRev = headCommit(git, headId)

Map(
"Build-Date" -> dateTime.print(DateTime.now),
"Build-Date" -> formatter.format(Instant.now()),
"Git-Branch" -> repository.getBranch,
"Git-Repo-Is-Clean" -> repoIsClean(git),
"Git-Head-Rev" -> headIdStr,
Expand All @@ -52,7 +56,7 @@ object GitStamp{
git.status.call.isClean.toString

private def commitDateTime(headRev: Option[RevCommit]): String =
dateTime.print(headRev.map(_.getCommitTime.toLong * 1000).getOrElse(0L))
formatter.format(Instant.ofEpochSecond(headRev.fold(0L)(_.getCommitTime.toLong)))

private def commitAuthorName(headRev: Option[RevCommit]): String =
headRev.map(_.getCommitterIdent.getName).getOrElse("")
Expand Down

0 comments on commit 7a6e3a7

Please sign in to comment.