FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-version-export-github-action/index.js at main · joshlong/java-version-export-github-action · GitHub
joshlong
/
java-version-export-github-action
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-version-export-github-action
/
index.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (78 loc) · 2.68 KB
Breadcrumbs
java-version-export-github-action
/
index.js
Copy path
File metadata and controls
86 lines (78 loc) · 2.68 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
74
75
76
77
78
79
80
81
82
83
84
85
/**
*
* Uses <a href="http://twitter.com/brunoborges">Bruno Borges'</a> brilliant
* <a href="https://twitter.com/brunoborges/status/1565783443216416768?s=21&t=EoHl3kqopkK5pry-VVsSZA">hack</a> to extract a property
* from a Maven `pom.xml` and export it to an environment variable
* or property that other things, like the `setup-java` Github Action, can use.
*
*
@author
Josh Long
*/
/* see: https://github.com/actions/toolkit */
const
core
=
require
(
"@actions/core"
)
;
const
github
=
require
(
"@actions/github"
)
;
const
exec
=
require
(
"@actions/exec"
)
;
const
fs
=
require
(
'fs'
)
;
/**
* makes it a little more clean to exec something. make sure to redirect all other file descripters to stdout!
*
@param
{
*
} cmd
*
@param
{
*
} args
*
@param
{
*
} stdoutListener
*/
function
cmd
(
cmd
,
args
,
stdoutListener
)
{
exec
.
exec
(
cmd
,
args
,
{
listeners
:
{
stdout
:
stdoutListener
,
}
,
}
)
.
then
(
(
ec
)
=>
{
console
.
debug
(
"the exit code is "
+
ec
)
;
}
)
;
}
try
{
const
maven
=
fs
.
existsSync
(
'pom.xml'
)
const
gradleGroovy
=
fs
.
existsSync
(
'build.gradle'
)
const
gradleKotlin
=
fs
.
existsSync
(
'build.gradle.kts'
)
console
.
log
(
maven
)
console
.
log
(
gradleGroovy
)
console
.
log
(
gradleKotlin
)
if
(
maven
)
{
// maven build
cmd
(
"mvn"
,
[
"help:evaluate"
,
"-q"
,
"-DforceStdout"
,
"-Dexpression=maven.compiler.target"
,
]
,
// ["help:evaluate", "-q", "-DforceStdout", "-Dexpression=java.version"],
(
outputBuffer
)
=>
{
const
output
=
outputBuffer
.
toString
(
)
;
console
.
log
(
output
)
;
const
varsMap
=
new
Map
(
)
;
varsMap
.
set
(
"java_version"
,
output
+
""
)
;
varsMap
.
set
(
"java_major_version"
,
parseInt
(
""
+
output
)
+
""
)
;
varsMap
.
forEach
(
function
(
value
,
key
)
{
console
.
log
(
key
+
"="
+
value
)
;
core
.
setOutput
(
key
,
value
)
;
core
.
exportVariable
(
key
.
toUpperCase
(
)
,
value
)
;
}
)
;
}
)
;
}
//
else
{
if
(
gradleGroovy
||
gradleKotlin
)
{
cmd
(
"./gradlew"
,
[
':properties'
,
'--property'
,
'sourceCompatibility'
]
,
outputBuffer
=>
{
const
buff
=
outputBuffer
.
toString
(
)
;
if
(
buff
.
indexOf
(
'sourceCompatibility'
)
!=
-
1
)
{
console
.
log
(
'sourceCompatibility: '
+
buff
)
}
else
{
console
.
log
(
'nope!'
)
}
}
)
;
}
}
}
catch
(
error
)
{
core
.
setFailed
(
error
.
message
)
;
}
Back
|
FazBrowse Home
|
New Git URL