|
| 1 | +def main(ctx): |
| 2 | + before = testing(ctx) |
| 3 | + |
| 4 | + stages = [ |
| 5 | + linux(ctx, "amd64"), |
| 6 | + linux(ctx, "arm64"), |
| 7 | + linux(ctx, "arm"), |
| 8 | + windows(ctx, "1909"), |
| 9 | + windows(ctx, "1903"), |
| 10 | + windows(ctx, "1809"), |
| 11 | + ] |
| 12 | + |
| 13 | + after = manifest(ctx) + gitter(ctx) |
| 14 | + |
| 15 | + for b in before: |
| 16 | + for s in stages: |
| 17 | + s["depends_on"].append(b["name"]) |
| 18 | + |
| 19 | + for s in stages: |
| 20 | + for a in after: |
| 21 | + a["depends_on"].append(s["name"]) |
| 22 | + |
| 23 | + return before + stages + after |
| 24 | + |
| 25 | +def testing(ctx): |
| 26 | + return [{ |
| 27 | + "kind": "pipeline", |
| 28 | + "type": "docker", |
| 29 | + "name": "testing", |
| 30 | + "platform": { |
| 31 | + "os": "linux", |
| 32 | + "arch": "amd64", |
| 33 | + }, |
| 34 | + "steps": [ |
| 35 | + { |
| 36 | + "name": "staticcheck", |
| 37 | + "image": "golang:1.15", |
| 38 | + "pull": "always", |
| 39 | + "commands": [ |
| 40 | + "go run honnef.co/go/tools/cmd/staticcheck ./...", |
| 41 | + ], |
| 42 | + "volumes": [ |
| 43 | + { |
| 44 | + "name": "gopath", |
| 45 | + "path": "/go", |
| 46 | + }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + { |
| 50 | + "name": "lint", |
| 51 | + "image": "golang:1.15", |
| 52 | + "commands": [ |
| 53 | + "go run golang.org/x/lint/golint -set_exit_status ./...", |
| 54 | + ], |
| 55 | + "volumes": [ |
| 56 | + { |
| 57 | + "name": "gopath", |
| 58 | + "path": "/go", |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + { |
| 63 | + "name": "vet", |
| 64 | + "image": "golang:1.15", |
| 65 | + "commands": [ |
| 66 | + "go vet ./...", |
| 67 | + ], |
| 68 | + "volumes": [ |
| 69 | + { |
| 70 | + "name": "gopath", |
| 71 | + "path": "/go", |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + { |
| 76 | + "name": "test", |
| 77 | + "image": "golang:1.15", |
| 78 | + "commands": [ |
| 79 | + "go test -cover ./...", |
| 80 | + ], |
| 81 | + "volumes": [ |
| 82 | + { |
| 83 | + "name": "gopath", |
| 84 | + "path": "/go", |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ], |
| 89 | + "volumes": [ |
| 90 | + { |
| 91 | + "name": "gopath", |
| 92 | + "temp": {}, |
| 93 | + }, |
| 94 | + ], |
| 95 | + "trigger": { |
| 96 | + "ref": [ |
| 97 | + "refs/heads/master", |
| 98 | + "refs/tags/**", |
| 99 | + "refs/pull/**", |
| 100 | + ], |
| 101 | + }, |
| 102 | + }] |
| 103 | + |
| 104 | +def linux(ctx, arch): |
| 105 | + if ctx.build.event == "tag": |
| 106 | + build = [ |
| 107 | + 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-gitea-release ./cmd/drone-gitea-release' % (ctx.build.ref.replace("refs/tags/v", ""), arch), |
| 108 | + ] |
| 109 | + else: |
| 110 | + build = [ |
| 111 | + 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-gitea-release ./cmd/drone-gitea-release' % (ctx.build.commit[0:8], arch), |
| 112 | + ] |
| 113 | + |
| 114 | + steps = [ |
| 115 | + { |
| 116 | + "name": "environment", |
| 117 | + "image": "golang:1.15", |
| 118 | + "pull": "always", |
| 119 | + "environment": { |
| 120 | + "CGO_ENABLED": "0", |
| 121 | + }, |
| 122 | + "commands": [ |
| 123 | + "go version", |
| 124 | + "go env", |
| 125 | + ], |
| 126 | + }, |
| 127 | + { |
| 128 | + "name": "build", |
| 129 | + "image": "golang:1.15", |
| 130 | + "environment": { |
| 131 | + "CGO_ENABLED": "0", |
| 132 | + }, |
| 133 | + "commands": build, |
| 134 | + }, |
| 135 | + { |
| 136 | + "name": "executable", |
| 137 | + "image": "golang:1.15", |
| 138 | + "commands": [ |
| 139 | + "./release/linux/%s/drone-gitea-release --help" % (arch), |
| 140 | + ], |
| 141 | + }, |
| 142 | + ] |
| 143 | + |
| 144 | + if ctx.build.event != "pull_request": |
| 145 | + steps.append({ |
| 146 | + "name": "docker", |
| 147 | + "image": "plugins/docker", |
| 148 | + "settings": { |
| 149 | + "dockerfile": "docker/Dockerfile.linux.%s" % (arch), |
| 150 | + "repo": "plugins/gitea-release", |
| 151 | + "username": { |
| 152 | + "from_secret": "docker_username", |
| 153 | + }, |
| 154 | + "password": { |
| 155 | + "from_secret": "docker_password", |
| 156 | + }, |
| 157 | + "auto_tag": True, |
| 158 | + "auto_tag_suffix": "linux-%s" % (arch), |
| 159 | + }, |
| 160 | + }) |
| 161 | + |
| 162 | + return { |
| 163 | + "kind": "pipeline", |
| 164 | + "type": "docker", |
| 165 | + "name": "linux-%s" % (arch), |
| 166 | + "platform": { |
| 167 | + "os": "linux", |
| 168 | + "arch": arch, |
| 169 | + }, |
| 170 | + "steps": steps, |
| 171 | + "depends_on": [], |
| 172 | + "trigger": { |
| 173 | + "ref": [ |
| 174 | + "refs/heads/master", |
| 175 | + "refs/tags/**", |
| 176 | + "refs/pull/**", |
| 177 | + ], |
| 178 | + }, |
| 179 | + } |
| 180 | + |
| 181 | +def windows(ctx, version): |
| 182 | + docker = [ |
| 183 | + "echo $env:PASSWORD | docker login --username $env:USERNAME --password-stdin", |
| 184 | + ] |
| 185 | + |
| 186 | + if ctx.build.event == "tag": |
| 187 | + build = [ |
| 188 | + 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe ./cmd/drone-gitea-release' % (ctx.build.ref.replace("refs/tags/v", "")), |
| 189 | + ] |
| 190 | + |
| 191 | + docker = docker + [ |
| 192 | + "docker build --pull -f docker/Dockerfile.windows.%s -t plugins/gitea-release:%s-windows-%s-amd64 ." % (version, ctx.build.ref.replace("refs/tags/v", ""), version), |
| 193 | + "docker run --rm plugins/gitea-release:%s-windows-%s-amd64 --help" % (ctx.build.ref.replace("refs/tags/v", ""), version), |
| 194 | + "docker push plugins/gitea-release:%s-windows-%s-amd64" % (ctx.build.ref.replace("refs/tags/v", ""), version), |
| 195 | + ] |
| 196 | + else: |
| 197 | + build = [ |
| 198 | + 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe ./cmd/drone-gitea-release' % (ctx.build.commit[0:8]), |
| 199 | + ] |
| 200 | + |
| 201 | + docker = docker + [ |
| 202 | + "docker build --pull -f docker/Dockerfile.windows.%s -t plugins/gitea-release:windows-%s-amd64 ." % (version, version), |
| 203 | + "docker run --rm plugins/gitea-release:windows-%s-amd64 --help" % (version), |
| 204 | + "docker push plugins/gitea-release:windows-%s-amd64" % (version), |
| 205 | + ] |
| 206 | + |
| 207 | + return { |
| 208 | + "kind": "pipeline", |
| 209 | + "type": "ssh", |
| 210 | + "name": "windows-%s" % (version), |
| 211 | + "platform": { |
| 212 | + "os": "windows", |
| 213 | + }, |
| 214 | + "server": { |
| 215 | + "host": { |
| 216 | + "from_secret": "windows_server_%s" % (version), |
| 217 | + }, |
| 218 | + "user": { |
| 219 | + "from_secret": "windows_username", |
| 220 | + }, |
| 221 | + "password": { |
| 222 | + "from_secret": "windows_password", |
| 223 | + }, |
| 224 | + }, |
| 225 | + "steps": [ |
| 226 | + { |
| 227 | + "name": "environment", |
| 228 | + "environment": { |
| 229 | + "CGO_ENABLED": "0", |
| 230 | + }, |
| 231 | + "commands": [ |
| 232 | + "go version", |
| 233 | + "go env", |
| 234 | + ], |
| 235 | + }, |
| 236 | + { |
| 237 | + "name": "build", |
| 238 | + "environment": { |
| 239 | + "CGO_ENABLED": "0", |
| 240 | + }, |
| 241 | + "commands": build, |
| 242 | + }, |
| 243 | + { |
| 244 | + "name": "executable", |
| 245 | + "commands": [ |
| 246 | + "./release/windows/amd64/drone-gitea-release.exe --help", |
| 247 | + ], |
| 248 | + }, |
| 249 | + { |
| 250 | + "name": "docker", |
| 251 | + "environment": { |
| 252 | + "USERNAME": { |
| 253 | + "from_secret": "docker_username", |
| 254 | + }, |
| 255 | + "PASSWORD": { |
| 256 | + "from_secret": "docker_password", |
| 257 | + }, |
| 258 | + }, |
| 259 | + "commands": docker, |
| 260 | + }, |
| 261 | + ], |
| 262 | + "depends_on": [], |
| 263 | + "trigger": { |
| 264 | + "ref": [ |
| 265 | + "refs/heads/master", |
| 266 | + "refs/tags/**", |
| 267 | + ], |
| 268 | + }, |
| 269 | + } |
| 270 | + |
| 271 | +def manifest(ctx): |
| 272 | + return [{ |
| 273 | + "kind": "pipeline", |
| 274 | + "type": "docker", |
| 275 | + "name": "manifest", |
| 276 | + "steps": [ |
| 277 | + { |
| 278 | + "name": "manifest", |
| 279 | + "image": "plugins/manifest", |
| 280 | + "settings": { |
| 281 | + "auto_tag": "true", |
| 282 | + "username": { |
| 283 | + "from_secret": "docker_username", |
| 284 | + }, |
| 285 | + "password": { |
| 286 | + "from_secret": "docker_password", |
| 287 | + }, |
| 288 | + "spec": "docker/manifest.tmpl", |
| 289 | + "ignore_missing": "true", |
| 290 | + }, |
| 291 | + }, |
| 292 | + { |
| 293 | + "name": "microbadger", |
| 294 | + "image": "plugins/webhook", |
| 295 | + "settings": { |
| 296 | + "urls": { |
| 297 | + "from_secret": "microbadger_url", |
| 298 | + }, |
| 299 | + }, |
| 300 | + }, |
| 301 | + ], |
| 302 | + "depends_on": [], |
| 303 | + "trigger": { |
| 304 | + "ref": [ |
| 305 | + "refs/heads/master", |
| 306 | + "refs/tags/**", |
| 307 | + ], |
| 308 | + }, |
| 309 | + }] |
| 310 | + |
| 311 | +def gitter(ctx): |
| 312 | + return [{ |
| 313 | + "kind": "pipeline", |
| 314 | + "type": "docker", |
| 315 | + "name": "gitter", |
| 316 | + "clone": { |
| 317 | + "disable": True, |
| 318 | + }, |
| 319 | + "steps": [ |
| 320 | + { |
| 321 | + "name": "gitter", |
| 322 | + "image": "plugins/gitter", |
| 323 | + "settings": { |
| 324 | + "webhook": { |
| 325 | + "from_secret": "gitter_webhook", |
| 326 | + }, |
| 327 | + }, |
| 328 | + }, |
| 329 | + ], |
| 330 | + "depends_on": [ |
| 331 | + "manifest", |
| 332 | + ], |
| 333 | + "trigger": { |
| 334 | + "ref": [ |
| 335 | + "refs/heads/master", |
| 336 | + "refs/tags/**", |
| 337 | + ], |
| 338 | + "status": [ |
| 339 | + "failure", |
| 340 | + ], |
| 341 | + }, |
| 342 | + }] |
0 commit comments