release-gitter/.drone.star

164 lines
3.7 KiB
Plaintext
Raw Normal View History

2022-01-05 23:20:28 +00:00
# Build pipelines
PYTHON_VERSIONS = [
"3.7",
"3.8",
2022-01-05 23:20:28 +00:00
"3.9",
"3.10",
2023-06-26 23:26:39 +00:00
"3.11",
2022-01-05 23:20:28 +00:00
"latest",
]
def main(ctx):
pipelines = []
# Run tests
pipelines += tests()
2023-10-27 21:04:46 +00:00
pipelines += [{
"kind": "pipeline",
"name": "lint",
"workspace": get_workspace(),
"steps": [{
"name": "lint",
"image": "python:3",
"commands": [
"python -V",
"make lint",
]
}]
}]
2022-01-05 23:20:28 +00:00
# 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": [
2023-10-27 20:36:48 +00:00
test_step("python:"+version)
2022-01-05 23:20:28 +00:00
for version in PYTHON_VERSIONS
],
}]
# Builds a single python test step
2023-10-27 20:36:48 +00:00
def test_step(docker_tag, python_cmd="python"):
2022-01-05 23:20:28 +00:00
return {
"name": "test {}".format(docker_tag.replace(":", "")),
"image": docker_tag,
"commands": [
"{} -V".format(python_cmd),
"make clean-all test"
2022-01-05 23:20:28 +00:00
],
}
# 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": "drone@iamthefij.com",
},
"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",
2023-10-27 21:04:46 +00:00
"depends_on": ["tests", "lint"],
2022-01-05 23:20:28 +00:00
"workspace": get_workspace(),
"trigger": {
"ref": [
"refs/heads/main",
2022-01-05 23:20:28 +00:00
"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"],
# },
2022-01-05 23:20:28 +00:00
{
"name": "push to pypi",
"image": "python:3",
"environment": {
2023-10-27 20:36:48 +00:00
"HATCH_INDEX_USER": {
2022-01-05 23:20:28 +00:00
"from_secret": "PYPI_USERNAME",
},
2023-10-27 20:36:48 +00:00
"HATCH_INDEX_AUTH": {
2022-01-05 23:20:28 +00:00
"from_secret": "PYPI_PASSWORD",
},
},
"commands": ["make upload"],
"when": {
"event": ["tag"],
},
},
]
}]
# vim: ft=python