FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/External/Tools/SetVersion/Program.cs at development · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
External
/
Tools
/
SetVersion
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (82 loc) · 3.05 KB
Breadcrumbs
flashdevelop
/
External
/
Tools
/
SetVersion
/
Program.cs
Copy path
File metadata and controls
85 lines (82 loc) · 3.05 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
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Text
;
using
System
.
Diagnostics
;
using
System
.
IO
;
using
System
.
Text
.
RegularExpressions
;
namespace
SetVersion
{
class
Program
{
/// <summary>
///
/// </summary>
static
void
Main
(
string
[
]
args
)
{
var
commit
=
""
;
var
branch
=
""
;
var
git
=
".git"
;
var
build
=
args
[
1
]
;
var
output
=
args
[
0
]
;
var
revOut
=
output
+
".rev"
;
if
(
!
File
.
Exists
(
revOut
)
)
{
Console
.
WriteLine
(
"Template not found: "
+
revOut
)
;
return
;
}
var
headFile
=
Path
.
Combine
(
git
,
"HEAD"
)
;
Match
headRef
;
if
(
!
File
.
Exists
(
headFile
)
)
{
Console
.
WriteLine
(
"Git folder not found"
)
;
headRef
=
null
;
}
else
{
var
head
=
File
.
ReadAllText
(
headFile
)
.
Trim
(
)
;
headRef
=
Regex
.
Match
(
head
,
"ref: refs/heads/(.*)"
)
;
}
if
(
headRef
==
null
||
!
headRef
.
Success
)
{
commit
=
Environment
.
ExpandEnvironmentVariables
(
"%APPVEYOR_REPO_COMMIT%"
)
;
if
(
commit
!=
"%APPVEYOR_REPO_COMMIT%"
)
{
Console
.
WriteLine
(
"SetVersion: Can not find HEAD ref, write from env vars."
)
;
if
(
commit
.
Length
==
40
)
commit
=
commit
.
Substring
(
0
,
10
)
;
branch
=
Environment
.
ExpandEnvironmentVariables
(
"%APPVEYOR_REPO_BRANCH%"
)
;
build
=
Environment
.
ExpandEnvironmentVariables
(
"%APPVEYOR_BUILD_NUMBER%"
)
;
}
else
{
Console
.
WriteLine
(
"SetVersion: Can not find HEAD ref nor CI env vars. Setting dummy values"
)
;
commit
=
string
.
Empty
;
branch
=
"local"
;
build
=
"0"
;
}
WriteFile
(
output
,
revOut
,
commit
,
branch
,
build
)
;
return
;
}
branch
=
headRef
.
Groups
[
1
]
.
Value
;
var
refPath
=
Path
.
Combine
(
Path
.
Combine
(
git
,
Path
.
Combine
(
"refs"
,
"heads"
)
)
,
branch
)
;
if
(
!
File
.
Exists
(
refPath
)
)
{
Console
.
WriteLine
(
"SetVersion: Can not read ref commit hash."
)
;
return
;
}
commit
=
File
.
ReadAllText
(
refPath
)
.
Trim
(
)
;
if
(
commit
.
Length
==
40
)
commit
=
commit
.
Substring
(
0
,
10
)
;
Console
.
WriteLine
(
"Set revision: "
+
branch
+
"-"
+
commit
+
"-"
+
build
)
;
WriteFile
(
output
,
revOut
,
commit
,
branch
,
build
)
;
}
/// <summary>
///
/// </summary>
static
void
WriteFile
(
String
output
,
String
revOut
,
String
commit
,
String
branch
,
String
build
)
{
var
raw
=
File
.
ReadAllText
(
revOut
)
;
if
(
build
!=
""
)
build
=
"."
+
build
;
raw
=
raw
.
Replace
(
"$BRANCH$"
,
branch
)
.
Replace
(
"$COMMIT$"
,
commit
)
.
Replace
(
"$BUILD$"
,
build
)
;
File
.
WriteAllText
(
output
,
raw
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL