-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.drone.star
167 lines (146 loc) · 3.82 KB
/
.drone.star
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Build pipelines
PYTHON_VERSIONS = [
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
"latest",
]
def main(ctx):
pipelines = []
# Run tests
pipelines += tests()
pipelines += [{
"kind": "pipeline",
"name": "lint",
"workspace": get_workspace(),
"steps": [{
"name": "lint",
"image": "python:3",
"commands": [
"python -V",
"make lint",
]
}]
}]
# Add pypi push pipeline
pipelines += push_to_pypi()
# Add notifications
pipeline_names = [
pipeline["name"] for pipeline in pipelines
]
pipelines += notify(pipeline_names)
return pipelines
# Return workspace in the container
def get_workspace():
return {
"base": "/app",
"path": ".",
}
# Builds a list of all test pipelines to be executed
def tests():
return [{
"kind": "pipeline",
"name": "tests",
"workspace": get_workspace(),
"steps": [
test_step("python:"+version)
for version in PYTHON_VERSIONS
],
}]
# Builds a single python test step
def test_step(docker_tag, python_cmd="python"):
return {
"name": "test {}".format(docker_tag.replace(":", "")),
"image": docker_tag,
"commands": [
"{} -V".format(python_cmd),
"make clean-all test"
],
"environment": {
"PIP_CACHE_DIR": ".pip-cache",
},
}
# Builds a notify step that will notify when the previous step changes
def notify_step():
return {
"name": "notify",
"image": "drillster/drone-email",
"settings": {
"host": {
"from_secret": "SMTP_HOST",
},
"username": {
"from_secret": "SMTP_USER",
},
"password": {
"from_secret": "SMTP_PASS",
},
"from": "[email protected]",
},
"when": {
"status": [
"changed",
"failure",
],
},
}
# Builds a notify pipeline that will notify when a dependency fails
def notify(depends_on=None):
if not depends_on:
depends_on = ["tests"]
return [{
"kind": "pipeline",
"name": "notify",
"depends_on": depends_on,
"trigger": {"status": ["failure"]},
"steps": [notify_step()]
}]
# Push package to pypi
def push_to_pypi():
return [{
"kind": "pipeline",
"name": "deploy to pypi",
"depends_on": ["tests", "lint"],
"workspace": get_workspace(),
"trigger": {
"ref": [
# "refs/heads/main",
"refs/tags/v*",
],
},
"steps": [
# {
# "name": "push to test pypi",
# "image": "python:3",
# "environment": {
# "HATCH_INDEX_USER": {
# "from_secret": "PYPI_USERNAME",
# },
# "HATCH_INDEX_AUTH": {
# "from_secret": "TEST_PYPI_PASSWORD",
# },
# },
# "commands": ["make upload-test"],
# },
{
"name": "push to pypi",
"image": "python:3",
"environment": {
"HATCH_INDEX_USER": {
"from_secret": "PYPI_USERNAME",
},
"HATCH_INDEX_AUTH": {
"from_secret": "PYPI_PASSWORD",
},
},
"commands": ["make upload"],
"when": {
"event": ["tag"],
},
},
]
}]
# vim: ft=python