Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
4be74723ba63
Commit
4be74723ba63
authored
3 months ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
build_version_file: fix a crash when no active topic
parent
c26b7fd68dd7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#114608
failed
3 months ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/build_version_file/main.go
+21
-12
21 additions, 12 deletions
tools/build_version_file/main.go
with
21 additions
and
12 deletions
tools/build_version_file/main.go
+
21
−
12
View file @
4be74723
package
main
import
(
"errors"
"fmt"
"os"
"os/exec"
...
...
@@ -8,6 +9,6 @@
"text/template"
)
func
sys
c
md
(
name
string
,
arg
...
string
)
string
{
func
sys
C
md
(
name
string
,
arg
...
string
)
(
string
,
error
)
{
cmd
:=
exec
.
Command
(
name
,
arg
...
)
out
,
err
:=
cmd
.
CombinedOutput
()
...
...
@@ -12,9 +13,5 @@
cmd
:=
exec
.
Command
(
name
,
arg
...
)
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
fmt
.
Println
(
string
(
out
))
panic
(
err
)
}
splitted
:=
strings
.
Split
(
string
(
out
),
"
\n
"
)
lines
:=
make
([]
string
,
0
,
len
(
splitted
))
for
_
,
l
:=
range
splitted
{
...
...
@@ -26,6 +23,7 @@
}
if
len
(
lines
)
!=
1
{
fmt
.
Println
(
string
(
out
))
panic
(
"Expects a single line"
)
return
""
,
errors
.
New
(
"Expects a single line"
)
}
...
...
@@ -30,6 +28,15 @@
}
return
lines
[
0
]
return
lines
[
0
],
err
}
func
mustSysCmd
(
name
string
,
arg
...
string
)
string
{
out
,
err
:=
sysCmd
(
name
,
arg
...
)
if
err
!=
nil
{
panic
(
err
)
}
return
out
}
func
getVersionTag
(
tags
string
)
string
{
...
...
@@ -56,9 +63,9 @@
`
))
func
main
()
{
sha
:=
s
ys
c
md
(
"hg"
,
"id"
,
"--id"
)
curVersion
:=
getVersionTag
(
s
ys
c
md
(
"hg"
,
"id"
,
"--tags"
))
lastVersion
:=
getVersionTag
(
s
ys
c
md
(
"hg"
,
"id"
,
"--tags"
,
"-r"
,
"limit(last(ancestors(.)&tag('re:v.*'))|.,1)"
))
sha
:=
mustS
ys
C
md
(
"hg"
,
"id"
,
"--id"
)
curVersion
:=
getVersionTag
(
mustS
ys
C
md
(
"hg"
,
"id"
,
"--tags"
))
lastVersion
:=
getVersionTag
(
mustS
ys
C
md
(
"hg"
,
"id"
,
"--tags"
,
"-r"
,
"limit(last(ancestors(.)&tag('re:v.*'))|.,1)"
))
modified
:=
strings
.
HasSuffix
(
sha
,
"+"
)
jobID
:=
os
.
Getenv
(
"CI_JOB_ID"
)
...
...
@@ -62,6 +69,6 @@
modified
:=
strings
.
HasSuffix
(
sha
,
"+"
)
jobID
:=
os
.
Getenv
(
"CI_JOB_ID"
)
topic
:=
sys
c
md
(
"hg"
,
"topic"
,
"--current"
)
topic
,
err
:=
sys
C
md
(
"hg"
,
"topic"
,
"--current"
)
if
topic
==
"no active topic"
{
topic
=
""
...
...
@@ -66,3 +73,5 @@
if
topic
==
"no active topic"
{
topic
=
""
}
else
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -68,5 +77,5 @@
}
branch
:=
s
ys
c
md
(
"hg"
,
"id"
,
"--branch"
)
branch
:=
mustS
ys
C
md
(
"hg"
,
"id"
,
"--branch"
)
var
version
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment