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
86
87
88
89
|
import std / [
os,
osproc,
hashes,
strformat
]
proc runCommand*(
command: string,
workingDir: string = ""
): (string, int) =
echo "-> {command} (workingDir: {workingDir})".fmt
let (output, code) = execCmdEx(
command=command,
workingDir=workingDir
)
result = (output, code)
proc ensureDir*(path: string) =
if not dirExists(path):
createDir(path)
proc readConfigFile*(configPath: string): string =
if fileExists(configPath):
result = readFile(configPath)
else:
result = ""
proc cloneSource*(
repoURL: string,
destinationDir: string
) =
if dirExists(destinationDir):
echo "Repository already exists at {destinationDir}".fmt
echo "Pulling..."
let (output, code) = runCommand(
command="git pull",
workingDir=destinationDir
)
echo output
else:
echo "Cloning from {repoURL}...".fmt
let (output, code) = runCommand(
command="git clone {repoURL} {destinationDir}".fmt
)
echo output
proc fetchTags*(
destinationDir: string
) =
let (output, code) = runCommand(
command="git fetch --tags --force",
workingDir=destinationDir
)
echo output
proc resolveTag*(
destinationDir: string,
pinnedTag: string = ""
): string =
## if pinnedTag is defined, we use that;
## otherwise we fall back to newest tag
if pinnedTag.len > 0:
result = pinnedTag
let (output, code) = runCommand(
command="git rev-parse --verify {pinnedTag}".fmt,
workingDir=destinationDir
)
echo output
if code != 0:
# if it fails, we try to fetch the tag
# just in case
fetchTags(destinationDir)
let (newOutput, newCode) = runCommand(
"git rev-parse --verify {pinnedTag}".fmt,
workingDir=destinationdir
)
echo newOutput
if newCode != 0:
quit("Pinned tag {pinnedTag} not found in repo at {destDir}.")
else:
let (output, code) = runCommand(
command="git describe --tags --abbrev=0",
workingDir=destinationDir
)
result = output
if code != 0:
quit("There seem to be no releases available from this software")
|