diff --git a/.appveyor.yml b/.appveyor.yml index a949a33..3b99152 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,9 @@ version: '{build}' image: 'Visual Studio 2017' +platform: x64 clone_folder: 'c:\go\src\github.com\drone-plugins\drone-webhook' +max_jobs: 1 environment: DOCKER_USERNAME: @@ -10,28 +12,51 @@ environment: secure: 'VqO/G3Zfslu6zSLdwHKO+Q==' install: - - cmd: | + - ps: | docker version go version build_script: - - cmd: | - go build -v -ldflags "-X main.build=%APPVEYOR_BUILD_VERSION%"" -a -o drone-webhook.exe + - ps: | + if ( $env:APPVEYOR_REPO_TAG -eq 'false' ) { + go build -ldflags "-X main.build=$env:APPVEYOR_BUILD_VERSION" -a -o drone-webhook.exe + } else { + $version = $env:APPVEYOR_REPO_TAG_NAME.substring(1) + go build -ldflags "-X main.version=$version -X main.build=$env:APPVEYOR_BUILD_VERSION" -a -o drone-webhook.exe + } docker pull microsoft/nanoserver:10.0.14393.1593 - docker build -f Dockerfile.windows -t plugins/webhook:windows . + docker build -f Dockerfile.windows -t plugins/webhook:windows-amd64 . test_script: - - cmd: | - docker run --rm plugins/webhook:windows --version + - ps: | + docker run --rm plugins/webhook:windows-amd64 --version deploy_script: - ps: | $ErrorActionPreference = 'Stop'; - if ( $env:APPVEYOR_PULL_REQUEST_NUMBER -Or ! $env:APPVEYOR_REPO_BRANCH.Equals("master")) { + if ( $env:APPVEYOR_PULL_REQUEST_NUMBER ) { Write-Host Nothing to deploy. } else { docker login --username $env:DOCKER_USERNAME --password $env:DOCKER_PASSWORD - docker push plugins/webhook:windows + + if ( $env:APPVEYOR_REPO_TAG -eq 'true' ) { + $major,$minor,$patch = $env:APPVEYOR_REPO_TAG_NAME.substring(1).split('.') + + docker push plugins/webhook:windows + + docker tag plugins/webhook:windows plugins/webhook:$major.$minor.$patch-windows + docker push plugins/webhook:$major.$minor.$patch-windows-amd64 + + docker tag plugins/webhook:windows plugins/webhook:$major.$minor-windows + docker push plugins/webhook:$major.$minor-windows-amd64 + + docker tag plugins/webhook:windows plugins/webhook:$major-windows + docker push plugins/webhook:$major-windows-amd64 + } else { + if ( $env:APPVEYOR_REPO_BRANCH -eq 'master' ) { + docker push plugins/webhook:windows-amd64 + } + } } diff --git a/.drone.yml b/.drone.yml index 513874f..c326e9b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,7 +8,10 @@ pipeline: pull: true commands: - go vet - - go test -cover -coverprofile=coverage.out + - | + for PKG in $(go list ./... | grep -v /vendor/); do + go test -cover -coverprofile $GOPATH/src/$PKG/coverage.out $PKG + done build_linux_amd64: image: golang:1.9 @@ -19,7 +22,28 @@ pipeline: - GOARCH=amd64 - CGO_ENABLED=0 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-webhook + - | + if test "${DRONE_TAG}" = ""; then + go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-webhook + else + go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-webhook + fi + + build_linux_i386: + image: golang:1.9 + pull: true + group: build + environment: + - GOOS=linux + - GOARCH=386 + - CGO_ENABLED=0 + commands: + - | + if test "${DRONE_TAG}" = ""; then + go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/i386/drone-webhook + else + go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/i386/drone-webhook + fi build_linux_arm64: image: golang:1.9 @@ -30,7 +54,12 @@ pipeline: - GOARCH=arm64 - CGO_ENABLED=0 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-webhook + - | + if test "${DRONE_TAG}" = ""; then + go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-webhook + else + go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-webhook + fi build_linux_arm: image: golang:1.9 @@ -42,68 +71,74 @@ pipeline: - CGO_ENABLED=0 - GOARM=7 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-webhook - - # build_windows_amd64: - # image: golang:1.9-nanoserver - # pull: true - # group: build - # environment: - # - GOOS=windows - # - GOARCH=amd64 - # - CGO_ENABLED=0 - # commands: - # - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/windows/amd64/drone-webhook + - | + if test "${DRONE_TAG}" = ""; then + go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-webhook + else + go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-webhook + fi publish_linux_amd64: image: plugins/docker:17.05 pull: true - repo: plugins/webhook - tags: [ latest, 1.0.0, 1.0, 1 ] secrets: [ docker_username, docker_password ] + group: docker + repo: plugins/webhook + auto_tag: true + auto_tag_suffix: linux-amd64 dockerfile: Dockerfile when: - branch: master - event: push + event: [ push, tag ] + + publish_linux_i386: + image: plugins/docker:17.05 + pull: true + secrets: [ docker_username, docker_password ] + group: docker + repo: plugins/webhook + auto_tag: true + auto_tag_suffix: linux-i386 + dockerfile: Dockerfile.i386 + when: + event: [ push, tag ] publish_linux_arm64: image: plugins/docker:17.05 pull: true - repo: plugins/webhook - tags: [ linux-arm64 ] secrets: [ docker_username, docker_password ] + group: docker + repo: plugins/webhook + auto_tag: true + auto_tag_suffix: linux-arm64 dockerfile: Dockerfile.arm64 when: - branch: master - event: push + event: [ push, tag ] publish_linux_arm: image: plugins/docker:17.05 pull: true - repo: plugins/webhook - tags: [ linux-arm ] secrets: [ docker_username, docker_password ] + group: docker + repo: plugins/webhook + auto_tag: true + auto_tag_suffix: linux-arm dockerfile: Dockerfile.arm when: - branch: master - event: push + event: [ push, tag ] - # publish_windows_amd64: - # image: plugins/docker:17.05 - # pull: true - # repo: plugins/webhook - # tags: [ windows-amd64 ] - # secrets: [ docker_username, docker_password ] - # dockerfile: Dockerfile.windows - # when: - # branch: master - # event: push + manifests: + image: plugins/manifest:1 + pull: true + secrets: [ docker_username, docker_password ] + spec: manifest.tmpl + auto_tag: true + ignore_missing: true + when: + event: [ push, tag ] microbadger: image: plugins/webhook:1 pull: true secrets: [ webhook_url ] when: - branch: master - event: push status: [ success ] diff --git a/Dockerfile b/Dockerfile index 6ea23d1..5131f36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,9 @@ FROM plugins/base:multiarch -MAINTAINER Drone.IO Community -LABEL org.label-schema.version=latest -LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" -LABEL org.label-schema.name="Drone Webhook" -LABEL org.label-schema.vendor="Drone.IO Community" -LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="Drone.IO Community " \ + org.label-schema.name="Drone Webhook" \ + org.label-schema.vendor="Drone.IO Community" \ + org.label-schema.schema-version="1.0" ADD release/linux/amd64/drone-webhook /bin/ ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.arm b/Dockerfile.arm index 2583f60..39faeda 100644 --- a/Dockerfile.arm +++ b/Dockerfile.arm @@ -1,11 +1,9 @@ FROM plugins/base:multiarch -MAINTAINER Drone.IO Community -LABEL org.label-schema.version=latest -LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" -LABEL org.label-schema.name="Drone Webhook" -LABEL org.label-schema.vendor="Drone.IO Community" -LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="Drone.IO Community " \ + org.label-schema.name="Drone Webhook" \ + org.label-schema.vendor="Drone.IO Community" \ + org.label-schema.schema-version="1.0" ADD release/linux/arm/drone-webhook /bin/ ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index a1d41b2..253ff71 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -1,11 +1,9 @@ FROM plugins/base:multiarch -MAINTAINER Drone.IO Community -LABEL org.label-schema.version=latest -LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" -LABEL org.label-schema.name="Drone Webhook" -LABEL org.label-schema.vendor="Drone.IO Community" -LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="Drone.IO Community " \ + org.label-schema.name="Drone Webhook" \ + org.label-schema.vendor="Drone.IO Community" \ + org.label-schema.schema-version="1.0" ADD release/linux/arm64/drone-webhook /bin/ ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.i386 b/Dockerfile.i386 new file mode 100644 index 0000000..e9ca144 --- /dev/null +++ b/Dockerfile.i386 @@ -0,0 +1,9 @@ +FROM plugins/base:multiarch + +LABEL maintainer="Drone.IO Community " \ + org.label-schema.name="Drone Webhook" \ + org.label-schema.vendor="Drone.IO Community" \ + org.label-schema.schema-version="1.0" + +ADD release/linux/i386/drone-webhook /bin/ +ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.windows b/Dockerfile.windows index 731324c..98cba3c 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -1,11 +1,10 @@ +# escape=` FROM microsoft/nanoserver:10.0.14393.1593 -MAINTAINER Drone.IO Community -LABEL org.label-schema.version=latest -LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" -LABEL org.label-schema.name="Drone Webhook" -LABEL org.label-schema.vendor="Drone.IO Community" -LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="Drone.IO Community " ` + org.label-schema.name="Drone Webhook" ` + org.label-schema.vendor="Drone.IO Community" ` + org.label-schema.schema-version="1.0" -ADD drone-webhook.exe /drone-webhook.exe -ENTRYPOINT [ "\\drone-webhook.exe" ] +ADD drone-webhook.exe c:\drone-webhook.exe +ENTRYPOINT [ "c:\\drone-webhook.exe" ] diff --git a/main.go b/main.go index 4d5efc7..a11a7be 100644 --- a/main.go +++ b/main.go @@ -2,19 +2,23 @@ package main import ( "fmt" - "github.com/urfave/cli" "log" "os" + + "github.com/urfave/cli" ) -var build = "0" // build number set at compile-time +var ( + version = "0.0.0" + build = "0" +) func main() { app := cli.NewApp() app.Name = "webhook plugin" app.Usage = "webhook plugin" app.Action = run - app.Version = fmt.Sprintf("1.0.0+%s", build) + app.Version = fmt.Sprintf("%s+%s", version, build) app.Flags = []cli.Flag{ cli.StringFlag{ Name: "method", @@ -51,7 +55,7 @@ func main() { cli.StringSliceFlag{ Name: "urls", Usage: "list of urls to perform the action on", - EnvVar: "PLUGIN_URLS", + EnvVar: "PLUGIN_URLS,WEBHOOK_URLS", }, cli.BoolFlag{ Name: "debug", diff --git a/manifest.tmpl b/manifest.tmpl new file mode 100644 index 0000000..7caf03b --- /dev/null +++ b/manifest.tmpl @@ -0,0 +1,33 @@ +image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-i386 + platform: + architecture: 386 + os: linux + - + image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + - + image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + - + image: plugins/webhook:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}windows-amd64 + platform: + architecture: amd64 + os: windows