-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.space.kts
88 lines (71 loc) · 2.86 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
82
83
84
85
86
87
88
job("inverse-canopy") {
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-image") {
shellScript {
interpreter = "/bin/bash"
content = """
docker pull $remote:{{ branchSlug }} || true
docker build --tag="$remote:{{ branchSlug }}" --tag="$remote:ci-{{ run:number }}-{{ branchSlug }}" .
docker push "$remote:ci-{{ run:number }}-{{ branchSlug }}"
"""
}
}
parallel {
host("Tests") {
shellScript("pytest") {
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:ci-{{ run:number }}-{{ branchSlug }}" pytest -n 4
"""
}
}
host("Coverage") {
shellScript("pytest --cov") {
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:ci-{{ run:number }}-{{ branchSlug }}" pytest --cov -n 4
"""
}
}
host("Lint & Format") {
shellScript("ruff check") {
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:ci-{{ run:number }}-{{ branchSlug }}" ruff check
"""
}
}
}
host("Publish") {
runIf("{{ isMainBranch }}")
env["USER"] = "{{ project:PYPI_USER_TOKEN }}"
env["PASSWORD"] = "{{ project:PYPI_PASSWORD_TOKEN }}"
shellScript("build & package") {
interpreter = "/bin/bash"
content = """
docker run --rm "$remote:ci-{{ run:number }}-{{ branchSlug }}" /bin/bash -c "python -m build && twine upload dist/* -u ${'$'}USER -p ${'$'}PASSWORD"
"""
}
}
}