FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/project/VersionInfo.scala at test-code-owners · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
project
/
VersionInfo.scala
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (63 loc) · 2.25 KB
Breadcrumbs
frontend
/
project
/
VersionInfo.scala
Copy path
File metadata and controls
73 lines (63 loc) · 2.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package
com
.
gu
.
versioninfo
import
java
.
net
.
InetAddress
import
org
.
joda
.
time
.{
DateTimeZone
,
DateTime
}
import
sbt
.
_
import
Keys
.
_
import
org
.
eclipse
.
jgit
.
storage
.
file
.
FileRepositoryBuilder
object
VersionInfo
extends
AutoPlugin
{
val
branch
=
SettingKey
[
String
](
"
version-branch
"
)
val
buildNumber
=
SettingKey
[
String
](
"
version-build-number
"
)
val
vcsNumber
=
SettingKey
[
String
](
"
version-vcs-number
"
)
private
def
getRepo
(
repo
: java.io.
File
)
=
{
try
{
val
gitRepo
=
new
FileRepositoryBuilder
().findGitDir(repo)
if
(gitRepo.build.getConfig.getString(
"
remote
"
,
"
origin
"
,
"
url
"
)
==
"
git@github.com:guardian/frontend.git
"
) {
Some
(gitRepo)
}
else
{
None
}
}
catch
{
case
_
:
Throwable
=>
None
}
}
override
val
projectSettings
=
Seq
(
buildNumber
:=
System
.getenv().getOrDefault(
"
BUILD_NUMBER
"
,
"
DEV
"
),
branch
:=
baseDirectory( baseDir
=>
{
getRepo(baseDir).map( gitRepo
=>
{
val
branchName
=
gitRepo.build.getBranch
gitRepo.build.close()
branchName
}).getOrElse(
"
DEV
"
)
}).value,
vcsNumber
:=
baseDirectory( baseDir
=>
{
getRepo(baseDir).map( gitRepo
=>
{
val
commitHash
=
gitRepo.build.resolve(
"
HEAD
"
).getName
gitRepo.build.close()
commitHash
}).getOrElse(
"
DEV
"
)
}).value,
resourceGenerators in
Compile
+=
Def
.task {
buildFile(
(resourceManaged in
Compile
).value,
branch.value,
buildNumber.value,
vcsNumber.value,
streams.value
)
}
)
def
buildFile
(
outDir
:
File
,
branch
:
String
,
buildNum
:
String
,
vcsNum
:
String
,
s
:
TaskStreams
)
:
Seq
[
File
]
=
{
val
versionInfo
=
Map
(
"
Revision
"
->
vcsNum,
"
Branch
"
->
branch,
"
Build
"
->
buildNum.replace(
"
\"
"
,
"
"
).trim,
"
Date
"
->
new
DateTime
(
DateTimeZone
.
UTC
).toString(),
"
Built-By
"
->
System
.getProperty(
"
user.name
"
,
"
<unknown>
"
),
"
Built-On
"
->
InetAddress
.getLocalHost.getHostName)
val
versionFileContents
=
(versionInfo map {
case
(x, y)
=>
x
+
"
:
"
+
y }).toList.sorted
val
versionFile
=
outDir
/
"
version.txt
"
s.log.debug(
"
Writing to
"
+
versionFile
+
"
:
\n
"
+
versionFileContents.mkString(
"
\n
"
))
IO
.write(versionFile, versionFileContents mkString
"
\n
"
)
Seq
(versionFile)
}
}
Back
|
FazBrowse Home
|
New Git URL