Compare commits

...

55 Commits

Author SHA1 Message Date
Bo-Yi Wu 2830e39260 chore: update go module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-04 15:12:06 +08:00
Bo-Yi Wu d4b1c86367 chore: update drone-template-lib module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-04 15:06:56 +08:00
Bo-Yi Wu e1e8532e04 chore: update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-04 15:05:47 +08:00
Bo-Yi Wu 52b70e4a89 chore: updae drone template library
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-03 10:59:33 +08:00
Bo-Yi Wu f6c3df01ff chore: update go module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-06-18 08:51:38 +08:00
Bo-Yi Wu 78124dd591 chore: upgrade to go.16
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-06-18 08:51:09 +08:00
Laurant Marijnissen 61e5d95ddb Small spelling correction (#34) 2020-12-16 15:54:36 +08:00
Bo-Yi Wu a451d9e0a5 chore: upgrade to go1.15
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-26 12:19:09 +08:00
Bo-Yi Wu 30be2b99d7 update build time format
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-23 12:16:10 +08:00
Bo-Yi Wu 546c9b8541 chore: update build name
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-21 10:30:27 +08:00
Bo-Yi Wu 48f22eab4a chore: upgrade to go1.14 2020-07-18 15:48:12 +08:00
Bo-Yi Wu 8567e2de7b chore: load env from /run/drone/env path 2020-07-17 23:24:45 +08:00
Bo-Yi Wu 5804cc4e37 chore: support for kubernetes runner (#32)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-01 21:11:32 +08:00
Bo-Yi Wu 026a8936a9 chore: remove secrets in docs
fix https://github.com/appleboy/drone-discord/issues/28
2020-05-08 19:21:40 +08:00
Bo-Yi Wu fd5ccbeed3 chore: update format 2020-05-08 19:08:04 +08:00
fgierlinger 28dea47a9c Added information about discords webhook url (#27) 2020-05-08 19:06:43 +08:00
Bo-Yi Wu cb122520bd chore: add datetime example. 2020-03-26 23:49:35 +08:00
Bo-Yi Wu f677050f44 chore: Add duration 2020-03-26 23:45:14 +08:00
Bo-Yi Wu f0a5083d6d chore: Add duration 2020-03-26 23:39:34 +08:00
Bo-Yi Wu b2f5cf4ba4 chore: Add duration 2020-03-26 23:36:25 +08:00
Bo-Yi Wu cfc2d80805 chore: upgrade go module 2020-03-26 23:26:09 +08:00
Bo-Yi Wu 5607652dd4 chore(makefile): remove GOPACKAGE variable 2020-02-01 00:45:23 +08:00
Maxime Malgorn 1e6904c06b docs: fix the image name in examples (#23) 2020-01-19 00:28:12 +08:00
Antoine GIRARD e2b1b67069 fix typo discored (#25)
drone-discored -> drone-discord
2020-01-19 00:27:43 +08:00
Bo-Yi Wu 11c87968e4 chore: update int64 to float64 2019-10-24 00:04:26 +08:00
Bo-Yi Wu a15636218c docs: add repo 2019-10-19 09:43:56 +08:00
Bo-Yi Wu b3140a539b docs: update diff format 2019-10-19 08:08:38 +08:00
Bo-Yi Wu 4df8911cdf fix: #21 update build.started env 2019-10-13 02:07:28 +08:00
Bo-Yi Wu 33e2805dd8 revert
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:57:39 +08:00
Bo-Yi Wu 82e100bf9a update time format
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:47:31 +08:00
Bo-Yi Wu d7ec25b596 testing
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:43:57 +08:00
Bo-Yi Wu 747ffca8cc chore: remove debug message 2019-10-13 01:23:48 +08:00
Bo-Yi Wu 83561d842b remove file if empty
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:15:17 +08:00
Bo-Yi Wu 5eb8b48ec3 debug
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 00:39:54 +08:00
Bo-Yi Wu fe2b53fab4 chore: add discord message 2019-10-13 00:16:14 +08:00
Bo-Yi Wu 9fce8c8c6b fix: testing 2019-10-12 23:36:16 +08:00
Bo-Yi Wu 1ab023c10d chore: update drone env 2019-10-12 23:33:06 +08:00
Bo-Yi Wu cfd3725c9a chore: replace template library 2019-10-11 20:42:10 +08:00
Bo-Yi Wu aecc652459 chore: support github actions 2019-10-04 21:13:53 +08:00
Bo-Yi Wu 4ef98156ed chore: add arch for building 2019-10-04 21:11:26 +08:00
Bo-Yi Wu 7b0188f107 docs: update 2019-10-04 21:09:36 +08:00
Bo-Yi Wu 851c23f7fa chore: upgrade go module 2019-10-04 20:58:06 +08:00
Bo-Yi Wu 8396f108b8 chore: upgrade to 1.13 2019-10-04 20:57:23 +08:00
Bo-Yi Wu a9f7dd6911 docs: update format 2019-10-04 20:55:40 +08:00
Bo-Yi Wu 98665b9a28 feat: update go module version 2019-03-24 21:59:50 +08:00
Bo-Yi Wu e67bb8f829 chore: update windows ENTRYPOINT path 2019-03-24 21:58:10 +08:00
Bo-Yi Wu ab201cc6f9 chore: update base images for windows 2019-03-24 21:55:55 +08:00
Bo-Yi Wu fcf20615e8 chore: rename dockerfile 2019-03-24 21:53:42 +08:00
Bo-Yi Wu e88ca34689 feat: build in go1.12 2019-03-24 21:50:44 +08:00
Bo-Yi Wu fc75470770 feat: add appveyor badge 2019-03-24 21:46:18 +08:00
Bo-Yi Wu 412a50abe1 feat: Add windows images 2019-03-24 21:44:21 +08:00
Bo-Yi Wu 187468f10b chore(docker): replace ADD with COPY 2019-03-04 21:44:20 +08:00
Bo-Yi Wu d20387ae04 chore: update golang to 1.12 2019-02-27 14:40:35 +08:00
Bo-Yi Wu 11fec702d5 docs: ci skip: add ref for upload file 2019-02-27 14:40:03 +08:00
Bo-Yi Wu a474b187c6 Fix manifest template helper
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-26 10:21:26 +08:00
16 changed files with 359 additions and 267 deletions
+61
View File
@@ -0,0 +1,61 @@
version: '{build}'
image: 'Visual Studio 2017'
platform: x64
max_jobs: 1
environment:
GOPATH: c:\go
docker_username:
secure: em/TNLUXxG19O/HvbvfJuQ==
docker_password:
secure: Yo9FJJqihaNz5q8T4Jz8tQ==
branches:
only:
- master
install:
- ps: |
docker version
go version
go env
build_script:
- ps: |
if ( $env:APPVEYOR_REPO_TAG -eq 'false' ) {
$version = $env:APPVEYOR_REPO_COMMIT
} else {
$version = $env:APPVEYOR_REPO_TAG_NAME
}
go build -ldflags "-X main.Version=$version" -a -o release/drone-discord.exe .
docker pull microsoft/nanoserver:10.0.14393.1884
docker build -f docker/Dockerfile.windows.amd64 -t appleboy/drone-discord:windows-amd64 .
test_script:
- ps: |
docker run --rm appleboy/drone-discord:windows-amd64 --version
deploy_script:
- ps: |
$ErrorActionPreference = 'Stop';
if ( $env:APPVEYOR_PULL_REQUEST_NUMBER ) {
Write-Host Nothing to deploy.
} else {
echo $env:DOCKER_PASSWORD | docker login --username $env:DOCKER_USERNAME --password-stdin
if ( $env:APPVEYOR_REPO_TAG -eq 'true' ) {
$major,$minor,$patch = $env:APPVEYOR_REPO_TAG_NAME.split('.')
docker push appleboy/drone-discord:windows-amd64
docker tag appleboy/drone-discord:windows-amd64 appleboy/drone-discord:$major.$minor.$patch-windows-amd64
docker push appleboy/drone-discord:$major.$minor.$patch-windows-amd64
docker tag appleboy/drone-discord:windows-amd64 appleboy/drone-discord:$major.$minor-windows-amd64
docker push appleboy/drone-discord:$major.$minor-windows-amd64
docker tag appleboy/drone-discord:windows-amd64 appleboy/drone-discord:$major-windows-amd64
docker push appleboy/drone-discord:$major-windows-amd64
} else {
if ( $env:APPVEYOR_REPO_BRANCH -eq 'master' ) {
docker push appleboy/drone-discord:windows-amd64
}
}
}
+39 -51
View File
@@ -9,45 +9,38 @@ platform:
steps:
- name: vet
pull: always
image: golang:1.11
image: golang:1.16
commands:
- make vet
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: lint
pull: always
image: golang:1.11
image: golang:1.16
commands:
- make lint
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: misspell
pull: always
image: golang:1.11
image: golang:1.16
commands:
- make misspell-check
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.11
image: golang:1.16
commands:
- make test
- make coverage
environment:
GO111MODULE: on
WEBHOOK_ID:
from_secret: webhook_id
WEBHOOK_TOKEN:
@@ -78,12 +71,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-discord"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -91,19 +83,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-discord"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/amd64/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.11
image: golang:1.16
commands:
- ./release/linux/amd64/drone-discord --help
@@ -142,8 +133,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -159,12 +150,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-discord"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -172,19 +162,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-discord"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm64/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.11
image: golang:1.16
commands:
- ./release/linux/arm64/drone-discord --help
@@ -223,8 +212,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -240,12 +229,11 @@ platform:
steps:
- name: build-push
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-discord"
- go build -v -ldflags '-X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
@@ -253,19 +241,18 @@ steps:
- name: build-tag
pull: always
image: golang:1.11
image: golang:1.16
commands:
- "go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-discord"
- go build -v -ldflags '-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -a -o release/linux/arm/drone-discord
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.11
image: golang:1.16
commands:
- ./release/linux/arm/drone-discord --help
@@ -304,8 +291,8 @@ steps:
trigger:
ref:
- refs/heads/master
- "refs/pull/**"
- "refs/tags/**"
- refs/pull/**
- refs/tags/**
depends_on:
- testing
@@ -321,11 +308,9 @@ platform:
steps:
- name: build-all-binary
pull: always
image: golang:1.11
image: golang:1.16
commands:
- make release
environment:
GO111MODULE: on
when:
event:
- tag
@@ -337,14 +322,14 @@ steps:
api_key:
from_secret: github_release_api_key
files:
- "dist/release/*"
- dist/release/*
when:
event:
- tag
trigger:
ref:
- "refs/tags/**"
- refs/tags/**
depends_on:
- testing
@@ -358,6 +343,16 @@ platform:
arch: amd64
steps:
- name: discord
pull: always
image: appleboy/drone-discord
settings:
message: "{{#success build.status}} ✅ Build #{{build.number}} of `{{repo.name}}` succeeded.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n🌐 {{ build.link }}\n\n ✅ duration: {{duration build.started build.finished}} \n\n ✅ started: {{datetime build.started \"2006/01/02 15:04\" \"Asia/Taipei\"}} \n\n ✅ finished: {{datetime build.finished \"2006/01/02 15:04\" \"Asia/Taipei\"}} {{else}} ❌ Build #{{build.number}} of `{{repo.name}}` failed.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n🌐 {{ build.link }}\n\n ✅ duration: {{duration build.started build.finished}} \n\n ✅ started: {{datetime build.started \"2006/01/02 15:04\" \"Asia/Taipei\"}} \n\n ✅ finished: {{datetime build.finished \"2006/01/02 15:04\" \"Asia/Taipei\"}}{{/success}}\n"
webhook_id:
from_secret: webhook_id
webhook_token:
from_secret: webhook_token
- name: manifest
pull: always
image: plugins/manifest
@@ -369,17 +364,10 @@ steps:
username:
from_secret: docker_username
- name: microbadger
pull: always
image: plugins/webhook:1
settings:
url:
from_secret: microbadger_url
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- refs/tags/**
depends_on:
- linux-amd64
+49 -41
View File
@@ -5,17 +5,24 @@ author: appleboy
tags: [ notifications, chat ]
repo: appleboy/drone-discord
logo: discord.svg
repo: appleboy/drone-discord
image: appleboy/drone-discord
---
Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use.
The webhook provided by discord is a single URL which contains the webhook_id and the webhook_token. The URL follows the following pattern:
```sh
https://discord.com/api/webhooks/<webhook_id>/<webhook_token>
```
The discord plugin posts build status messages to discord channel. The below pipeline configuration demonstrates simple usage:
```yaml
pipeline:
discord:
image: appleboy/drone-discord
- name: discord notification
image: appleboy/drone-discord
settings:
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
```
@@ -23,68 +30,69 @@ pipeline:
Example configuration with TTS (text-to-speech) message:
```diff
pipeline:
discord:
- name: discord notification
image: appleboy/drone-discord
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ tts: true
message: "Testing from drone image"
settings:
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ tts: true
message: "Testing from drone image"
```
Example configuration with override the default username of the webhook:
```diff
pipeline:
discord:
- name: discord notification
image: appleboy/drone-discord
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ username: appleboy
message: "Testing from drone image"
settings:
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ username: appleboy
message: "Testing from drone image"
```
Example configuration with override the default avatar of the webhook:
```diff
pipeline:
discord:
- name: discord notification
image: appleboy/drone-discord
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ avatar_url: http://exampple.com/appleboy.png
message: "Testing from drone image"
settings:
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ avatar_url: http://exampple.com/appleboy.png
message: "Testing from drone image"
```
Example configuration with a custom message template:
```diff
pipeline:
discord:
- name: discord notification
image: appleboy/drone-discord
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ message: >
+ {{#success build.status}}
+ build {{build.number}} succeeded. Good job.
+ {{else}}
+ build {{build.number}} failed. Fix me please.
+ {{/success}}
settings:
webhook_id: xxxxxxxxxx
webhook_token: xxxxxxxxxx
+ message: >
+ {{#success build.status}}
+ build {{build.number}} succeeded. Good job.
+ {{else}}
+ build {{build.number}} failed. Fix me please.
+ {{/success}}
```
Example configuration using credentials from secrets:
```diff
pipeline:
discord:
- name: discord notification
image: appleboy/drone-discord
- webhook_id: xxxxxxxxxx
- webhook_token: xxxxxxxxxx
+ secrets: [ discord_webhook_id, discord_webhook_token ]
message: "Testing from drone image"
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token
message: "Testing from drone image"
```
# Secret Reference
## Secret Reference
discord_webhook_id
: discord webhook id
@@ -92,7 +100,7 @@ discord_webhook_id
discord_webhook_token
: discord webhook token
# Parameter Reference
## Parameter Reference
webhook_id
: webhook id
@@ -112,7 +120,7 @@ tts
message
: the message contents (up to 2000 characters)
# Template Reference
## Template Reference
repo.owner
: repository owner
@@ -156,7 +164,7 @@ build.started
build.finished
: unix timestamp for build finished
# Template Function Reference
## Template Function Reference
uppercasefirst
: converts the first letter of a string to uppercase
+3 -4
View File
@@ -8,7 +8,6 @@ DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux darwin windows
PACKAGES ?= $(shell $(GO) list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
@@ -32,7 +31,7 @@ fmt:
$(GOFMT) -w $(SOURCES)
vet:
$(GO) vet $(PACKAGES)
$(GO) vet ./...
lint:
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
@@ -64,7 +63,7 @@ fmt-check:
fi;
test: fmt-check
@$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
install: $(SOURCES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
@@ -83,7 +82,7 @@ release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
+17 -43
View File
@@ -1,15 +1,16 @@
<img src="images/discord-logo.png">
# drone-[discord](https://discordapp.com)
![logo](images/discord-logo.png)
Drone plugin for sending message to Discord channel using Webhook.
[![GoDoc](https://godoc.org/github.com/appleboy/drone-discord?status.svg)](https://godoc.org/github.com/appleboy/drone-discord)
[![Build Status](https://cloud.drone.io/api/badges/appleboy/drone-discord/status.svg)](https://cloud.drone.io/appleboy/drone-discord)
[![Build status](https://ci.appveyor.com/api/projects/status/xj24ye9lu68a9sqm?svg=true)](https://ci.appveyor.com/project/appleboy/drone-discord-bne7m)
[![codecov](https://codecov.io/gh/appleboy/drone-discord/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-discord)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-discord)](https://goreportcard.com/report/github.com/appleboy/drone-discord)
[![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-discord.svg)](https://hub.docker.com/r/appleboy/drone-discord/)
[![](https://images.microbadger.com/badges/image/appleboy/drone-discord:linux-amd64.svg)](https://microbadger.com/images/appleboy/drone-discord:linux-amd64 "Get your own image badge on microbadger.com")
[![microbadger](https://images.microbadger.com/badges/image/appleboy/drone-discord:linux-amd64.svg)](https://microbadger.com/images/appleboy/drone-discord:linux-amd64 "Get your own image badge on microbadger.com")
Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. See more [api document information](https://discordapp.com/developers/docs/resources/webhook). For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/appleboy/drone-discord/).
@@ -18,7 +19,7 @@ Sending discord message using a binary, docker or [Drone CI](http://docs.drone.i
## Features
* [x] Send Multiple Messages
* [x] Send Multiple Files
* [x] Send Multiple Files
## Build or Download a binary
@@ -30,52 +31,29 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
With `Go` installed
```sh
go get -u -v github.com/appleboy/drone-discord
```
$ go get -u -v github.com/appleboy/drone-discord
```
or build the binary with the following command:
```
$ export GOOS=linux
$ export GOARCH=amd64
$ export CGO_ENABLED=0
$ export GO111MODULE=on
```sh
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
$ go test -cover ./...
go test -cover ./...
$ go build -v -a -tags netgo -o release/linux/amd64/drone-discord .
```
## Docker
Build the docker image with the following commands:
```
$ make docker
```
Please note incorrectly building the image for the correct x64 linux and with
CGO disabled will result in an error when running the Docker image:
```
docker: Error response from daemon: Container command
'/bin/drone-discord' not found or does not exist..
go build -v -a -tags netgo -o release/linux/amd64/drone-discord
```
## Usage
There are three ways to send notification.
* [usage from binary](#usage-from-binary)
* [usage from docker](#usage-from-docker)
* [usage from drone ci](#usage-from-drone-ci)
<a name="usage-from-binary"></a>
### Usage from binary
#### Send Notification
```bash
drone-discord \
--webhook-id xxxx \
@@ -83,11 +61,8 @@ drone-discord \
--message "Test Message"
```
<a name="usage-from-docker"></a>
### Usage from docker
#### Send Notification
```bash
docker run --rm \
-e WEBHOOK_ID=xxxxxxx \
@@ -100,14 +75,13 @@ docker run --rm \
appleboy/drone-discord
```
<a name="usage-from-drone-ci"></a>
### Usage from drone ci
#### Send Notification
Execute from the working directory:
```bash
```sh
docker run --rm \
-e WEBHOOK_ID=xxxxxxx \
-e WEBHOOK_TOKEN=xxxxxxx \
@@ -139,6 +113,6 @@ You can get more [information](DOCS.md) about how to use this plugin in drone.
Test the package with the following command:
```
$ make test
```sh
make test
```
+1 -1
View File
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
ADD release/linux/amd64/drone-discord /bin/
COPY release/linux/amd64/drone-discord /bin/
ENTRYPOINT ["/bin/drone-discord"]
+1 -1
View File
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
ADD release/linux/arm/drone-discord /bin/
COPY release/linux/arm/drone-discord /bin/
ENTRYPOINT ["/bin/drone-discord"]
+1 -1
View File
@@ -5,6 +5,6 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
ADD release/linux/arm64/drone-discord /bin/
COPY release/linux/arm64/drone-discord /bin/
ENTRYPOINT ["/bin/drone-discord"]
@@ -1,9 +1,10 @@
FROM plugins/base:windows-amd64
FROM microsoft/nanoserver:10.0.14393.1884
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Discord" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
ADD release/drone-discord.exe /drone-discord.exe
ENTRYPOINT [ "\\drone-discord.exe" ]
COPY release/drone-discord.exe C:/bin/drone-discord.exe
ENTRYPOINT [ "C:\\bin\\drone-discord.exe" ]
+4 -4
View File
@@ -1,4 +1,4 @@
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}{{else}}latest{{/if}}
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,18 +7,18 @@ tags:
{{/if}}
manifests:
-
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-amd64
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm64
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
-
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
+6 -8
View File
@@ -1,12 +1,10 @@
module github.com/appleboy/drone-discord
go 1.13
require (
github.com/appleboy/drone-facebook v0.0.0-20170430101616-fdda56ebba0f
github.com/aymerick/raymond v0.0.0-20161209220724-72acac220747 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/joho/godotenv v0.0.0-20170328200154-325433c502d4
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v0.0.0-20170601210322-f6abca593680
github.com/urfave/cli v0.0.0-20170506042529-d70f47eeca3a
gopkg.in/yaml.v2 v2.2.2 // indirect
github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605
github.com/joho/godotenv v1.3.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.3
)
+51 -11
View File
@@ -1,18 +1,58 @@
github.com/appleboy/drone-facebook v0.0.0-20170430101616-fdda56ebba0f h1:X+DQ0ayEB/dcUp/YcsKzKcgdowjmUUInoRCYhtK1yg0=
github.com/appleboy/drone-facebook v0.0.0-20170430101616-fdda56ebba0f/go.mod h1:5PxqvgIcQy+Je2Rde2tbxGUG9/emkCHkFqZg/8vf4ZA=
github.com/aymerick/raymond v0.0.0-20161209220724-72acac220747 h1:gu88ZN3sXG5+1mH0W4Ty00jzHA044ND3ogxmJNN6Rik=
github.com/aymerick/raymond v0.0.0-20161209220724-72acac220747/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
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/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk=
github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/sprig/v3 v3.1.0 h1:j7GpgZ7PdFqNsmncycTHsLmVPf5/3wJtlgW9TNDYD9Y=
github.com/Masterminds/sprig/v3 v3.1.0/go.mod h1:ONGMf7UfYGAbMXCZmQLy8x3lCDIPrEZE/rU8pmrbihA=
github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605 h1:13DCA0YYotNdiFodfoWpMVBi4bBTv3OxO2o/IU60kuw=
github.com/appleboy/drone-template-lib v1.0.1-0.20210703043441-92442f23f605/go.mod h1:Mdr1SPt42qahB+Gfb/QBsQID+tkBkzrR+j+Gwq9XMBs=
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/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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v0.0.0-20170328200154-325433c502d4 h1:4efwqN/95XpF2pyttkH2f288+TcG0jFQUk0avks7zes=
github.com/joho/godotenv v0.0.0-20170328200154-325433c502d4/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
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/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v0.0.0-20170601210322-f6abca593680 h1:k3Cv7ttquofwySV/QIpSg4f2UYl/sPXAoTKIxO9CNGc=
github.com/stretchr/testify v0.0.0-20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v0.0.0-20170506042529-d70f47eeca3a h1:QCKpTIKfYPSx19VYrRHtsbShQVfIFzBFe3pO/wBUOc8=
github.com/urfave/cli v0.0.0-20170506042529-d70f47eeca3a/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
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/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
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.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+55 -35
View File
@@ -7,7 +7,6 @@ import (
"time"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)
@@ -15,6 +14,15 @@ import (
var Version string
func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
godotenv.Load(filename)
}
if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
}
year := fmt.Sprintf("%v", time.Now().Year())
app := cli.NewApp()
app.Name = "Drone Discord"
@@ -32,47 +40,47 @@ func main() {
cli.StringFlag{
Name: "webhook-id",
Usage: "discord webhook id",
EnvVar: "PLUGIN_WEBHOOK_ID,WEBHOOK_ID,DISCORD_WEBHOOK_ID",
EnvVar: "PLUGIN_WEBHOOK_ID,WEBHOOK_ID,DISCORD_WEBHOOK_ID,INPUT_WEBHOOK_ID",
},
cli.StringFlag{
Name: "webhook-token",
Usage: "discord webhook token",
EnvVar: "PLUGIN_WEBHOOK_TOKEN,WEBHOOK_TOKEN,DISCORD_WEBHOOK_TOKEN",
EnvVar: "PLUGIN_WEBHOOK_TOKEN,WEBHOOK_TOKEN,DISCORD_WEBHOOK_TOKEN,INPUT_WEBHOOK_TOKEN",
},
cli.StringSliceFlag{
Name: "message",
Usage: "the message contents (up to 2000 characters)",
EnvVar: "PLUGIN_MESSAGE,DISCORD_MESSAGE,MESSAGE",
EnvVar: "PLUGIN_MESSAGE,DISCORD_MESSAGE,MESSAGE,INPUT_MESSAGE",
},
cli.StringSliceFlag{
Name: "file",
Usage: "the contents of the file being sent",
EnvVar: "PLUGIN_FILE,DISCORD_FILE,FILE",
EnvVar: "PLUGIN_FILE,DISCORD_FILE,FILE,INPUT_FILE",
},
cli.StringFlag{
Name: "color",
Usage: "color code of the embed",
EnvVar: "PLUGIN_COLOR,COLOR",
EnvVar: "PLUGIN_COLOR,COLOR,INPUT_COLOR",
},
cli.BoolFlag{
Name: "wait",
Usage: "waits for server confirmation of message send before response, and returns the created message body",
EnvVar: "PLUGIN_WAIT,WAIT",
EnvVar: "PLUGIN_WAIT,WAIT,INPUT_WAIT",
},
cli.BoolFlag{
Name: "tts",
Usage: "true if this is a TTS message",
EnvVar: "PLUGIN_TTS,TTS",
EnvVar: "PLUGIN_TTS,TTS,INPUT_TTS",
},
cli.StringFlag{
Name: "username",
Usage: "override the default username of the webhook",
EnvVar: "PLUGIN_USERNAME,USERNAME",
EnvVar: "PLUGIN_USERNAME,USERNAME,INPUT_USERNAME",
},
cli.StringFlag{
Name: "avatar-url",
Usage: "override the default avatar of the webhook",
EnvVar: "PLUGIN_AVATAR_URL,AVATAR_URL",
EnvVar: "PLUGIN_AVATAR_URL,AVATAR_URL,INPUT_AVATAR_URL",
},
cli.BoolFlag{
Name: "drone",
@@ -110,6 +118,11 @@ func main() {
Usage: "git commit branch",
EnvVar: "DRONE_COMMIT_BRANCH",
},
cli.StringFlag{
Name: "commit.link",
Usage: "git commit link",
EnvVar: "DRONE_COMMIT_LINK",
},
cli.StringFlag{
Name: "commit.author",
Usage: "git author name",
@@ -157,19 +170,20 @@ func main() {
Usage: "build tag",
EnvVar: "DRONE_TAG",
},
cli.Float64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_JOB_STARTED",
},
cli.Float64Flag{
Name: "job.finished",
Usage: "job finished",
EnvVar: "DRONE_JOB_FINISHED",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
Name: "pull.request",
Usage: "pull request",
EnvVar: "DRONE_PULL_REQUEST",
},
cli.Int64Flag{
Name: "build.started",
Usage: "build started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.Int64Flag{
Name: "build.finished",
Usage: "build finished",
EnvVar: "DRONE_BUILD_FINISHED",
},
cli.BoolFlag{
Name: "github",
@@ -201,6 +215,11 @@ func main() {
Usage: "The GitHub workspace path. Value: /github/workspace.",
EnvVar: "GITHUB_WORKSPACE",
},
cli.StringFlag{
Name: "deploy.to",
Usage: "Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.",
EnvVar: "DRONE_DEPLOY_TO",
},
}
if err := app.Run(os.Args); err != nil {
@@ -209,10 +228,6 @@ func main() {
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
GitHub: GitHub{
Workflow: c.String("github.workflow"),
@@ -226,21 +241,26 @@ func run(c *cli.Context) error {
Namespace: c.String("repo.namespace"),
Name: c.String("repo.name"),
},
Commit: Commit{
Sha: c.String("commit.sha"),
Ref: c.String("commit.ref"),
Branch: c.String("commit.branch"),
Link: c.String("commit.link"),
Author: c.String("commit.author"),
Email: c.String("commit.author.email"),
Avatar: c.String("commit.author.avatar"),
Message: c.String("commit.message"),
},
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"),
RefSpec: c.String("commit.refspec"),
Branch: c.String("commit.branch"),
Author: c.String("commit.author"),
Email: c.String("commit.author.email"),
Avatar: c.String("commit.author.avatar"),
Message: c.String("commit.message"),
Link: c.String("build.link"),
Started: c.Float64("job.started"),
Finished: c.Float64("job.finished"),
Started: c.Int64("build.started"),
Finished: c.Int64("build.finished"),
PR: c.String("pull.request"),
DeployTo: c.String("deploy.to"),
},
Config: Config{
WebhookID: c.String("webhook-id"),
+18 -31
View File
@@ -9,11 +9,8 @@
steps: [
{
name: 'vet',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make vet',
],
@@ -26,11 +23,8 @@
},
{
name: 'lint',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make lint',
],
@@ -43,11 +37,8 @@
},
{
name: 'misspell',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make misspell-check',
],
@@ -60,10 +51,9 @@
},
{
name: 'test',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
GO111MODULE: 'on',
WEBHOOK_ID: { 'from_secret': 'webhook_id' },
WEBHOOK_TOKEN: { 'from_secret': 'webhook_token' },
},
@@ -105,11 +95,10 @@
steps: [
{
name: 'build-push',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
@@ -122,11 +111,10 @@
},
{
name: 'build-tag',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags \'-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/' + name,
@@ -137,7 +125,7 @@
},
{
name: 'executable',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + ' --help',
@@ -202,11 +190,8 @@
steps: [
{
name: 'build-all-binary',
image: 'golang:1.11',
image: 'golang:1.16',
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'make release'
],
@@ -245,6 +230,16 @@
arch: arch,
},
steps: [
{
name: 'discord',
image: 'appleboy/drone-discord',
pull: 'always',
settings: {
webhook_id: { from_secret: 'webhook_id' },
webhook_token: { from_secret: 'webhook_token' },
message: '{{#success build.status}} Build #{{build.number}} of `{{repo.name}}` succeeded.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n🌐 {{ build.link }}\n\n duration: {{duration build.started build.finished}} \n\n started: {{datetime build.started "2006/01/02 15:04" "Asia/Taipei"}} \n\n finished: {{datetime build.finished "2006/01/02 15:04" "Asia/Taipei"}} {{else}} Build #{{build.number}} of `{{repo.name}}` failed.\n\n📝 Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.message}} ```\n🌐 {{ build.link }}\n\n duration: {{duration build.started build.finished}} \n\n started: {{datetime build.started "2006/01/02 15:04" "Asia/Taipei"}} \n\n finished: {{datetime build.finished "2006/01/02 15:04" "Asia/Taipei"}}{{/success}}\n',
},
},
{
name: 'manifest',
image: 'plugins/manifest',
@@ -256,14 +251,6 @@
ignore_missing: true,
},
},
{
name: 'microbadger',
image: 'plugins/webhook:1',
pull: 'always',
settings: {
url: { 'from_secret': 'microbadger_url' },
},
},
],
depends_on: depends_on,
trigger: {
+38 -23
View File
@@ -13,7 +13,7 @@ import (
"strconv"
"strings"
"github.com/appleboy/drone-facebook/template"
"github.com/appleboy/drone-template-lib/template"
)
const (
@@ -33,29 +33,36 @@ type (
EventPath string
}
// Repo information
// Repo information.
Repo struct {
FullName string
Namespace string
Name string
}
// Build information
// Commit information.
Commit struct {
Sha string
Ref string
Branch string
Link string
Author string
Avatar string
Email string
Message string
}
// Build information.
Build struct {
Tag string
Event string
Number int
Commit string
RefSpec string
Branch string
Author string
Avatar string
Message string
Email string
Status string
Link string
Started float64
Finished float64
Started int64
Finished int64
PR string
DeployTo string
}
// Config for the plugin.
@@ -116,10 +123,16 @@ type (
Build Build
Config Config
Payload Payload
Commit Commit
}
)
func templateMessage(t string, plugin Plugin) (string, error) {
return template.RenderTrim(t, plugin)
}
// Creates a new file upload http request with optional extra params
// https://matt.aimonetti.net/posts/2013/07/01/golang-multipart-file-upload-example/
func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
file, err := os.Open(path)
if err != nil {
@@ -165,7 +178,7 @@ func (p *Plugin) Exec() error {
if len(p.Config.Message) > 0 {
for _, m := range p.Config.Message {
txt, err := template.RenderTrim(m, p)
txt, err := templateMessage(m, *p)
if err != nil {
return err
}
@@ -191,6 +204,9 @@ func (p *Plugin) Exec() error {
}
for _, f := range p.Config.File {
if f == "" {
continue
}
err := p.SendFile(f)
if err != nil {
return err
@@ -243,7 +259,6 @@ func (p *Plugin) SendMessage() error {
return err
}
_, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
if err != nil {
return err
}
@@ -282,27 +297,27 @@ func (p *Plugin) Template() EmbedObject {
description := ""
switch p.Build.Event {
case "push":
description = fmt.Sprintf("%s pushed to %s", p.Build.Author, p.Build.Branch)
description = fmt.Sprintf("%s pushed to %s", p.Commit.Author, p.Commit.Branch)
case "pull_request":
branch := ""
if p.Build.RefSpec != "" {
branch = p.Build.RefSpec
if p.Commit.Ref != "" {
branch = p.Commit.Ref
} else {
branch = p.Build.Branch
branch = p.Commit.Branch
}
description = fmt.Sprintf("%s updated pull request %s", p.Build.Author, branch)
description = fmt.Sprintf("%s updated pull request %s", p.Commit.Author, branch)
case "tag":
description = fmt.Sprintf("%s pushed tag %s", p.Build.Author, p.Build.Branch)
description = fmt.Sprintf("%s pushed tag %s", p.Commit.Author, p.Commit.Branch)
}
return EmbedObject{
Title: p.Build.Message,
Title: p.Commit.Message,
Description: description,
URL: p.Build.Link,
Color: p.Color(),
Author: EmbedAuthorObject{
Name: p.Build.Author,
IconURL: p.Build.Avatar,
Name: p.Commit.Author,
IconURL: p.Commit.Avatar,
},
Footer: EmbedFooterObject{
Text: DroneDesc,
+11 -10
View File
@@ -22,17 +22,18 @@ func TestTemplate(t *testing.T) {
Name: "go-hello",
Namespace: "appleboy",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Commit: Commit{
Author: "appleboy",
Branch: "master",
Event: "tag",
Message: "update by drone discord plugin. \r\n update by drone discord plugin.",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
Avatar: "https://avatars0.githubusercontent.com/u/21979?v=3&s=100",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Event: "tag",
},
Config: Config{
WebhookID: os.Getenv("WEBHOOK_ID"),
@@ -69,7 +70,7 @@ func TestTemplate(t *testing.T) {
// send success embed message
plugin.Build.Status = "failure"
plugin.Build.Message = "send failure embed message"
plugin.Commit.Message = "send failure embed message"
plugin.Clear()
err = plugin.Exec()
assert.Nil(t, err)
@@ -77,14 +78,14 @@ func TestTemplate(t *testing.T) {
// send default embed message
plugin.Build.Status = "test"
plugin.Build.Message = "send default embed message"
plugin.Commit.Message = "send default embed message"
plugin.Clear()
err = plugin.Exec()
assert.Nil(t, err)
//change color for embed message
// change color for embed message
plugin.Config.Color = "#4842f4"
plugin.Build.Message = "Change embed color to #4842f4"
plugin.Commit.Message = "Change embed color to #4842f4"
plugin.Clear()
err = plugin.Exec()
assert.Nil(t, err)