-
Notifications
You must be signed in to change notification settings - Fork 0
/
.space.kts
81 lines (63 loc) · 2.54 KB
/
.space.kts
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
job("InverseCanopy CI") {
requirements {
workerTags("swarm-worker")
}
val registry = "packages.space.openpra.org/p/openpra/containers/"
val image = "inverse-canopy"
val remote = "$registry$image"
host("Image Tags") {
// use kotlinScript blocks for usage of parameters
kotlinScript("Generate slugs") { api ->
api.parameters["commitRef"] = api.gitRevision()
api.parameters["gitBranch"] = api.gitBranch()
val branchName = api.gitBranch()
.removePrefix("refs/heads/")
.replace(Regex("[^A-Za-z0-9-]"), "-") // Replace all non-alphanumeric characters except hyphens with hyphens
.replace(Regex("-+"), "-") // Replace multiple consecutive hyphens with a single hyphen
.lowercase() // Convert to lower case for consistency
val maxSlugLength = if (branchName.length > 48) 48 else branchName.length
var branchSlug = branchName.subSequence(0, maxSlugLength).toString()
api.parameters["branchSlug"] = branchSlug
api.parameters["isMainBranch"] = (api.gitBranch() == "refs/heads/main").toString()
}
}
host("Build & Test") {
shellScript("build"){
interpreter = "/bin/bash"
content = """
docker build --tag="$remote:{{ branchSlug }}" .
"""
}
shellScript("tests"){
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:{{ branchSlug }}" pytest
"""
}
shellScript("coverage"){
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:{{ branchSlug }}" pytest --cov
"""
}
shellScript("lint"){
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:{{ branchSlug }}" pylint /app/inverse_canopy || exit 0
"""
}
}
host("Publish") {
runIf("{{ isMainBranch }}")
env["USER"] = "{{ project:PYPI_USER_TOKEN }}"
env["PASSWORD"] = "{{ project:PYPI_PASSWORD_TOKEN }}"
shellScript("build & push"){
interpreter = "/bin/bash"
content = """
docker build --tag="$remote:{{ branchSlug }}" .
docker run --rm "$remote:{{ branchSlug }}" /bin/bash -c "python setup.py sdist bdist_wheel && twine upload dist/* -u ${'$'}USER -p ${'$'}PASSWORD"
docker rmi "$remote:{{ branchSlug }}"
"""
}
}
}