mirror of
https://github.com/drone-plugins/drone-webhook.git
synced 2026-06-13 18:41:59 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a0ade0870 | |||
| 131f624843 | |||
| c92f28d142 | |||
| 05dd646658 | |||
| b83c004215 | |||
| 8b44f3c41f | |||
| 5d0c917e8f | |||
| dc62731f93 | |||
| b2d83444d1 | |||
| 07a4386c3d | |||
| 739613d9dc | |||
| 63eabce274 | |||
| a4a3dd85d0 | |||
| 25de318efb | |||
| bff3a91abd | |||
| 32f681e175 | |||
| 770ffb857e | |||
| 7f2efea728 | |||
| a76e37dacb | |||
| b06afe33fc | |||
| 79df46e1e2 |
-358
@@ -1,358 +0,0 @@
|
||||
def main(ctx):
|
||||
before = testing(ctx)
|
||||
|
||||
stages = [
|
||||
linux(ctx, 'amd64'),
|
||||
linux(ctx, 'arm64'),
|
||||
linux(ctx, 'arm'),
|
||||
windows(ctx, '1909'),
|
||||
windows(ctx, '1903'),
|
||||
windows(ctx, '1809'),
|
||||
]
|
||||
|
||||
after = manifest(ctx) + gitter(ctx)
|
||||
|
||||
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 ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'lint',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go run golang.org/x/lint/golint -set_exit_status ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'vet',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go vet ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go test -cover ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'temp': {},
|
||||
},
|
||||
],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
'refs/pull/**',
|
||||
],
|
||||
},
|
||||
}]
|
||||
|
||||
def linux(ctx, arch):
|
||||
docker = {
|
||||
'dockerfile': 'docker/Dockerfile.linux.%s' % (arch),
|
||||
'repo': 'plugins/webhook',
|
||||
'username': {
|
||||
'from_secret': 'docker_username',
|
||||
},
|
||||
'password': {
|
||||
'from_secret': 'docker_password',
|
||||
},
|
||||
}
|
||||
|
||||
if ctx.build.event == 'pull_request':
|
||||
docker.update({
|
||||
'dry_run': True,
|
||||
'tags': 'linux-%s' % (arch),
|
||||
})
|
||||
else:
|
||||
docker.update({
|
||||
'auto_tag': True,
|
||||
'auto_tag_suffix': 'linux-%s' % (arch),
|
||||
})
|
||||
|
||||
if ctx.build.event == 'tag':
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-webhook ./cmd/drone-webhook' % (ctx.build.ref.replace("refs/tags/v", ""), arch),
|
||||
]
|
||||
else:
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-webhook ./cmd/drone-webhook' % (ctx.build.commit[0:8], arch),
|
||||
]
|
||||
|
||||
return {
|
||||
'kind': 'pipeline',
|
||||
'type': 'docker',
|
||||
'name': 'linux-%s' % (arch),
|
||||
'platform': {
|
||||
'os': 'linux',
|
||||
'arch': arch,
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'name': 'environment',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': [
|
||||
'go version',
|
||||
'go env',
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'build',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': build,
|
||||
},
|
||||
{
|
||||
'name': 'executable',
|
||||
'image': 'golang:1.15',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'./release/linux/%s/drone-webhook --help' % (arch),
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'docker',
|
||||
'image': 'plugins/docker',
|
||||
'pull': 'always',
|
||||
'settings': docker,
|
||||
},
|
||||
],
|
||||
'depends_on': [],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
'refs/pull/**',
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
def windows(ctx, version):
|
||||
docker = [
|
||||
'echo $env:PASSWORD | docker login --username $env:USERNAME --password-stdin',
|
||||
]
|
||||
|
||||
if ctx.build.event == 'tag':
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-webhook.exe ./cmd/drone-webhook' % (ctx.build.ref.replace("refs/tags/v", "")),
|
||||
]
|
||||
|
||||
docker = docker + [
|
||||
'docker build --pull -f docker/Dockerfile.windows.%s -t plugins/webhook:%s-windows-%s-amd64 .' % (version, ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
'docker run --rm plugins/webhook:%s-windows-%s-amd64 --help' % (ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
'docker push plugins/webhook:%s-windows-%s-amd64' % (ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
]
|
||||
else:
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-webhook.exe ./cmd/drone-webhook' % (ctx.build.commit[0:8]),
|
||||
]
|
||||
|
||||
docker = docker + [
|
||||
'docker build --pull -f docker/Dockerfile.windows.%s -t plugins/webhook:windows-%s-amd64 .' % (version, version),
|
||||
'docker run --rm plugins/webhook:windows-%s-amd64 --help' % (version),
|
||||
'docker push plugins/webhook:windows-%s-amd64' % (version),
|
||||
]
|
||||
|
||||
return {
|
||||
'kind': 'pipeline',
|
||||
'type': 'ssh',
|
||||
'name': 'windows-%s' % (version),
|
||||
'platform': {
|
||||
'os': 'windows',
|
||||
},
|
||||
'server': {
|
||||
'host': {
|
||||
'from_secret': 'windows_server_%s' % (version),
|
||||
},
|
||||
'user': {
|
||||
'from_secret': 'windows_username',
|
||||
},
|
||||
'password': {
|
||||
'from_secret': 'windows_password',
|
||||
},
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'name': 'environment',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': [
|
||||
'go version',
|
||||
'go env',
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'build',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': build,
|
||||
},
|
||||
{
|
||||
'name': 'executable',
|
||||
'commands': [
|
||||
'./release/windows/amd64/drone-webhook.exe --help',
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'docker',
|
||||
'environment': {
|
||||
'USERNAME': {
|
||||
'from_secret': 'docker_username',
|
||||
},
|
||||
'PASSWORD': {
|
||||
'from_secret': 'docker_password',
|
||||
},
|
||||
},
|
||||
'commands': docker,
|
||||
},
|
||||
],
|
||||
'depends_on': [],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
def manifest(ctx):
|
||||
return [{
|
||||
'kind': 'pipeline',
|
||||
'type': 'docker',
|
||||
'name': 'manifest',
|
||||
'steps': [
|
||||
{
|
||||
'name': 'manifest',
|
||||
'image': 'plugins/manifest',
|
||||
'pull': 'always',
|
||||
'settings': {
|
||||
'auto_tag': 'true',
|
||||
'username': {
|
||||
'from_secret': 'docker_username',
|
||||
},
|
||||
'password': {
|
||||
'from_secret': 'docker_password',
|
||||
},
|
||||
'spec': 'docker/manifest.tmpl',
|
||||
'ignore_missing': 'true',
|
||||
},
|
||||
},
|
||||
{
|
||||
'name': 'microbadger',
|
||||
'image': 'plugins/webhook',
|
||||
'pull': 'always',
|
||||
'settings': {
|
||||
'urls': {
|
||||
'from_secret': 'microbadger_url',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
'depends_on': [],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
}]
|
||||
|
||||
def gitter(ctx):
|
||||
return [{
|
||||
'kind': 'pipeline',
|
||||
'type': 'docker',
|
||||
'name': 'gitter',
|
||||
'clone': {
|
||||
'disable': True,
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'name': 'gitter',
|
||||
'image': 'plugins/gitter',
|
||||
'pull': 'always',
|
||||
'settings': {
|
||||
'webhook': {
|
||||
'from_secret': 'gitter_webhook',
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
'depends_on': [
|
||||
'manifest',
|
||||
],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
],
|
||||
'status': [
|
||||
'failure',
|
||||
],
|
||||
},
|
||||
}]
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: testing
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
commands:
|
||||
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
- golangci-lint version
|
||||
- golangci-lint run
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: "/go"
|
||||
- name: test
|
||||
image: golang:1.20
|
||||
commands:
|
||||
- go test -cover ./...
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: "/go"
|
||||
volumes:
|
||||
- name: gopath
|
||||
temp: {}
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: linux-amd64
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
steps:
|
||||
- name: environment
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go version
|
||||
- go env
|
||||
- name: build
|
||||
image: golang:1.20
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-webhook .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.linux.amd64
|
||||
repo: plugins/webhook
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-amd64
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: linux-arm64
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
pool:
|
||||
use: ubuntu_arm64
|
||||
|
||||
steps:
|
||||
- name: environment
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go version
|
||||
- go env
|
||||
- name: build
|
||||
image: golang:1.20
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-webhook .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.linux.arm64
|
||||
repo: plugins/webhook
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm64
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: windows-1809
|
||||
platform:
|
||||
os: windows
|
||||
arch: amd64
|
||||
pool:
|
||||
use: windows
|
||||
|
||||
steps:
|
||||
- name: environment
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go version
|
||||
- go env
|
||||
- name: build
|
||||
image: golang:1.20
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-webhook.exe .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.windows.1809
|
||||
repo: plugins/webhook
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: windows-1809-amd64
|
||||
daemon_off: true
|
||||
purge: false
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: windows-ltsc2022
|
||||
platform:
|
||||
os: windows
|
||||
arch: amd64
|
||||
pool:
|
||||
use: windows-2022
|
||||
|
||||
steps:
|
||||
- name: environment
|
||||
image: golang:1.20
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go version
|
||||
- go env
|
||||
- name: build
|
||||
image: golang:1.20
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-webhook.exe .
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.windows.ltsc2022
|
||||
repo: plugins/webhook
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: windows-ltsc2022-amd64
|
||||
daemon_off: true
|
||||
purge: false
|
||||
when:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
depends_on:
|
||||
- testing
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: vm
|
||||
name: manifest
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
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:
|
||||
- linux-amd64
|
||||
- linux-arm64
|
||||
- windows-1809
|
||||
- windows-ltsc2022
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/tags/**
|
||||
@@ -69,9 +69,5 @@ branches:
|
||||
- continuous-integration/drone/pr
|
||||
enforce_admins: false
|
||||
restrictions:
|
||||
apps:
|
||||
- renovate
|
||||
users: []
|
||||
teams:
|
||||
- Admins
|
||||
- Maintainers
|
||||
teams: []
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
/release/
|
||||
/drone-webhook*
|
||||
release/
|
||||
|
||||
coverage.out
|
||||
.drone.yml
|
||||
drone-webhook
|
||||
|
||||
@@ -199,3 +199,4 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-webhook/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||
// Replace below with all the flags required for the plugin.
|
||||
// Use Destination within the cli.Flags to populate settings
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "method",
|
||||
Usage: "webhook method",
|
||||
Value: "POST",
|
||||
EnvVars: []string{"PLUGIN_METHOD"},
|
||||
Destination: &settings.Method,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "username for basic auth",
|
||||
EnvVars: []string{"PLUGIN_USERNAME", "WEBHOOK_USERNAME"},
|
||||
Destination: &settings.Username,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "password for basic auth",
|
||||
EnvVars: []string{"PLUGIN_PASSWORD", "WEBHOOK_PASSWORD"},
|
||||
Destination: &settings.Password,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "content-type",
|
||||
Usage: "content type",
|
||||
Value: "application/json",
|
||||
EnvVars: []string{"PLUGIN_CONTENT_TYPE"},
|
||||
Destination: &settings.ContentType,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "template",
|
||||
Usage: "custom template for webhook",
|
||||
EnvVars: []string{"PLUGIN_TEMPLATE"},
|
||||
Destination: &settings.Template,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "headers",
|
||||
Usage: "custom headers key map",
|
||||
EnvVars: []string{"PLUGIN_HEADERS"},
|
||||
Destination: &settings.Headers,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "urls",
|
||||
Usage: "list of urls to perform the action on",
|
||||
EnvVars: []string{"PLUGIN_URLS", "PLUGIN_URL", "WEBHOOK_URLS", "WEBHOOK_URL"},
|
||||
Destination: &settings.URLs,
|
||||
},
|
||||
// Should be an IntSliceFlag but that doesn't have a Destination field
|
||||
&cli.StringSliceFlag{
|
||||
Name: "valid-response-codes",
|
||||
Usage: "list of valid http response codes",
|
||||
EnvVars: []string{"PLUGIN_VALID_RESPONSE_CODES"},
|
||||
Destination: &settings.ValidCodes,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// DO NOT MODIFY THIS FILE DIRECTLY
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/drone-plugins/drone-plugin-lib/errors"
|
||||
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||||
"github.com/drone-plugins/drone-webhook/plugin"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var version = "unknown"
|
||||
|
||||
func main() {
|
||||
settings := &plugin.Settings{}
|
||||
|
||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||
godotenv.Overload("/run/drone/env")
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "drone-webhook",
|
||||
Usage: "trigger webhooks",
|
||||
Version: version,
|
||||
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
||||
Action: run(settings),
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
errors.HandleExit(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(settings *plugin.Settings) cli.ActionFunc {
|
||||
return func(ctx *cli.Context) error {
|
||||
urfave.LoggingFromContext(ctx)
|
||||
|
||||
plugin := plugin.New(
|
||||
*settings,
|
||||
urfave.PipelineFromContext(ctx),
|
||||
urfave.NetworkFromContext(ctx),
|
||||
)
|
||||
|
||||
if err := plugin.Validate(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
|
||||
return errors.ExitMessagef("validation failed: %w", err)
|
||||
}
|
||||
|
||||
if err := plugin.Execute(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
|
||||
return errors.ExitMessagef("execution failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
const respFormat = `Webhook %d
|
||||
URL: %s
|
||||
RESPONSE STATUS: %s
|
||||
RESPONSE BODY: %s
|
||||
`
|
||||
|
||||
const debugFormat = `Webhook %d
|
||||
URL: %s
|
||||
METHOD: %s
|
||||
HEADERS: %s
|
||||
REQUEST BODY: %s
|
||||
RESPONSE STATUS: %s
|
||||
RESPONSE BODY: %s
|
||||
`
|
||||
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/amd64/drone-webhook /bin/
|
||||
ENTRYPOINT [ "/bin/drone-webhook" ]
|
||||
ENTRYPOINT ["/bin/drone-webhook"]
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
FROM plugins/base:multiarch
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
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" ]
|
||||
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/arm64/drone-webhook /bin/
|
||||
ENTRYPOINT [ "/bin/drone-webhook" ]
|
||||
ENTRYPOINT ["/bin/drone-webhook"]
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1909-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Webhook" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-webhook.exe C:/bin/drone-webhook.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-webhook.exe" ]
|
||||
@@ -1,10 +0,0 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-2004-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Webhook" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-webhook.exe C:/bin/drone-webhook.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-webhook.exe" ]
|
||||
@@ -1,5 +1,5 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1903-amd64
|
||||
FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Webhook" `
|
||||
+5
-23
@@ -1,12 +1,10 @@
|
||||
image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||
|
||||
{{#if build.tags}}
|
||||
tags:
|
||||
{{#each build.tags}}
|
||||
- {{this}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
manifests:
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
platform:
|
||||
@@ -16,29 +14,13 @@ manifests:
|
||||
platform:
|
||||
architecture: arm64
|
||||
os: linux
|
||||
variant: v8
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||
platform:
|
||||
architecture: arm
|
||||
os: linux
|
||||
variant: v7
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-2004-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 2004
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1909
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1903
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1809
|
||||
- image: plugins/webhook:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: ltsc2022
|
||||
@@ -1,10 +1,17 @@
|
||||
module github.com/drone-plugins/drone-webhook
|
||||
|
||||
go 1.15
|
||||
require (
|
||||
github.com/drone/drone-template-lib v0.0.0-20181004051823-4019baa6c594
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/urfave/cli v1.20.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
||||
github.com/drone/drone-template-lib v1.0.0
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
bou.ke/monkey v1.0.1 // indirect
|
||||
github.com/aymerick/raymond v2.0.2+incompatible // indirect
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/tkuchiki/faketime v0.1.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2 // indirect
|
||||
)
|
||||
|
||||
go 1.20
|
||||
|
||||
@@ -1,58 +1,17 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
|
||||
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
|
||||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI=
|
||||
github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
||||
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
|
||||
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
|
||||
github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0=
|
||||
github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||
github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
|
||||
github.com/drone/drone-template-lib v1.0.0 h1:PNBBfUhifRnrPCoWBlTitk3jipXdv8u8WLbIf7h7j00=
|
||||
github.com/drone/drone-template-lib v1.0.0/go.mod h1:Hqy1tgqPH5mtbFOZmow19l4jOkZvp+WZ00cB4W3MJhg=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
|
||||
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
|
||||
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
||||
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
|
||||
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/drone/drone-template-lib v0.0.0-20181004051823-4019baa6c594 h1:zPRVfiHpXeGt1XGpK2TQcaj2lRydiGdVz1AoHkaC554=
|
||||
github.com/drone/drone-template-lib v0.0.0-20181004051823-4019baa6c594/go.mod h1:u34woe41m58Whrf21iH6z/xLOIRM3650LhWAyUc7Oik=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0=
|
||||
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
github.com/tkuchiki/faketime v0.1.1 h1:UZjBlktFAi23wo+jWuHuNoHUpLnB0j/5B62bl5nCPls=
|
||||
github.com/tkuchiki/faketime v0.1.1/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "webhook plugin"
|
||||
app.Usage = "webhook plugin"
|
||||
app.Action = run
|
||||
app.Version = version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "method",
|
||||
Usage: "webhook method",
|
||||
EnvVar: "PLUGIN_METHOD",
|
||||
Value: "POST",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "username for basic auth",
|
||||
EnvVar: "PLUGIN_USERNAME,WEBHOOK_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "password for basic auth",
|
||||
EnvVar: "PLUGIN_PASSWORD,WEBHOOK_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "token-value",
|
||||
Usage: "token value",
|
||||
EnvVar: "PLUGIN_TOKEN_VALUE,WEBHOOK_TOKEN_VALUE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "token-type",
|
||||
Usage: "type of token",
|
||||
EnvVar: "PLUGIN_TOKEN_TYPE,WEBHOOK_TOKEN_TYPE",
|
||||
Value: "Bearer",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "content-type",
|
||||
Usage: "content type",
|
||||
EnvVar: "PLUGIN_CONTENT_TYPE",
|
||||
Value: "application/json",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "template",
|
||||
Usage: "custom template for webhook",
|
||||
EnvVar: "PLUGIN_TEMPLATE",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "headers",
|
||||
Usage: "custom headers key map",
|
||||
EnvVar: "PLUGIN_HEADERS",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "urls",
|
||||
Usage: "list of urls to perform the action on",
|
||||
EnvVar: "PLUGIN_URLS,WEBHOOK_URLS",
|
||||
},
|
||||
cli.IntSliceFlag{
|
||||
Name: "valid-response-codes",
|
||||
Usage: "list of valid http response codes",
|
||||
EnvVar: "PLUGIN_VALID_RESPONSE_CODES",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "enable debug information",
|
||||
EnvVar: "PLUGIN_DEBUG",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-verify",
|
||||
Usage: "skip ssl verification",
|
||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "signature-header",
|
||||
Usage: "header name to use in request",
|
||||
EnvVar: "PLUGIN_SIGNATURE_HEADER,WEBHOOK_SIGNATURE_HEADER",
|
||||
Value: "X-Drone-Signature",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "signature-secret",
|
||||
Usage: "secret to generate signature",
|
||||
EnvVar: "PLUGIN_SIGNATURE_SECRET,WEBHOOK_SIGNATURE_SECRET",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repository owner",
|
||||
EnvVar: "DRONE_REPO_OWNER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repository name",
|
||||
EnvVar: "DRONE_REPO_NAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "git commit sha",
|
||||
EnvVar: "DRONE_COMMIT_SHA",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.ref",
|
||||
Value: "refs/heads/master",
|
||||
Usage: "git commit ref",
|
||||
EnvVar: "DRONE_COMMIT_REF",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "git commit branch",
|
||||
EnvVar: "DRONE_COMMIT_BRANCH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "git author name",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVar: "DRONE_COMMIT_MESSAGE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "build event",
|
||||
EnvVar: "DRONE_BUILD_EVENT",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "build number",
|
||||
EnvVar: "DRONE_BUILD_NUMBER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
Value: "success",
|
||||
EnvVar: "DRONE_BUILD_STATUS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "build link",
|
||||
EnvVar: "DRONE_BUILD_LINK",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.deployTo",
|
||||
Usage: "environment deployed to",
|
||||
EnvVar: "DRONE_DEPLOY_TO",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "build.started",
|
||||
Usage: "build started",
|
||||
EnvVar: "DRONE_BUILD_STARTED",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "build.created",
|
||||
Usage: "build created",
|
||||
EnvVar: "DRONE_BUILD_CREATED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.tag",
|
||||
Usage: "build tag",
|
||||
EnvVar: "DRONE_TAG",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "job.started",
|
||||
Usage: "job started",
|
||||
EnvVar: "DRONE_JOB_STARTED",
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||
_ = godotenv.Overload("/run/drone/env")
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
plugin := Plugin{
|
||||
Repo: Repo{
|
||||
Owner: c.String("repo.owner"),
|
||||
Name: c.String("repo.name"),
|
||||
},
|
||||
Build: Build{
|
||||
Tag: c.String("build.tag"),
|
||||
Number: c.Int("build.number"),
|
||||
Event: c.String("build.event"),
|
||||
Status: c.String("build.status"),
|
||||
Commit: c.String("commit.sha"),
|
||||
Ref: c.String("commit.ref"),
|
||||
Branch: c.String("commit.branch"),
|
||||
Author: c.String("commit.author"),
|
||||
Message: c.String("commit.message"),
|
||||
Link: c.String("build.link"),
|
||||
DeployTo: c.String("build.deployTo"),
|
||||
Started: c.Int64("build.started"),
|
||||
Created: c.Int64("build.created"),
|
||||
},
|
||||
Job: Job{
|
||||
Started: c.Int64("job.started"),
|
||||
},
|
||||
Config: Config{
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
TokenValue: c.String("token-value"),
|
||||
TokenType: c.String("token-type"),
|
||||
ContentType: c.String("content-type"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
URLs: c.StringSlice("urls"),
|
||||
ValidCodes: c.IntSlice("valid-response-codes"),
|
||||
Debug: c.Bool("debug"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
SignatureHeader: c.String("signature-header"),
|
||||
SignatureSecret: c.String("signature-secret"),
|
||||
},
|
||||
}
|
||||
|
||||
return plugin.Exec()
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone-template-lib/template"
|
||||
)
|
||||
|
||||
type (
|
||||
Repo struct {
|
||||
Owner string `json:"owner"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
Build struct {
|
||||
Tag string `json:"tag"`
|
||||
Event string `json:"event"`
|
||||
Number int `json:"number"`
|
||||
Commit string `json:"commit"`
|
||||
Ref string `json:"ref"`
|
||||
Branch string `json:"branch"`
|
||||
Author string `json:"author"`
|
||||
Message string `json:"message"`
|
||||
Status string `json:"status"`
|
||||
Link string `json:"link"`
|
||||
DeployTo string `json:"deployTo"`
|
||||
Started int64 `json:"started"`
|
||||
Created int64 `json:"created"`
|
||||
}
|
||||
|
||||
Config struct {
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
TokenValue string
|
||||
TokenType string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
ValidCodes []int
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
SignatureHeader string
|
||||
SignatureSecret string
|
||||
}
|
||||
|
||||
Job struct {
|
||||
Started int64
|
||||
}
|
||||
|
||||
Plugin struct {
|
||||
Repo Repo
|
||||
Build Build
|
||||
Config Config
|
||||
Job Job
|
||||
}
|
||||
)
|
||||
|
||||
func (p Plugin) Exec() error {
|
||||
var (
|
||||
buf bytes.Buffer
|
||||
b []byte
|
||||
)
|
||||
|
||||
if len(p.Config.URLs) == 0 {
|
||||
return fmt.Errorf("You must provide at least one url")
|
||||
}
|
||||
|
||||
if p.Config.Template == "" {
|
||||
data := struct {
|
||||
Repo Repo `json:"repo"`
|
||||
Build Build `json:"build"`
|
||||
}{p.Repo, p.Build}
|
||||
|
||||
if err := json.NewEncoder(&buf).Encode(&data); err != nil {
|
||||
fmt.Printf("Error: Failed to encode JSON payload. %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
b = buf.Bytes()
|
||||
} else {
|
||||
txt, err := template.RenderTrim(p.Config.Template, p)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
text := txt
|
||||
b = []byte(text)
|
||||
}
|
||||
|
||||
// build and execute a request for each url.
|
||||
// all auth, headers, method, template (payload),
|
||||
// and content_type values will be applied to
|
||||
// every webhook request.
|
||||
|
||||
for i, rawurl := range p.Config.URLs {
|
||||
uri, err := url.Parse(rawurl)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: Failed to parse the hook URL. %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
r := bytes.NewReader(b)
|
||||
req, err := http.NewRequest(p.Config.Method, uri.String(), r)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: Failed to create the HTTP request. %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", p.Config.ContentType)
|
||||
|
||||
if p.Config.SignatureSecret != "" {
|
||||
// generate signature with secret and body
|
||||
h := hmac.New(sha256.New, []byte(p.Config.SignatureSecret))
|
||||
h.Write(b)
|
||||
sha := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
// append signature to headers
|
||||
req.Header.Set(p.Config.SignatureHeader, fmt.Sprintf("sha256=%s", sha))
|
||||
}
|
||||
|
||||
for _, value := range p.Config.Headers {
|
||||
header := strings.Split(value, "=")
|
||||
req.Header.Set(header[0], header[1])
|
||||
}
|
||||
|
||||
if p.Config.Username != "" && p.Config.Password != "" {
|
||||
req.SetBasicAuth(p.Config.Username, p.Config.Password)
|
||||
}
|
||||
|
||||
if p.Config.TokenValue != "" {
|
||||
req.Header.Set("Authorization", fmt.Sprintf("%s %s", p.Config.TokenType, p.Config.TokenValue))
|
||||
}
|
||||
|
||||
client := http.DefaultClient
|
||||
|
||||
if p.Config.SkipVerify {
|
||||
client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: Failed to execute the HTTP request. %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if p.Config.Debug || resp.StatusCode >= http.StatusBadRequest {
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error: Failed to read the HTTP response body. %s\n", err)
|
||||
}
|
||||
|
||||
if p.Config.Debug {
|
||||
fmt.Printf(
|
||||
debugFormat,
|
||||
i+1,
|
||||
req.URL,
|
||||
req.Method,
|
||||
req.Header,
|
||||
string(b),
|
||||
resp.Status,
|
||||
string(body),
|
||||
)
|
||||
} else {
|
||||
fmt.Printf(
|
||||
respFormat,
|
||||
i+1,
|
||||
req.URL,
|
||||
resp.Status,
|
||||
string(body),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if len(p.Config.ValidCodes) > 0 && !intInSlice(p.Config.ValidCodes, resp.StatusCode) {
|
||||
return fmt.Errorf("Error: Response code %d not found among valid response codes", resp.StatusCode)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Function checks if int is in slice of ints
|
||||
func intInSlice(s []int, e int) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
run:
|
||||
go:
|
||||
module: github.com/drone-plugins/drone-webhook
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import "fmt"
|
||||
|
||||
// intInSlice checks if int is in slice of ints
|
||||
func intInSlice(s []string, e int) bool {
|
||||
eStr := fmt.Sprintf("%d", e)
|
||||
for _, a := range s {
|
||||
if a == eStr {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone-template-lib/template"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Settings for the plugin.
|
||||
type Settings struct {
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers cli.StringSlice
|
||||
URLs cli.StringSlice
|
||||
ValidCodes cli.StringSlice
|
||||
payload []byte
|
||||
}
|
||||
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
if len(p.settings.URLs.Value()) == 0 {
|
||||
return errors.New("must provide at least one webhook url")
|
||||
}
|
||||
|
||||
for _, raw := range p.settings.URLs.Value() {
|
||||
_, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if p.settings.Template == "" {
|
||||
res, err := json.Marshal(&p.pipeline)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate json response: %w", err)
|
||||
}
|
||||
|
||||
p.settings.payload = res
|
||||
} else {
|
||||
res, err := template.RenderTrim(p.settings.Template, p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse response template: %w", err)
|
||||
}
|
||||
|
||||
p.settings.payload = []byte(res)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
for i, raw := range p.settings.URLs.Value() {
|
||||
uri, _ := url.Parse(raw)
|
||||
|
||||
req, err := http.NewRequest(p.settings.Method, uri.String(), bytes.NewReader(p.settings.payload))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create http request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", p.settings.ContentType)
|
||||
for _, value := range p.settings.Headers.Value() {
|
||||
header := strings.SplitN(value, "=", 2)
|
||||
req.Header.Set(header[0], header[1])
|
||||
}
|
||||
|
||||
if p.settings.Username != "" && p.settings.Password != "" {
|
||||
req.SetBasicAuth(p.settings.Username, p.settings.Password)
|
||||
}
|
||||
|
||||
resp, err := p.network.Client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute http request: %w", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if /*p.settings.Debug ||*/ resp.StatusCode >= http.StatusBadRequest {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse http response: %w", err)
|
||||
}
|
||||
|
||||
output, err := template.RenderTrim(result, webhook{
|
||||
Debug: true, //p.settings.Debug,
|
||||
Number: i,
|
||||
URL: req.URL.String(),
|
||||
Method: req.Method,
|
||||
Header: req.Header,
|
||||
Status: resp.Status,
|
||||
Request: string(p.settings.payload),
|
||||
Response: string(body),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse debug template: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println(output)
|
||||
}
|
||||
|
||||
validCodes := p.settings.ValidCodes.Value()
|
||||
if len(validCodes) > 0 && !intInSlice(validCodes, resp.StatusCode) {
|
||||
return fmt.Errorf("response of %d is not valid", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||
)
|
||||
|
||||
// Plugin implements drone.Plugin to provide the plugin implementation.
|
||||
type Plugin struct {
|
||||
settings Settings
|
||||
pipeline drone.Pipeline
|
||||
network drone.Network
|
||||
}
|
||||
|
||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
||||
return &Plugin{
|
||||
settings: settings,
|
||||
pipeline: pipeline,
|
||||
network: network,
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// webhook defines the result payload.
|
||||
type webhook struct {
|
||||
Number int
|
||||
URL string
|
||||
Method string
|
||||
Header http.Header
|
||||
Status string
|
||||
Request string
|
||||
Response string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
// result defines the output template.
|
||||
const result = `Webhook {{Number}}
|
||||
URL: {{URL}}{{#if Debug}}
|
||||
METHOD: {{Method}}
|
||||
HEADERS: {{Headers}}
|
||||
REQUEST: {{Request}}{{/if}}
|
||||
STATUS: {{Status}}
|
||||
RESPONSE: {{Response}}
|
||||
`
|
||||
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base",
|
||||
":automergeMinor",
|
||||
":automergeDigest"
|
||||
],
|
||||
"enabledManagers": [
|
||||
"dockerfile",
|
||||
"gomod"
|
||||
],
|
||||
"dockerfile": {
|
||||
"fileMatch": [
|
||||
"docker/Dockerfile\\.linux\\.(arm|arm64|amd64|multiarch)",
|
||||
"docker/Dockerfile\\.windows\\.(1809|1903|1909|2004)"
|
||||
],
|
||||
"pinDigests": true
|
||||
},
|
||||
"gomod": {
|
||||
"postUpdateOptions": [
|
||||
"gomodTidy"
|
||||
]
|
||||
},
|
||||
"labels": [
|
||||
"renovate"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user