0
0
mirror of https://github.com/thegeeklab/wp-ansible.git synced 2024-11-13 22:50:40 +00:00
wp-ansible/.drone.star

333 lines
8.6 KiB
Plaintext
Raw Normal View History

2021-01-26 11:00:05 +00:00
def main(ctx):
before = testing(ctx)
stages = [
linux(ctx, "amd64"),
linux(ctx, "arm64"),
linux(ctx, "arm"),
]
2021-01-26 13:06:02 +00:00
after = manifest(ctx) + pushrm(ctx) + release(ctx) + notification(ctx)
2021-01-26 11:00:05 +00:00
for b in before:
for s in stages:
s["depends_on"].append(b["name"])
for s in stages:
for a in after:
a["depends_on"].append(s["name"])
return before + stages + after
def testing(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "testing",
"platform": {
"os": "linux",
"arch": "amd64",
},
"steps": [
{
"name": "staticcheck",
"image": "golang:1.15",
"pull": "always",
"commands": [
"go run honnef.co/go/tools/cmd/staticcheck ./...",
],
2021-01-26 11:28:47 +00:00
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
2021-01-26 11:00:05 +00:00
},
{
"name": "lint",
"image": "golang:1.15",
"commands": [
"go run golang.org/x/lint/golint -set_exit_status ./...",
],
2021-01-26 11:28:47 +00:00
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
2021-01-26 11:00:05 +00:00
},
{
"name": "vet",
"image": "golang:1.15",
"commands": [
"go vet ./...",
],
2021-01-26 11:28:47 +00:00
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
2021-01-26 11:00:05 +00:00
},
{
"name": "test",
"image": "golang:1.15",
"commands": [
"go test -cover ./...",
],
2021-01-26 11:28:47 +00:00
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
},
],
"volumes": [
{
"name": "gopath",
"temp": {},
2021-01-26 11:00:05 +00:00
},
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
}]
def linux(ctx, arch):
if ctx.build.event == "tag":
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-ansible ./cmd/drone-ansible' % (ctx.build.ref.replace("refs/tags/v", ""), arch),
2021-01-26 11:00:05 +00:00
]
else:
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-ansible ./cmd/drone-ansible' % (ctx.build.commit[0:8], arch),
2021-01-26 11:00:05 +00:00
]
steps = [
{
"name": "environment",
"image": "golang:1.15",
"pull": "always",
"environment": {
"CGO_ENABLED": "0",
},
"commands": [
"go version",
"go env",
],
},
{
"name": "build",
"image": "golang:1.15",
"environment": {
"CGO_ENABLED": "0",
},
"commands": build,
},
{
"name": "executable",
"image": "golang:1.15",
"commands": [
"./release/linux/%s/drone-ansible --help" % (arch),
],
},
]
if ctx.build.event != "pull_request":
steps.append({
"name": "docker",
"image": "plugins/docker",
"settings": {
2021-02-09 09:45:07 +00:00
"dockerfile": "docker/Dockerfile.%s" % (arch),
2021-01-26 11:00:05 +00:00
"repo": "owncloudci/%s" % (ctx.repo.name),
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
"auto_tag": True,
2021-02-09 09:45:07 +00:00
"auto_tag_suffix": "%s" % (arch),
},
})
else:
steps.append({
"name": "dryrun",
"image": "plugins/docker",
"settings": {
'dry_run': True,
"dockerfile": "docker/Dockerfile.%s" % (arch),
"repo": "owncloudci/%s" % (ctx.repo.name),
"tags": "latest",
2021-01-26 11:00:05 +00:00
},
})
return {
"kind": "pipeline",
"type": "docker",
2021-02-09 09:45:07 +00:00
"name": "build-%s" % (arch),
2021-01-26 11:00:05 +00:00
"platform": {
"os": "linux",
"arch": arch,
},
"steps": steps,
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
}
def manifest(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "manifest",
"steps": [
{
"name": "manifest",
"image": "plugins/manifest",
"settings": {
"auto_tag": "true",
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
"spec": "docker/manifest.tmpl",
"ignore_missing": "true",
},
},
],
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
},
}]
2021-01-26 13:06:02 +00:00
def pushrm(ctx):
2021-01-26 12:29:26 +00:00
return [{
"kind": "pipeline",
"type": "docker",
2021-01-26 13:06:02 +00:00
"name": "pushrm",
2021-01-26 12:29:26 +00:00
"steps": [
2021-01-26 13:06:02 +00:00
{
2021-01-26 13:08:18 +00:00
"name": "pushrm",
"image": "chko/docker-pushrm:1",
"environment": {
"DOCKER_PASS": {
"from_secret": "docker_password",
2021-01-26 13:06:02 +00:00
},
2021-01-26 13:08:18 +00:00
"DOCKER_USER": {
"from_secret": "docker_username",
2021-01-26 13:06:02 +00:00
},
2021-01-26 13:08:18 +00:00
"PUSHRM_FILE": "README.md",
"PUSHRM_SHORT": "Drone plugin to provision infrastructure with Ansible",
"PUSHRM_TARGET": "owncloudci/%s" % (ctx.repo.name),
2021-01-26 12:29:26 +00:00
},
},
],
"depends_on": [
"manifest",
],
"trigger": {
"ref": [
2021-01-26 13:24:26 +00:00
"refs/heads/master",
2021-01-26 12:29:26 +00:00
"refs/tags/**",
],
2021-01-26 13:08:18 +00:00
"status": ["success"],
2021-01-26 12:29:26 +00:00
},
}]
2021-01-26 13:06:02 +00:00
def release(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "release",
"steps": [
{
"name": "changelog",
"image": "thegeeklab/git-chglog",
"commands": [
"git fetch -tq",
2021-02-12 10:14:17 +00:00
"git-chglog --no-color --no-emoji %s" % (ctx.build.ref.replace("refs/tags/", "") if ctx.build.event == "tag" else "--next-tag unreleased unreleased"),
"git-chglog --no-color --no-emoji -o CHANGELOG.md %s" % (ctx.build.ref.replace("refs/tags/", "") if ctx.build.event == "tag" else "--next-tag unreleased unreleased"),
]
},
{
"name": "release",
"image": "plugins/github-release",
"settings": {
"api_key": {
"from_secret": "github_token",
},
"note": "CHANGELOG.md",
"overwrite": True,
"title": ctx.build.ref.replace("refs/tags/", ""),
},
"when": {
"ref": [
"refs/tags/**",
],
},
2021-01-26 13:06:02 +00:00
}
],
"depends_on": [
"pushrm",
],
"trigger": {
"ref": [
"refs/heads/master",
2021-01-26 13:06:02 +00:00
"refs/tags/**",
"refs/pull/**",
2021-01-26 13:06:02 +00:00
],
},
}]
2021-01-26 11:00:05 +00:00
def notification(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "notify",
"clone": {
"disable": True,
},
"steps": [
2021-01-26 13:06:02 +00:00
{
"name": "notify",
"image": "plugins/slack",
"settings": {
"webhook": {
2021-01-29 14:44:10 +00:00
"from_secret": "private_rocketchat",
2021-01-26 13:06:02 +00:00
},
"channel": "builds",
},
}
2021-01-26 11:00:05 +00:00
],
"depends_on": [
2021-01-26 12:29:26 +00:00
"release",
2021-01-26 11:00:05 +00:00
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
"status": [
"success",
"failure",
],
},
}]