mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-13 18:51:38 +08:00
Compare commits
104 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8533df8e0b | |||
| 217a6b17eb | |||
| a58131af2a | |||
| 3721fc313d | |||
| cea35a9ac9 | |||
| e80db3da6a | |||
| 6c782afaae | |||
| ffa230b880 | |||
| f2bd7836ef | |||
| 4d1d86d8c2 | |||
| 53d0f6ec67 | |||
| 91c0d241df | |||
| 223b0aa14f | |||
| 5e71b59c72 | |||
| 01518e5a92 | |||
| 7478381b56 | |||
| c96089116d | |||
| e17a1e9920 | |||
| 51f0b338c5 | |||
| 2e8d61dcf2 | |||
| d80fc1adb6 | |||
| 1b92a095c1 | |||
| 8a872ab32f | |||
| 17f7e18d78 | |||
| 59b6fbbaf2 | |||
| 2000a2e484 | |||
| 6dc40cfa7f | |||
| 7e5539d30c | |||
| 3f344cdf2e | |||
| 692f7ff6dd | |||
| 881339ea8f | |||
| af8276f8fa | |||
| 2586433815 | |||
| 69a9056c05 | |||
| 17058ff053 | |||
| 242a4e9588 | |||
| 4bb2c902ad | |||
| 22c00bf3c3 | |||
| f3724e17a2 | |||
| 9d765d231b | |||
| 26bd0641dc | |||
| cb38b0a194 | |||
| 5144ba01a7 | |||
| a1c6d30b44 | |||
| bf68bcb2b9 | |||
| 6d07c7dd06 | |||
| e282060e04 | |||
| f760d3a7a8 | |||
| 7ac022b650 | |||
| 2830e39260 | |||
| d4b1c86367 | |||
| e1e8532e04 | |||
| 52b70e4a89 | |||
| f6c3df01ff | |||
| 78124dd591 | |||
| 61e5d95ddb | |||
| a451d9e0a5 | |||
| 30be2b99d7 | |||
| 546c9b8541 | |||
| 48f22eab4a | |||
| 8567e2de7b | |||
| 5804cc4e37 | |||
| 026a8936a9 | |||
| fd5ccbeed3 | |||
| 28dea47a9c | |||
| cb122520bd | |||
| f677050f44 | |||
| f0a5083d6d | |||
| b2f5cf4ba4 | |||
| cfc2d80805 | |||
| 5607652dd4 | |||
| 1e6904c06b | |||
| e2b1b67069 | |||
| 11c87968e4 | |||
| a15636218c | |||
| b3140a539b | |||
| 4df8911cdf | |||
| 33e2805dd8 | |||
| 82e100bf9a | |||
| d7ec25b596 | |||
| 747ffca8cc | |||
| 83561d842b | |||
| 5eb8b48ec3 | |||
| fe2b53fab4 | |||
| 9fce8c8c6b | |||
| 1ab023c10d | |||
| cfd3725c9a | |||
| aecc652459 | |||
| 4ef98156ed | |||
| 7b0188f107 | |||
| 851c23f7fa | |||
| 8396f108b8 | |||
| a9f7dd6911 | |||
| 98665b9a28 | |||
| e67bb8f829 | |||
| ab201cc6f9 | |||
| fcf20615e8 | |||
| e88ca34689 | |||
| fc75470770 | |||
| 412a50abe1 | |||
| 187468f10b | |||
| d20387ae04 | |||
| 11fec702d5 | |||
| a474b187c6 |
@@ -1,16 +0,0 @@
|
||||
local pipeline = import 'pipeline.libsonnet';
|
||||
local name = 'drone-discord';
|
||||
|
||||
[
|
||||
pipeline.test,
|
||||
pipeline.build(name, 'linux', 'amd64'),
|
||||
pipeline.build(name, 'linux', 'arm64'),
|
||||
pipeline.build(name, 'linux', 'arm'),
|
||||
pipeline.release,
|
||||
pipeline.notifications(depends_on=[
|
||||
'linux-amd64',
|
||||
'linux-arm64',
|
||||
'linux-arm',
|
||||
'release-binary',
|
||||
]),
|
||||
]
|
||||
@@ -1,76 +0,0 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: windows-amd64
|
||||
|
||||
platform:
|
||||
os: windows
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/windows/amd64/drone-discord'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
GO111MODULE: on
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -o release/windows/amd64/drone-discord'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
GO111MODULE: on
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
- name: executable
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- ./release/windows/amd64/drone-discord --help
|
||||
|
||||
- name: dryrun
|
||||
pull: always
|
||||
image: plugins/docker:windows-amd64
|
||||
settings:
|
||||
dockerfile: docker/Dockerfile.windows.amd64
|
||||
dry_run: true
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: appleboy/drone-discord
|
||||
tags: windows-amd64
|
||||
username:
|
||||
from_secret: docker_username
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
- name: publish
|
||||
pull: always
|
||||
image: plugins/docker:windows-amd64
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: windows-amd64
|
||||
dockerfile: docker/Dockerfile.windows.amd64
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: appleboy/drone-discord
|
||||
username:
|
||||
from_secret: docker_username
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- master
|
||||
-390
@@ -1,390 +0,0 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: testing
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: vet
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- make vet
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: lint
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- make lint
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: misspell
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- make misspell-check
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: test
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- make test
|
||||
- make coverage
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
WEBHOOK_ID:
|
||||
from_secret: webhook_id
|
||||
WEBHOOK_TOKEN:
|
||||
from_secret: webhook_token
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: codecov
|
||||
pull: always
|
||||
image: robertstettner/drone-codecov
|
||||
settings:
|
||||
token:
|
||||
from_secret: codecov_token
|
||||
|
||||
volumes:
|
||||
- name: gopath
|
||||
temp: {}
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-amd64
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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
|
||||
commands:
|
||||
- ./release/linux/amd64/drone-discord --help
|
||||
|
||||
- name: dryrun
|
||||
pull: always
|
||||
image: plugins/docker:linux-amd64
|
||||
settings:
|
||||
cache_from: appleboy/drone-discord
|
||||
dockerfile: docker/Dockerfile.linux.amd64
|
||||
dry_run: true
|
||||
repo: appleboy/drone-discord
|
||||
tags: linux-amd64
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
- name: publish
|
||||
pull: always
|
||||
image: plugins/docker:linux-amd64
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-amd64
|
||||
cache_from: appleboy/drone-discord
|
||||
daemon_off: false
|
||||
dockerfile: docker/Dockerfile.linux.amd64
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: appleboy/drone-discord
|
||||
username:
|
||||
from_secret: docker_username
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-arm64
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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
|
||||
commands:
|
||||
- ./release/linux/arm64/drone-discord --help
|
||||
|
||||
- name: dryrun
|
||||
pull: always
|
||||
image: plugins/docker:linux-arm64
|
||||
settings:
|
||||
cache_from: appleboy/drone-discord
|
||||
dockerfile: docker/Dockerfile.linux.arm64
|
||||
dry_run: true
|
||||
repo: appleboy/drone-discord
|
||||
tags: linux-arm64
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
- name: publish
|
||||
pull: always
|
||||
image: plugins/docker:linux-arm64
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm64
|
||||
cache_from: appleboy/drone-discord
|
||||
daemon_off: false
|
||||
dockerfile: docker/Dockerfile.linux.arm64
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: appleboy/drone-discord
|
||||
username:
|
||||
from_secret: docker_username
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-arm
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- "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
|
||||
commands:
|
||||
- ./release/linux/arm/drone-discord --help
|
||||
|
||||
- name: dryrun
|
||||
pull: always
|
||||
image: plugins/docker:linux-arm
|
||||
settings:
|
||||
cache_from: appleboy/drone-discord
|
||||
dockerfile: docker/Dockerfile.linux.arm
|
||||
dry_run: true
|
||||
repo: appleboy/drone-discord
|
||||
tags: linux-arm
|
||||
when:
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
- name: publish
|
||||
pull: always
|
||||
image: plugins/docker:linux-arm
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm
|
||||
cache_from: appleboy/drone-discord
|
||||
daemon_off: false
|
||||
dockerfile: docker/Dockerfile.linux.arm
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: appleboy/drone-discord
|
||||
username:
|
||||
from_secret: docker_username
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/pull/**"
|
||||
- "refs/tags/**"
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: release-binary
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: build-all-binary
|
||||
pull: always
|
||||
image: golang:1.11
|
||||
commands:
|
||||
- make release
|
||||
environment:
|
||||
GO111MODULE: on
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
- name: deploy-all-binary
|
||||
pull: always
|
||||
image: plugins/github-release
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: github_release_api_key
|
||||
files:
|
||||
- "dist/release/*"
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- "refs/tags/**"
|
||||
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: notifications
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: manifest
|
||||
pull: always
|
||||
image: plugins/manifest
|
||||
settings:
|
||||
ignore_missing: true
|
||||
password:
|
||||
from_secret: docker_password
|
||||
spec: docker/manifest.tmpl
|
||||
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/**"
|
||||
|
||||
depends_on:
|
||||
- linux-amd64
|
||||
- linux-arm64
|
||||
- linux-arm
|
||||
- release-binary
|
||||
|
||||
...
|
||||
@@ -1,42 +0,0 @@
|
||||
# unifying the coding style for different editors and IDEs => editorconfig.org
|
||||
|
||||
; indicate this is the root of the project
|
||||
root = true
|
||||
|
||||
###########################################################
|
||||
; common
|
||||
###########################################################
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
|
||||
end_of_line = LF
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
###########################################################
|
||||
; make
|
||||
###########################################################
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
[makefile]
|
||||
indent_style = tab
|
||||
|
||||
###########################################################
|
||||
; markdown
|
||||
###########################################################
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
###########################################################
|
||||
; golang
|
||||
###########################################################
|
||||
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
@@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
custom: ["https://www.paypal.me/appleboy46"]
|
||||
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
- package-ecosystem: gomod
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
@@ -0,0 +1,54 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [master]
|
||||
schedule:
|
||||
- cron: "41 23 * * 6"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: ["go"]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
@@ -0,0 +1,70 @@
|
||||
name: Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- "v*"
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
build-docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "^1"
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Build binary
|
||||
run: |
|
||||
make build_linux_amd64
|
||||
make build_linux_arm64
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker meta
|
||||
id: docker-meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ github.repository }}
|
||||
ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: docker/Dockerfile
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.docker-meta.outputs.tags }}
|
||||
labels: ${{ steps.docker-meta.outputs.labels }}
|
||||
@@ -0,0 +1,32 @@
|
||||
name: Goreleaser
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "^1"
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,67 @@
|
||||
name: Lint and Testing
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "^1"
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup golangci-lint
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: latest
|
||||
args: --verbose
|
||||
|
||||
- uses: hadolint/hadolint-action@v3.1.0
|
||||
name: hadolint for Dockerfile
|
||||
with:
|
||||
dockerfile: docker/Dockerfile
|
||||
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
go: [1.23, 1.24]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
go-build: ~/.cache/go-build
|
||||
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
GO111MODULE: on
|
||||
GOPROXY: https://proxy.golang.org
|
||||
steps:
|
||||
- name: Set up Go ${{ matrix.go }}
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
${{ matrix.go-build }}
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- name: Run Tests
|
||||
run: |
|
||||
go test -v -covermode=atomic -coverprofile=coverage.out
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
flags: ${{ matrix.os }},go-${{ matrix.go }}
|
||||
@@ -18,3 +18,4 @@ drone-discord
|
||||
coverage.txt
|
||||
release/
|
||||
dist/
|
||||
bin/
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
run:
|
||||
timeout: 5m
|
||||
linters:
|
||||
enable:
|
||||
- asciicheck
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errorlint
|
||||
- gci
|
||||
- gofmt
|
||||
- goimports
|
||||
- gosec
|
||||
- misspell
|
||||
- nakedret
|
||||
- nilerr
|
||||
- nolintlint
|
||||
- perfsprint
|
||||
- revive
|
||||
- usestdlibvars
|
||||
- wastedassign
|
||||
|
||||
linters-settings:
|
||||
gosec:
|
||||
# To select a subset of rules to run.
|
||||
# Available rules: https://github.com/securego/gosec#available-rules
|
||||
# Default: [] - means include all rules
|
||||
includes:
|
||||
- G102
|
||||
- G106
|
||||
- G108
|
||||
- G109
|
||||
- G111
|
||||
- G112
|
||||
- G201
|
||||
- G203
|
||||
perfsprint:
|
||||
err-error: true
|
||||
errorf: true
|
||||
int-conversion: true
|
||||
sprintf1: true
|
||||
strconcat: true
|
||||
@@ -0,0 +1,123 @@
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- darwin
|
||||
- linux
|
||||
- windows
|
||||
- freebsd
|
||||
goarch:
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
goarm:
|
||||
- "5"
|
||||
- "6"
|
||||
- "7"
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: arm
|
||||
- goos: darwin
|
||||
goarch: ppc64le
|
||||
- goos: darwin
|
||||
goarch: s390x
|
||||
- goos: windows
|
||||
goarch: ppc64le
|
||||
- goos: windows
|
||||
goarch: s390x
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
goarm: "5"
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
goarm: "6"
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
goarm: "7"
|
||||
- goos: windows
|
||||
goarch: arm64
|
||||
- goos: freebsd
|
||||
goarch: ppc64le
|
||||
- goos: freebsd
|
||||
goarch: s390x
|
||||
- goos: freebsd
|
||||
goarch: arm
|
||||
goarm: "5"
|
||||
- goos: freebsd
|
||||
goarch: arm
|
||||
goarm: "6"
|
||||
- goos: freebsd
|
||||
goarch: arm
|
||||
goarm: "7"
|
||||
- goos: freebsd
|
||||
goarch: arm64
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X main.Version={{.Version}}
|
||||
binary: >-
|
||||
{{ .ProjectName }}-
|
||||
{{- if .IsSnapshot }}{{ .Branch }}-
|
||||
{{- else }}{{- .Version }}-{{ end }}
|
||||
{{- .Os }}-
|
||||
{{- if eq .Arch "amd64" }}amd64
|
||||
{{- else if eq .Arch "amd64_v1" }}amd64
|
||||
{{- else if eq .Arch "386" }}386
|
||||
{{- else }}{{ .Arch }}{{ end }}
|
||||
{{- if .Arm }}-{{ .Arm }}{{ end }}
|
||||
no_unique_dist_dir: true
|
||||
hooks:
|
||||
post:
|
||||
- cmd: xz -k -9 {{ .Path }}
|
||||
dir: ./dist/
|
||||
|
||||
archives:
|
||||
- format: binary
|
||||
name_template: "{{ .Binary }}"
|
||||
allow_different_binary_count: true
|
||||
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
extra_files:
|
||||
- glob: ./**.xz
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ incpatch .Version }}"
|
||||
|
||||
release:
|
||||
# You can add extra pre-existing files to the release.
|
||||
# The filename on the release will be the last part of the path (base).
|
||||
# If another file with the same name exists, the last one found will be used.
|
||||
#
|
||||
# Templates: allowed
|
||||
extra_files:
|
||||
- glob: ./**.xz
|
||||
|
||||
changelog:
|
||||
use: github
|
||||
groups:
|
||||
- title: Features
|
||||
regexp: "^.*feat[(\\w)]*:+.*$"
|
||||
order: 0
|
||||
- title: "Bug fixes"
|
||||
regexp: "^.*fix[(\\w)]*:+.*$"
|
||||
order: 1
|
||||
- title: "Enhancements"
|
||||
regexp: "^.*chore[(\\w)]*:+.*$"
|
||||
order: 2
|
||||
- title: "Refactor"
|
||||
regexp: "^.*refactor[(\\w)]*:+.*$"
|
||||
order: 3
|
||||
- title: "Build process updates"
|
||||
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
|
||||
order: 4
|
||||
- title: "Documentation updates"
|
||||
regexp: ^.*?docs?(\(.+\))??!?:.+$
|
||||
order: 4
|
||||
- title: Others
|
||||
order: 999
|
||||
@@ -0,0 +1,3 @@
|
||||
ignored:
|
||||
- DL3018
|
||||
- DL3008
|
||||
@@ -1,25 +0,0 @@
|
||||
ignoreGeneratedHeader = false
|
||||
severity = "warning"
|
||||
confidence = 0.8
|
||||
errorCode = 1
|
||||
warningCode = 1
|
||||
|
||||
[rule.blank-imports]
|
||||
[rule.context-as-argument]
|
||||
[rule.context-keys-type]
|
||||
[rule.dot-imports]
|
||||
[rule.error-return]
|
||||
[rule.error-strings]
|
||||
[rule.error-naming]
|
||||
[rule.exported]
|
||||
[rule.if-return]
|
||||
[rule.increment-decrement]
|
||||
[rule.var-naming]
|
||||
[rule.var-declaration]
|
||||
[rule.package-comments]
|
||||
[rule.range]
|
||||
[rule.receiver-naming]
|
||||
[rule.time-naming]
|
||||
[rule.unexported-return]
|
||||
[rule.indent-error-flow]
|
||||
[rule.errorf]
|
||||
@@ -1,21 +1,33 @@
|
||||
---
|
||||
date: 2017-06-10T00:00:00+00:00
|
||||
title: Discord
|
||||
name: Discord
|
||||
description: Send message to Discord channel using Webhook
|
||||
author: appleboy
|
||||
tags: [ notifications, chat ]
|
||||
repo: appleboy/drone-discord
|
||||
logo: discord.svg
|
||||
icon: https://raw.githubusercontent.com/appleboy/drone-discord/master/images/discord-mark-blue.svg
|
||||
image: appleboy/drone-discord
|
||||
containerImage: appleboy/drone-discord
|
||||
containerImageUrl: https://hub.docker.com/r/appleboy/drone-discord
|
||||
url: https://github.com/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 +35,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 +105,7 @@ discord_webhook_id
|
||||
discord_webhook_token
|
||||
: discord webhook token
|
||||
|
||||
# Parameter Reference
|
||||
## Parameter Reference
|
||||
|
||||
webhook_id
|
||||
: webhook id
|
||||
@@ -112,7 +125,7 @@ tts
|
||||
message
|
||||
: the message contents (up to 2000 characters)
|
||||
|
||||
# Template Reference
|
||||
## Template Reference
|
||||
|
||||
repo.owner
|
||||
: repository owner
|
||||
@@ -156,7 +169,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
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
DIST := dist
|
||||
EXECUTABLE := drone-discord
|
||||
GOFMT ?= gofmt "-s"
|
||||
GOFMT ?= gofumpt -l -s -w
|
||||
GO ?= go
|
||||
|
||||
# for dockerhub
|
||||
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)'
|
||||
TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'tempdir')
|
||||
GOFILES := $(shell find . -name "*.go" -type f)
|
||||
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||
|
||||
ifneq ($(shell uname), Darwin)
|
||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||
@@ -20,109 +11,77 @@ else
|
||||
EXTLDFLAGS =
|
||||
endif
|
||||
|
||||
ifeq ($(HAS_GO), GO)
|
||||
GOPATH ?= $(shell $(GO) env GOPATH)
|
||||
export PATH := $(GOPATH)/bin:$(PATH)
|
||||
|
||||
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
|
||||
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(OS), Windows_NT)
|
||||
GOFLAGS := -v -buildmode=exe
|
||||
EXECUTABLE ?= $(EXECUTABLE).exe
|
||||
else ifeq ($(OS), Windows)
|
||||
GOFLAGS := -v -buildmode=exe
|
||||
EXECUTABLE ?= $(EXECUTABLE).exe
|
||||
else
|
||||
GOFLAGS := -v
|
||||
EXECUTABLE ?= $(EXECUTABLE)
|
||||
endif
|
||||
|
||||
ifneq ($(DRONE_TAG),)
|
||||
VERSION ?= $(DRONE_TAG)
|
||||
else
|
||||
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
||||
endif
|
||||
|
||||
TAGS ?=
|
||||
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
||||
|
||||
all: build
|
||||
|
||||
fmt:
|
||||
$(GOFMT) -w $(SOURCES)
|
||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) install mvdan.cc/gofumpt; \
|
||||
fi
|
||||
$(GOFMT) -w $(GOFILES)
|
||||
|
||||
vet:
|
||||
$(GO) vet $(PACKAGES)
|
||||
|
||||
lint:
|
||||
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) get -u github.com/mgechev/revive; \
|
||||
fi
|
||||
revive -config .revive.toml ./... || exit 1
|
||||
|
||||
.PHONY: misspell-check
|
||||
misspell-check:
|
||||
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
||||
fi
|
||||
misspell -error $(SOURCES)
|
||||
|
||||
.PHONY: misspell
|
||||
misspell:
|
||||
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
||||
fi
|
||||
misspell -w $(SOURCES)
|
||||
$(GO) vet ./...
|
||||
|
||||
.PHONY: fmt-check
|
||||
fmt-check:
|
||||
@diff=$$($(GOFMT) -d $(SOURCES)); \
|
||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
$(GO) install mvdan.cc/gofumpt; \
|
||||
fi
|
||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||
if [ -n "$$diff" ]; then \
|
||||
echo "Please run 'make fmt' and commit the result:"; \
|
||||
echo "$${diff}"; \
|
||||
exit 1; \
|
||||
fi;
|
||||
|
||||
test: fmt-check
|
||||
@$(GO) test -v -cover -coverprofile coverage.txt $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||
test:
|
||||
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||
|
||||
install: $(SOURCES)
|
||||
install: $(GOFILES)
|
||||
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
||||
|
||||
build: $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(SOURCES)
|
||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
||||
|
||||
release: release-dirs release-build release-copy release-check
|
||||
|
||||
release-dirs:
|
||||
mkdir -p $(DIST)/binaries $(DIST)/release
|
||||
|
||||
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}}"
|
||||
|
||||
release-copy:
|
||||
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
|
||||
|
||||
release-check:
|
||||
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
||||
$(EXECUTABLE): $(GOFILES)
|
||||
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
||||
|
||||
build_linux_amd64:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
||||
|
||||
build_linux_i386:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
|
||||
|
||||
build_linux_arm64:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
|
||||
|
||||
build_linux_arm:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
|
||||
|
||||
docker_image:
|
||||
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
|
||||
|
||||
docker: docker_image
|
||||
|
||||
docker_deploy:
|
||||
ifeq ($(tag),)
|
||||
@echo "Usage: make $@ tag=<tag>"
|
||||
@exit 1
|
||||
endif
|
||||
# deploy image
|
||||
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
||||
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
||||
|
||||
coverage:
|
||||
sed -i '/main.go/d' coverage.txt
|
||||
|
||||
clean:
|
||||
$(GO) clean -x -i ./...
|
||||
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
||||
rm -rf coverage.txt $(EXECUTABLE)
|
||||
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
|
||||
@@ -1,80 +1,55 @@
|
||||
<img src="images/discord-logo.png">
|
||||
|
||||
# drone-[discord](https://discordapp.com)
|
||||
|
||||
Drone plugin for sending message to Discord channel using Webhook.
|
||||

|
||||
|
||||
[Drone](https://www.drone.io/) / [Woodpecker](https://woodpecker-ci.org/) plugin for sending messages to Discord channels using Webhooks.
|
||||
|
||||
[](https://godoc.org/github.com/appleboy/drone-discord)
|
||||
[](https://cloud.drone.io/appleboy/drone-discord)
|
||||
[](https://codecov.io/gh/appleboy/drone-discord)
|
||||
[](https://goreportcard.com/report/github.com/appleboy/drone-discord)
|
||||
[](https://hub.docker.com/r/appleboy/drone-discord/)
|
||||
[](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/).
|
||||
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 documentation](https://discordapp.com/developers/docs/resources/webhook). For usage information and a list of available options, please refer to [the documentation](http://plugins.drone.io/appleboy/drone-discord/).
|
||||
|
||||
Sending discord message using a binary, docker or [Drone CI](http://docs.drone.io/).
|
||||
Send Discord messages using a binary, Docker, or [Drone CI](http://docs.drone.io/).
|
||||
|
||||
## Features
|
||||
|
||||
* [x] Send Multiple Messages
|
||||
* [x] Send Multiple Files
|
||||
- [x] Send Multiple Messages
|
||||
- [x] Send Multiple Files
|
||||
|
||||
## Build or Download a binary
|
||||
|
||||
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-discord/releases). Support the following OS type.
|
||||
The pre-compiled binaries can be downloaded from the [release page](https://github.com/appleboy/drone-discord/releases). The following OS types are supported:
|
||||
|
||||
* Windows amd64/386
|
||||
* Linux arm/amd64/386
|
||||
* Darwin amd64/386
|
||||
- Windows amd64/386
|
||||
- Linux arm/amd64/386
|
||||
- Darwin amd64/386
|
||||
|
||||
With `Go` installed
|
||||
With `Go` installed:
|
||||
|
||||
```
|
||||
$ 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
|
||||
|
||||
$ go test -cover ./...
|
||||
|
||||
$ go build -v -a -tags netgo -o release/linux/amd64/drone-discord .
|
||||
```sh
|
||||
go get -u -v github.com/appleboy/drone-discord
|
||||
```
|
||||
|
||||
## Docker
|
||||
Or build the binary with the following command:
|
||||
|
||||
Build the docker image with the following commands:
|
||||
```sh
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
export CGO_ENABLED=0
|
||||
export GO111MODULE=on
|
||||
|
||||
```
|
||||
$ make docker
|
||||
```
|
||||
go test -cover ./...
|
||||
|
||||
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.
|
||||
There are three ways to send notifications:
|
||||
|
||||
* [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
|
||||
### Usage from Binary
|
||||
|
||||
```bash
|
||||
drone-discord \
|
||||
@@ -83,10 +58,7 @@ drone-discord \
|
||||
--message "Test Message"
|
||||
```
|
||||
|
||||
<a name="usage-from-docker"></a>
|
||||
### Usage from docker
|
||||
|
||||
#### Send Notification
|
||||
### Usage from Docker
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
@@ -100,14 +72,13 @@ docker run --rm \
|
||||
appleboy/drone-discord
|
||||
```
|
||||
|
||||
<a name="usage-from-drone-ci"></a>
|
||||
### Usage from drone ci
|
||||
### Usage from Drone CI
|
||||
|
||||
#### Send Notification
|
||||
|
||||
Execute from the working directory:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
docker run --rm \
|
||||
-e WEBHOOK_ID=xxxxxxx \
|
||||
-e WEBHOOK_TOKEN=xxxxxxx \
|
||||
@@ -133,12 +104,35 @@ docker run --rm \
|
||||
appleboy/drone-discord
|
||||
```
|
||||
|
||||
You can get more [information](DOCS.md) about how to use this plugin in drone.
|
||||
## Declarative Environment Config Usage
|
||||
|
||||
You can get more [information](DOCS.md) about how to use this plugin in Drone.
|
||||
|
||||
```yml
|
||||
- name: msg status
|
||||
image: appleboy/drone-discord
|
||||
settings:
|
||||
webhook_id:
|
||||
from_secret: discord_id
|
||||
webhook_token:
|
||||
from_secret: discord_token
|
||||
message: "{{#success build.status}}✅{{else}}❌{{/success}} Repository `[{{repo.name}}/{{commit.branch}}]` triggered by event `[{{uppercase build.event}}]` for build.\n - Commit [[{{commit.sha}}]({{commit.link}})]\n - Author `[{{commit.author}} / {{commit.email}}]`\n - Message: {{commit.message}} - Drone build [[#{{build.number}}]({{build.link}})] reported `[{{uppercase build.status}}]` at `[{{datetime build.finished \"2006.01.02 15:04\" \"\"}}]`\n"
|
||||
when:
|
||||
status: [success, failure, changed]
|
||||
```
|
||||
|
||||
```yml
|
||||
- name: multi line msg status
|
||||
...
|
||||
message: >
|
||||
Line one
|
||||
Line two
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Test the package with the following command:
|
||||
|
||||
```
|
||||
$ make test
|
||||
```sh
|
||||
make test
|
||||
```
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
//
|
||||
// Details about the drone-discord project are found in github page:
|
||||
//
|
||||
// https://github.com/appleboy/drone-discord
|
||||
// https://github.com/appleboy/drone-discord
|
||||
//
|
||||
// The pre-compiled binaries can be downloaded from release page.
|
||||
//
|
||||
// Send Notification
|
||||
//
|
||||
// drone-discord \
|
||||
// --webhook-id xxxx \
|
||||
// --webhook-token xxxx \
|
||||
// --username value \
|
||||
// --avatar-url value \
|
||||
// --message "Test Message"
|
||||
// drone-discord \
|
||||
// --webhook-id xxxx \
|
||||
// --webhook-token xxxx \
|
||||
// --username value \
|
||||
// --avatar-url value \
|
||||
// --message "Test Message"
|
||||
//
|
||||
// For more details, see the documentation and example.
|
||||
//
|
||||
package main
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
FROM alpine:3.21
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
||||
org.label-schema.name="Drone Discord Plugin" \
|
||||
org.label-schema.vendor="Bo-Yi Wu" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-discord
|
||||
LABEL org.opencontainers.image.description="Drone Discord"
|
||||
LABEL org.opencontainers.image.licenses=MIT
|
||||
|
||||
RUN apk add --no-cache ca-certificates && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
COPY release/${TARGETOS}/${TARGETARCH}/drone-discord /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-discord"]
|
||||
@@ -1,10 +0,0 @@
|
||||
FROM plugins/base:linux-amd64
|
||||
|
||||
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/linux/amd64/drone-discord /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-discord"]
|
||||
@@ -1,10 +0,0 @@
|
||||
FROM plugins/base:linux-arm
|
||||
|
||||
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/linux/arm/drone-discord /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-discord"]
|
||||
@@ -1,10 +0,0 @@
|
||||
FROM plugins/base:linux-arm64
|
||||
|
||||
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/linux/arm64/drone-discord /bin/
|
||||
|
||||
ENTRYPOINT ["/bin/drone-discord"]
|
||||
@@ -1,9 +0,0 @@
|
||||
FROM plugins/base:windows-amd64
|
||||
|
||||
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" ]
|
||||
@@ -1,25 +0,0 @@
|
||||
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}{{else}}latest{{/if}}
|
||||
{{#if build.tags}}
|
||||
tags:
|
||||
{{#each build.tags}}
|
||||
- {{this}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
manifests:
|
||||
-
|
||||
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: linux
|
||||
-
|
||||
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm64
|
||||
platform:
|
||||
architecture: arm64
|
||||
os: linux
|
||||
variant: v8
|
||||
-
|
||||
image: appleboy/drone-discord:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm
|
||||
platform:
|
||||
architecture: arm
|
||||
os: linux
|
||||
variant: v7
|
||||
@@ -1,12 +1,33 @@
|
||||
module github.com/appleboy/drone-discord
|
||||
|
||||
go 1.23.0
|
||||
|
||||
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.3.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/urfave/cli/v2 v2.27.6
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.2.1 // indirect
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/huandu/xstrings v1.5.0 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
github.com/mailgun/raymond/v2 v2.0.48 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.4.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
golang.org/x/crypto v0.36.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,18 +1,109 @@
|
||||
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/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
|
||||
github.com/appleboy/drone-template-lib v1.3.0 h1:aX36/1za3v8JsEyBeMY1Bp/VNRtZa8qPYkfkjBszW+A=
|
||||
github.com/appleboy/drone-template-lib v1.3.0/go.mod h1:edlmXkFMKYAVypff8r2oN7aFlHfOZE5sLyPEnRHONeA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
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/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
|
||||
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
|
||||
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mailgun/raymond/v2 v2.0.48 h1:5dmlB680ZkFG2RN/0lvTAghrSxIESeu9/2aeDqACtjw=
|
||||
github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNfj4KA0W54Z18=
|
||||
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||
github.com/mitchellh/reflectwalk v1.0.2/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/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
||||
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
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.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g=
|
||||
github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/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-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127.14 96.36"><path fill="#5865f2" d="M107.7,8.07A105.15,105.15,0,0,0,81.47,0a72.06,72.06,0,0,0-3.36,6.83A97.68,97.68,0,0,0,49,6.83,72.37,72.37,0,0,0,45.64,0,105.89,105.89,0,0,0,19.39,8.09C2.79,32.65-1.71,56.6.54,80.21h0A105.73,105.73,0,0,0,32.71,96.36,77.7,77.7,0,0,0,39.6,85.25a68.42,68.42,0,0,1-10.85-5.18c.91-.66,1.8-1.34,2.66-2a75.57,75.57,0,0,0,64.32,0c.87.71,1.76,1.39,2.66,2a68.68,68.68,0,0,1-10.87,5.19,77,77,0,0,0,6.89,11.1A105.25,105.25,0,0,0,126.6,80.22h0C129.24,52.84,122.09,29.11,107.7,8.07ZM42.45,65.69C36.18,65.69,31,60,31,53s5-12.74,11.43-12.74S54,46,53.89,53,48.84,65.69,42.45,65.69Zm42.24,0C78.41,65.69,73.25,60,73.25,53s5-12.74,11.44-12.74S96.23,46,96.12,53,91.08,65.69,84.69,65.69Z"/></svg>
|
||||
|
After Width: | Height: | Size: 764 B |
@@ -1,26 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version set at compile-time
|
||||
var Version string
|
||||
|
||||
func main() {
|
||||
year := fmt.Sprintf("%v", time.Now().Year())
|
||||
// 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")
|
||||
}
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "Drone Discord"
|
||||
app.Usage = "Sending message to Discord channel using Webhook"
|
||||
app.Copyright = "Copyright (c) " + year + " Bo-Yi Wu"
|
||||
app.Authors = []cli.Author{
|
||||
app.Copyright = "Copyright (c) " + strconv.Itoa(time.Now().Year()) + " Bo-Yi Wu"
|
||||
app.Authors = []*cli.Author{
|
||||
{
|
||||
Name: "Bo-Yi Wu",
|
||||
Email: "appleboy.tw@gmail.com",
|
||||
@@ -29,177 +36,204 @@ func main() {
|
||||
app.Action = run
|
||||
app.Version = Version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "webhook-id",
|
||||
Usage: "discord webhook id",
|
||||
EnvVar: "PLUGIN_WEBHOOK_ID,WEBHOOK_ID,DISCORD_WEBHOOK_ID",
|
||||
&cli.StringFlag{
|
||||
Name: "webhook-url",
|
||||
Usage: "The Discord webhook URL to send messages to.",
|
||||
EnvVars: []string{"PLUGIN_WEBHOOK_URL", "WEBHOOK_URL", "DISCORD_WEBHOOK_URL", "INPUT_WEBHOOK_URL"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "webhook-token",
|
||||
Usage: "discord webhook token",
|
||||
EnvVar: "PLUGIN_WEBHOOK_TOKEN,WEBHOOK_TOKEN,DISCORD_WEBHOOK_TOKEN",
|
||||
&cli.StringFlag{
|
||||
Name: "webhook-id",
|
||||
Usage: "The Discord webhook ID.",
|
||||
EnvVars: []string{"PLUGIN_WEBHOOK_ID", "WEBHOOK_ID", "DISCORD_WEBHOOK_ID", "INPUT_WEBHOOK_ID"},
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "message",
|
||||
Usage: "the message contents (up to 2000 characters)",
|
||||
EnvVar: "PLUGIN_MESSAGE,DISCORD_MESSAGE,MESSAGE",
|
||||
&cli.StringFlag{
|
||||
Name: "webhook-token",
|
||||
Usage: "The Discord webhook token.",
|
||||
EnvVars: []string{"PLUGIN_WEBHOOK_TOKEN", "WEBHOOK_TOKEN", "DISCORD_WEBHOOK_TOKEN", "INPUT_WEBHOOK_TOKEN"},
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "file",
|
||||
Usage: "the contents of the file being sent",
|
||||
EnvVar: "PLUGIN_FILE,DISCORD_FILE,FILE",
|
||||
&cli.StringSliceFlag{
|
||||
Name: "message",
|
||||
Usage: "The message contents to send to the Discord channel (up to 2000 characters).",
|
||||
EnvVars: []string{"PLUGIN_MESSAGE", "DISCORD_MESSAGE", "MESSAGE", "INPUT_MESSAGE"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "color",
|
||||
Usage: "color code of the embed",
|
||||
EnvVar: "PLUGIN_COLOR,COLOR",
|
||||
&cli.StringSliceFlag{
|
||||
Name: "file",
|
||||
Usage: "The contents of the file being sent to the Discord channel.",
|
||||
EnvVars: []string{"PLUGIN_FILE", "DISCORD_FILE", "FILE", "INPUT_FILE"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "wait",
|
||||
Usage: "waits for server confirmation of message send before response, and returns the created message body",
|
||||
EnvVar: "PLUGIN_WAIT,WAIT",
|
||||
&cli.StringFlag{
|
||||
Name: "color",
|
||||
Usage: "The color code of the embed message.",
|
||||
EnvVars: []string{"PLUGIN_COLOR", "COLOR", "INPUT_COLOR"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "tts",
|
||||
Usage: "true if this is a TTS message",
|
||||
EnvVar: "PLUGIN_TTS,TTS",
|
||||
&cli.BoolFlag{
|
||||
Name: "wait",
|
||||
Usage: "Wait for server confirmation of message send before response, and return the created message body.",
|
||||
EnvVars: []string{"PLUGIN_WAIT", "WAIT", "INPUT_WAIT"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "override the default username of the webhook",
|
||||
EnvVar: "PLUGIN_USERNAME,USERNAME",
|
||||
&cli.BoolFlag{
|
||||
Name: "tts",
|
||||
Usage: "Set to true if this is a Text-to-Speech (TTS) message.",
|
||||
EnvVars: []string{"PLUGIN_TTS", "TTS", "INPUT_TTS"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "avatar-url",
|
||||
Usage: "override the default avatar of the webhook",
|
||||
EnvVar: "PLUGIN_AVATAR_URL,AVATAR_URL",
|
||||
&cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "Override the default username of the webhook.",
|
||||
EnvVars: []string{"PLUGIN_USERNAME", "USERNAME", "INPUT_USERNAME"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "drone",
|
||||
Usage: "environment is drone",
|
||||
EnvVar: "DRONE",
|
||||
&cli.StringFlag{
|
||||
Name: "avatar-url",
|
||||
Usage: "Override the default avatar of the webhook.",
|
||||
EnvVars: []string{"PLUGIN_AVATAR_URL", "AVATAR_URL", "INPUT_AVATAR_URL"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo",
|
||||
Usage: "repository owner and repository name",
|
||||
EnvVar: "DRONE_REPO,GITHUB_REPOSITORY",
|
||||
&cli.BoolFlag{
|
||||
Name: "drone",
|
||||
Usage: "Indicate if the environment is Drone CI.",
|
||||
EnvVars: []string{"DRONE"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.namespace",
|
||||
Usage: "repository namespace",
|
||||
EnvVar: "DRONE_REPO_OWNER,DRONE_REPO_NAMESPACE,GITHUB_ACTOR",
|
||||
&cli.StringFlag{
|
||||
Name: "ci.environment",
|
||||
Usage: "The name of the CI environment.",
|
||||
EnvVars: []string{"CI"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repository name",
|
||||
EnvVar: "DRONE_REPO_NAME",
|
||||
&cli.StringFlag{
|
||||
Name: "repo",
|
||||
Usage: "The repository owner and repository name.",
|
||||
EnvVars: []string{"DRONE_REPO", "CI_REPO", "GITHUB_REPOSITORY"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "git commit sha",
|
||||
EnvVar: "DRONE_COMMIT_SHA,GITHUB_SHA",
|
||||
&cli.StringFlag{
|
||||
Name: "repo.namespace",
|
||||
Usage: "The repository namespace.",
|
||||
EnvVars: []string{"DRONE_REPO_OWNER", "DRONE_REPO_NAMESPACE", "CI_REPO_OWNER", "GITHUB_ACTOR"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.ref",
|
||||
Usage: "git commit ref",
|
||||
EnvVar: "DRONE_COMMIT_REF,GITHUB_REF",
|
||||
&cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "The repository name.",
|
||||
EnvVars: []string{"DRONE_REPO_NAME", "CI_REPO_NAME"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "git commit branch",
|
||||
EnvVar: "DRONE_COMMIT_BRANCH",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "The Git commit SHA.",
|
||||
EnvVars: []string{"DRONE_COMMIT_SHA", "CI_COMMIT_SHA", "GITHUB_SHA"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "git author name",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.ref",
|
||||
Usage: "The Git commit reference.",
|
||||
EnvVars: []string{"DRONE_COMMIT_REF", "CI_COMMIT_REF", "GITHUB_REF"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author.email",
|
||||
Usage: "git author email",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR_EMAIL",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "The Git commit branch.",
|
||||
EnvVars: []string{"DRONE_COMMIT_BRANCH", "CI_COMMIT_BRANCH"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author.avatar",
|
||||
Usage: "git author avatar",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR_AVATAR",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.link",
|
||||
Usage: "The link to the Git commit.",
|
||||
EnvVars: []string{"DRONE_COMMIT_LINK", "CI_PIPELINE_FORGE_URL"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVar: "DRONE_COMMIT_MESSAGE",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "The name of the Git commit author.",
|
||||
EnvVars: []string{"DRONE_COMMIT_AUTHOR", "CI_COMMIT_AUTHOR"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "build event",
|
||||
EnvVar: "DRONE_BUILD_EVENT",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author.email",
|
||||
Usage: "The email of the Git commit author.",
|
||||
EnvVars: []string{"DRONE_COMMIT_AUTHOR_EMAIL", "CI_COMMIT_AUTHOR_EMAIL"},
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "build number",
|
||||
EnvVar: "DRONE_BUILD_NUMBER",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author.avatar",
|
||||
Usage: "The avatar URL of the Git commit author.",
|
||||
EnvVars: []string{"DRONE_COMMIT_AUTHOR_AVATAR", "CI_COMMIT_AUTHOR_AVATAR"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
Value: "success",
|
||||
EnvVar: "DRONE_BUILD_STATUS",
|
||||
&cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "The Git commit message.",
|
||||
EnvVars: []string{"DRONE_COMMIT_MESSAGE", "CI_COMMIT_MESSAGE"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "build link",
|
||||
EnvVar: "DRONE_BUILD_LINK",
|
||||
&cli.StringFlag{
|
||||
Name: "source.branch",
|
||||
Value: "develop",
|
||||
Usage: "The Git source branch.",
|
||||
EnvVars: []string{"DRONE_SOURCE_BRANCH", "CI_COMMIT_SOURCE_BRANCH"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.tag",
|
||||
Usage: "build tag",
|
||||
EnvVar: "DRONE_TAG",
|
||||
&cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "The build event type.",
|
||||
EnvVars: []string{"DRONE_BUILD_EVENT", "CI_PIPELINE_EVENT"},
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "job.started",
|
||||
Usage: "job started",
|
||||
EnvVar: "DRONE_JOB_STARTED",
|
||||
&cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "The build number.",
|
||||
EnvVars: []string{"DRONE_BUILD_NUMBER", "CI_PIPELINE_NUMBER"},
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "job.finished",
|
||||
Usage: "job finished",
|
||||
EnvVar: "DRONE_JOB_FINISHED",
|
||||
&cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "The build status.",
|
||||
Value: "success",
|
||||
EnvVars: []string{"DRONE_BUILD_STATUS", "CI_PIPELINE_STATUS"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "env-file",
|
||||
Usage: "source env file",
|
||||
&cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "The link to the build.",
|
||||
EnvVars: []string{"DRONE_BUILD_LINK", "CI_PIPELINE_URL"},
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "github",
|
||||
Usage: "Boolean value, indicates the runtime environment is GitHub Action.",
|
||||
EnvVar: "PLUGIN_GITHUB,GITHUB",
|
||||
&cli.StringFlag{
|
||||
Name: "build.tag",
|
||||
Usage: "The build tag.",
|
||||
EnvVars: []string{"DRONE_TAG", "CI_COMMIT_TAG"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "github.workflow",
|
||||
Usage: "The name of the workflow.",
|
||||
EnvVar: "GITHUB_WORKFLOW",
|
||||
&cli.StringFlag{
|
||||
Name: "pull.request",
|
||||
Usage: "The pull request number.",
|
||||
EnvVars: []string{"DRONE_PULL_REQUEST", "CI_COMMIT_PULL_REQUEST"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "github.action",
|
||||
Usage: "The name of the action.",
|
||||
EnvVar: "GITHUB_ACTION",
|
||||
&cli.Int64Flag{
|
||||
Name: "build.started",
|
||||
Usage: "The timestamp when the build started.",
|
||||
EnvVars: []string{"DRONE_BUILD_STARTED", "CI_PIPELINE_STARTED"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "github.event.name",
|
||||
Usage: "The webhook name of the event that triggered the workflow.",
|
||||
EnvVar: "GITHUB_EVENT_NAME",
|
||||
&cli.Int64Flag{
|
||||
Name: "build.finished",
|
||||
Usage: "The timestamp when the build finished.",
|
||||
EnvVars: []string{"DRONE_BUILD_FINISHED", "CI_PIPELINE_FINISHED"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "github.event.path",
|
||||
Usage: "The path to a file that contains the payload of the event that triggered the workflow. Value: /github/workflow/event.json.",
|
||||
EnvVar: "GITHUB_EVENT_PATH",
|
||||
&cli.BoolFlag{
|
||||
Name: "github",
|
||||
Usage: "Indicate if the runtime environment is GitHub Actions.",
|
||||
EnvVars: []string{"PLUGIN_GITHUB", "GITHUB"},
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "github.workspace",
|
||||
Usage: "The GitHub workspace path. Value: /github/workspace.",
|
||||
EnvVar: "GITHUB_WORKSPACE",
|
||||
&cli.StringFlag{
|
||||
Name: "github.workflow",
|
||||
Usage: "The name of the GitHub Actions workflow.",
|
||||
EnvVars: []string{"GITHUB_WORKFLOW"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "github.action",
|
||||
Usage: "The name of the GitHub Actions action.",
|
||||
EnvVars: []string{"GITHUB_ACTION"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "github.event.name",
|
||||
Usage: "The name of the GitHub event that triggered the workflow.",
|
||||
EnvVars: []string{"GITHUB_EVENT_NAME"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "github.event.path",
|
||||
Usage: "The path to the file containing the payload of the event that triggered the workflow. Default: /github/workflow/event.json",
|
||||
EnvVars: []string{"GITHUB_EVENT_PATH"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "github.workspace",
|
||||
Usage: "The GitHub workspace path. Default: /github/workspace",
|
||||
EnvVars: []string{"GITHUB_WORKSPACE"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "deploy.to",
|
||||
Usage: "The target deployment environment for the running build. This value is only available to promotion and rollback pipelines.",
|
||||
EnvVars: []string{"DRONE_DEPLOY_TO", "CI_PIPELINE_DEPLOY_TARGET"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -209,10 +243,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,29 +256,38 @@ 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"),
|
||||
},
|
||||
Source: Source{
|
||||
Branch: c.String("source.branch"),
|
||||
},
|
||||
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{
|
||||
webhookURL: c.String("webhook-url"),
|
||||
WebhookID: c.String("webhook-id"),
|
||||
WebhookToken: c.String("webhook-token"),
|
||||
Message: c.StringSlice("message"),
|
||||
File: c.StringSlice("file"),
|
||||
Color: c.String("color"),
|
||||
Drone: c.Bool("drone"),
|
||||
Drone: c.Bool("drone") || c.String("ci.environment") == "woodpecker",
|
||||
GitHub: c.Bool("github"),
|
||||
},
|
||||
Payload: Payload{
|
||||
@@ -259,5 +298,5 @@ func run(c *cli.Context) error {
|
||||
},
|
||||
}
|
||||
|
||||
return plugin.Exec()
|
||||
return plugin.Exec(c.Context)
|
||||
}
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
{
|
||||
test:: {
|
||||
kind: 'pipeline',
|
||||
name: 'testing',
|
||||
platform: {
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'vet',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make vet',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'lint',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make lint',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'misspell',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make misspell-check',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'test',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
WEBHOOK_ID: { 'from_secret': 'webhook_id' },
|
||||
WEBHOOK_TOKEN: { 'from_secret': 'webhook_token' },
|
||||
},
|
||||
commands: [
|
||||
'make test',
|
||||
'make coverage',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'codecov',
|
||||
image: 'robertstettner/drone-codecov',
|
||||
pull: 'always',
|
||||
settings: {
|
||||
token: { 'from_secret': 'codecov_token' },
|
||||
},
|
||||
},
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
temp: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
build(name, os='linux', arch='amd64'):: {
|
||||
kind: 'pipeline',
|
||||
name: os + '-' + arch,
|
||||
platform: {
|
||||
os: os,
|
||||
arch: arch,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'build-push',
|
||||
image: 'golang:1.11',
|
||||
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,
|
||||
],
|
||||
when: {
|
||||
event: {
|
||||
exclude: [ 'tag' ],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'build-tag',
|
||||
image: 'golang:1.11',
|
||||
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,
|
||||
],
|
||||
when: {
|
||||
event: [ 'tag' ],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'executable',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
commands: [
|
||||
'./release/' + os + '/' + arch + '/' + name + ' --help',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'dryrun',
|
||||
image: 'plugins/docker:' + os + '-' + arch,
|
||||
pull: 'always',
|
||||
settings: {
|
||||
daemon_off: false,
|
||||
dry_run: true,
|
||||
tags: os + '-' + arch,
|
||||
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
|
||||
repo: 'appleboy/' + name,
|
||||
cache_from: 'appleboy/' + name,
|
||||
},
|
||||
when: {
|
||||
event: [ 'pull_request' ],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'publish',
|
||||
image: 'plugins/docker:' + os + '-' + arch,
|
||||
pull: 'always',
|
||||
settings: {
|
||||
daemon_off: 'false',
|
||||
auto_tag: true,
|
||||
auto_tag_suffix: os + '-' + arch,
|
||||
dockerfile: 'docker/Dockerfile.' + os + '.' + arch,
|
||||
repo: 'appleboy/' + name,
|
||||
cache_from: 'appleboy/' + name,
|
||||
username: { 'from_secret': 'docker_username' },
|
||||
password: { 'from_secret': 'docker_password' },
|
||||
},
|
||||
when: {
|
||||
event: {
|
||||
exclude: [ 'pull_request' ],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: [
|
||||
'testing',
|
||||
],
|
||||
trigger: {
|
||||
ref: [
|
||||
'refs/heads/master',
|
||||
'refs/pull/**',
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
release:: {
|
||||
kind: 'pipeline',
|
||||
name: 'release-binary',
|
||||
platform: {
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'build-all-binary',
|
||||
image: 'golang:1.11',
|
||||
pull: 'always',
|
||||
environment: {
|
||||
GO111MODULE: 'on',
|
||||
},
|
||||
commands: [
|
||||
'make release'
|
||||
],
|
||||
when: {
|
||||
event: [ 'tag' ],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'deploy-all-binary',
|
||||
image: 'plugins/github-release',
|
||||
pull: 'always',
|
||||
settings: {
|
||||
files: [ 'dist/release/*' ],
|
||||
api_key: { 'from_secret': 'github_release_api_key' },
|
||||
},
|
||||
when: {
|
||||
event: [ 'tag' ],
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: [
|
||||
'testing',
|
||||
],
|
||||
trigger: {
|
||||
ref: [
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
notifications(os='linux', arch='amd64', depends_on=[]):: {
|
||||
kind: 'pipeline',
|
||||
name: 'notifications',
|
||||
platform: {
|
||||
os: os,
|
||||
arch: arch,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'manifest',
|
||||
image: 'plugins/manifest',
|
||||
pull: 'always',
|
||||
settings: {
|
||||
username: { from_secret: 'docker_username' },
|
||||
password: { from_secret: 'docker_password' },
|
||||
spec: 'docker/manifest.tmpl',
|
||||
ignore_missing: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'microbadger',
|
||||
image: 'plugins/webhook:1',
|
||||
pull: 'always',
|
||||
settings: {
|
||||
url: { 'from_secret': 'microbadger_url' },
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: depends_on,
|
||||
trigger: {
|
||||
ref: [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
signature(key):: {
|
||||
kind: 'signature',
|
||||
hmac: key,
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,20 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/appleboy/drone-facebook/template"
|
||||
"github.com/appleboy/drone-template-lib/template"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,33 +35,45 @@ 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
|
||||
}
|
||||
|
||||
Source struct {
|
||||
Branch 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.
|
||||
Config struct {
|
||||
webhookURL string
|
||||
WebhookID string
|
||||
WebhookToken string
|
||||
Color string
|
||||
@@ -103,7 +117,7 @@ type (
|
||||
Payload struct {
|
||||
Wait bool `json:"wait"`
|
||||
Content string `json:"content"`
|
||||
Username string `json:"username"`
|
||||
Username string `json:"username,omitempty"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
TTS bool `json:"tts"`
|
||||
Embeds []EmbedObject `json:"embeds"`
|
||||
@@ -114,16 +128,56 @@ type (
|
||||
GitHub GitHub
|
||||
Repo Repo
|
||||
Build Build
|
||||
Source Source
|
||||
Config Config
|
||||
Payload Payload
|
||||
Commit Commit
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Config) validate() error {
|
||||
var missingFields []string
|
||||
|
||||
if c.webhookURL != "" {
|
||||
_, err := url.Parse(c.webhookURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid webhook url: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if c.webhookURL == "" {
|
||||
if c.WebhookID == "" {
|
||||
missingFields = append(missingFields, "WebhookID")
|
||||
}
|
||||
if c.WebhookToken == "" {
|
||||
missingFields = append(missingFields, "WebhookToken")
|
||||
}
|
||||
}
|
||||
|
||||
if len(missingFields) > 0 {
|
||||
return fmt.Errorf("missing discord config: %s", strings.Join(missingFields, ", "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get WebhookURL
|
||||
func (c *Config) GetWebhookURL() string {
|
||||
if c.webhookURL != "" {
|
||||
return c.webhookURL
|
||||
}
|
||||
return fmt.Sprintf("https://discord.com/api/webhooks/%s/%s", c.WebhookID, c.WebhookToken)
|
||||
}
|
||||
|
||||
func templateMessage(t string, plugin Plugin) (string, error) {
|
||||
return template.RenderTrim(t, plugin)
|
||||
}
|
||||
|
||||
// Creates a new file upload http request with optional extra params
|
||||
func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
|
||||
// https://matt.aimonetti.net/posts/2013/07/01/golang-multipart-file-upload-example/
|
||||
func fileUploadRequest(ctx context.Context, uri string, params map[string]string, paramName, path string) (*http.Request, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
@@ -131,33 +185,38 @@ func newfileUploadRequest(uri string, params map[string]string, paramName, path
|
||||
writer := multipart.NewWriter(body)
|
||||
part, err := writer.CreateFormFile(paramName, filepath.Base(path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to create form file: %w", err)
|
||||
}
|
||||
if _, err = io.Copy(part, file); err != nil {
|
||||
return nil, fmt.Errorf("failed to copy file content: %w", err)
|
||||
}
|
||||
_, err = io.Copy(part, file)
|
||||
|
||||
for key, val := range params {
|
||||
_ = writer.WriteField(key, val)
|
||||
if err = writer.WriteField(key, val); err != nil {
|
||||
return nil, fmt.Errorf("failed to write field %s: %w", key, err)
|
||||
}
|
||||
}
|
||||
err = writer.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err = writer.Close(); err != nil {
|
||||
return nil, fmt.Errorf("failed to close writer: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", uri, body)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create new request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
return req, err
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// Exec executes the plugin.
|
||||
func (p *Plugin) Exec() error {
|
||||
if p.Config.WebhookID == "" || p.Config.WebhookToken == "" {
|
||||
return errors.New("missing discord config")
|
||||
func (p *Plugin) Exec(ctx context.Context) error {
|
||||
if err := p.Config.validate(); err != nil {
|
||||
return fmt.Errorf("failed to validate config: %w", err)
|
||||
}
|
||||
|
||||
if len(p.Config.Message) == 0 {
|
||||
object := p.Template()
|
||||
p.Payload.Embeds = []EmbedObject{object}
|
||||
err := p.SendMessage()
|
||||
err := p.SendMessage(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -165,7 +224,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
|
||||
}
|
||||
@@ -175,7 +234,7 @@ func (p *Plugin) Exec() error {
|
||||
p.Payload.Embeds = append(p.Payload.Embeds, object)
|
||||
} else {
|
||||
p.Payload.Content = txt
|
||||
err = p.SendMessage()
|
||||
err = p.SendMessage(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -183,7 +242,7 @@ func (p *Plugin) Exec() error {
|
||||
}
|
||||
|
||||
if len(p.Payload.Embeds) > 0 {
|
||||
err := p.SendMessage()
|
||||
err := p.SendMessage(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -191,7 +250,10 @@ func (p *Plugin) Exec() error {
|
||||
}
|
||||
|
||||
for _, f := range p.Config.File {
|
||||
err := p.SendFile(f)
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
err := p.SendFile(ctx, f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -201,8 +263,8 @@ func (p *Plugin) Exec() error {
|
||||
}
|
||||
|
||||
// SendFile upload file to discord
|
||||
func (p *Plugin) SendFile(file string) error {
|
||||
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", p.Config.WebhookID, p.Config.WebhookToken)
|
||||
func (p *Plugin) SendFile(ctx context.Context, file string) error {
|
||||
webhookURL := p.Config.GetWebhookURL()
|
||||
extraParams := map[string]string{}
|
||||
|
||||
if p.Payload.Username != "" {
|
||||
@@ -217,7 +279,8 @@ func (p *Plugin) SendFile(file string) error {
|
||||
extraParams["tts"] = "true"
|
||||
}
|
||||
|
||||
request, err := newfileUploadRequest(
|
||||
request, err := fileUploadRequest(
|
||||
ctx,
|
||||
webhookURL,
|
||||
extraParams,
|
||||
"file",
|
||||
@@ -236,17 +299,31 @@ func (p *Plugin) SendFile(file string) error {
|
||||
}
|
||||
|
||||
// SendMessage to send discord message.
|
||||
func (p *Plugin) SendMessage() error {
|
||||
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", p.Config.WebhookID, p.Config.WebhookToken)
|
||||
func (p *Plugin) SendMessage(ctx context.Context) error {
|
||||
webhookURL := p.Config.GetWebhookURL()
|
||||
b := new(bytes.Buffer)
|
||||
if err := json.NewEncoder(b).Encode(p.Payload); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, webhookURL, b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusNoContent {
|
||||
return fmt.Errorf("failed to send message, status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -261,48 +338,35 @@ func (p *Plugin) DefaultTemplate(title string) EmbedObject {
|
||||
|
||||
// Template is plugin default template for Drone CI or GitHub Action.
|
||||
func (p *Plugin) Template() EmbedObject {
|
||||
if p.Config.GitHub {
|
||||
message := fmt.Sprintf("%s/%s triggered by %s (%s)",
|
||||
var description string
|
||||
switch {
|
||||
case p.Config.GitHub:
|
||||
description = fmt.Sprintf("%s/%s triggered by %s (%s)",
|
||||
p.Repo.FullName,
|
||||
p.GitHub.Workflow,
|
||||
p.Repo.Namespace,
|
||||
p.GitHub.EventName,
|
||||
)
|
||||
|
||||
return EmbedObject{
|
||||
Title: message,
|
||||
Color: p.Color(),
|
||||
Footer: EmbedFooterObject{
|
||||
Text: DroneDesc,
|
||||
IconURL: DroneIconURL,
|
||||
},
|
||||
case p.Build.Event == "push":
|
||||
description = fmt.Sprintf("%s pushed to %s", p.Commit.Author, p.Commit.Branch)
|
||||
case p.Build.Event == "pull_request":
|
||||
branch := p.Commit.Ref
|
||||
if branch == "" {
|
||||
branch = p.Commit.Branch
|
||||
}
|
||||
}
|
||||
|
||||
description := ""
|
||||
switch p.Build.Event {
|
||||
case "push":
|
||||
description = fmt.Sprintf("%s pushed to %s", p.Build.Author, p.Build.Branch)
|
||||
case "pull_request":
|
||||
branch := ""
|
||||
if p.Build.RefSpec != "" {
|
||||
branch = p.Build.RefSpec
|
||||
} else {
|
||||
branch = p.Build.Branch
|
||||
}
|
||||
description = fmt.Sprintf("%s updated pull request %s", p.Build.Author, branch)
|
||||
case "tag":
|
||||
description = fmt.Sprintf("%s pushed tag %s", p.Build.Author, p.Build.Branch)
|
||||
description = fmt.Sprintf("%s updated pull request %s", p.Commit.Author, branch)
|
||||
case p.Build.Event == "tag":
|
||||
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,
|
||||
|
||||
+24
-19
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
func TestMissingConfig(t *testing.T) {
|
||||
var plugin Plugin
|
||||
|
||||
err := plugin.Exec()
|
||||
err := plugin.Exec(context.Background())
|
||||
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
@@ -22,17 +23,21 @@ 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",
|
||||
},
|
||||
Source: Source{
|
||||
Branch: "feature/awesome-feature",
|
||||
},
|
||||
|
||||
Config: Config{
|
||||
WebhookID: os.Getenv("WEBHOOK_ID"),
|
||||
@@ -49,14 +54,14 @@ func TestTemplate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := plugin.Exec()
|
||||
err := plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
|
||||
plugin.Clear()
|
||||
plugin.Config.Message = []string{"I am appleboy"}
|
||||
plugin.Payload.TTS = true
|
||||
plugin.Payload.Wait = true
|
||||
err = plugin.Exec()
|
||||
err = plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
|
||||
// send success embed message
|
||||
@@ -64,29 +69,29 @@ func TestTemplate(t *testing.T) {
|
||||
plugin.Payload.TTS = false
|
||||
plugin.Payload.Wait = false
|
||||
plugin.Clear()
|
||||
err = plugin.Exec()
|
||||
err = plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
|
||||
// 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()
|
||||
err = plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// 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()
|
||||
err = plugin.Exec(context.Background())
|
||||
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()
|
||||
err = plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -108,12 +113,12 @@ func TestDefaultTemplate(t *testing.T) {
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
plugin.Clear()
|
||||
err := plugin.Exec()
|
||||
err := plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
|
||||
plugin.Config.Color = "#f4be41"
|
||||
time.Sleep(1 * time.Second)
|
||||
plugin.Clear()
|
||||
err = plugin.Exec()
|
||||
err = plugin.Exec(context.Background())
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user