mirror of
https://github.com/lddsb/drone-dingtalk-message.git
synced 2026-06-16 14:50:42 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c8a85bcc4 | |||
| ecf4f89e0a | |||
| e7ef2de488 | |||
| acd708ada3 |
@@ -28,8 +28,8 @@ jobs:
|
||||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
MINOR=${VERSION%.*}
|
||||
MAJOR=${MINOR%.*}
|
||||
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR}"
|
||||
TAGS="$TAGS,${GITHUB_IMAGE}:${VERSION},${GITHUB_IMAGE}:${MINOR},${GITHUB_IMAGE}:${MAJOR}"
|
||||
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
|
||||
TAGS="$TAGS,${GITHUB_IMAGE}:${VERSION},${GITHUB_IMAGE}:${MINOR},${GITHUB_IMAGE}:${MAJOR},${GITHUB_IMAGE}:latest"
|
||||
fi
|
||||
echo ::set-output name=tags::${TAGS}
|
||||
- name: Setup Docker Buildx
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
name: Publish release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: publish release, upload asset
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15.6
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.CR_PAT }}
|
||||
@@ -0,0 +1,49 @@
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
before:
|
||||
hooks:
|
||||
- go mod download
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
goarch:
|
||||
- 386
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
mod_timestamp: '{{ .CommitTimestamp }}'
|
||||
binary: dingtalk-message
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
|
||||
checksum:
|
||||
name_template: '{{ .ProjectName }}_checksums.txt'
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
- Merge pull request
|
||||
- Merge branch
|
||||
- go mod tidy
|
||||
archives:
|
||||
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
|
||||
replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- README.md
|
||||
- LICENSE
|
||||
- tpls/*
|
||||
+9
-2
@@ -2,6 +2,12 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.2.5] - 2020-12-16
|
||||
### Added:
|
||||
* The TPL can use environment variables.
|
||||
* Debug mode.
|
||||
* Use GitHub Actions for automation.
|
||||
|
||||
## [1.2.4] - 2020-04-28
|
||||
### Fixed:
|
||||
* kubernetes runner missing env, [details](https://docs.drone.io/runner/kubernetes/overview)
|
||||
@@ -20,7 +26,7 @@
|
||||
|
||||
## [1.2.0] - 2019-09-24
|
||||
### Added:
|
||||
* Support custom tpl.
|
||||
* Support custom TPL.
|
||||
|
||||
## [1.1.4] - 2020-04-28
|
||||
### Fixed:
|
||||
@@ -50,7 +56,8 @@
|
||||
### Added:
|
||||
* Auto publish image to DockerHub.
|
||||
|
||||
[Unreleased]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.4...HEAD
|
||||
[Unreleased]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.5...HEAD
|
||||
[1.2.5]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.4...v1.2.5
|
||||
[1.2.4]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.3...v1.2.4
|
||||
[1.2.3]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.2...v1.2.3
|
||||
[1.2.2]: https://github.com/lddsb/drone-dingtalk-message/compare/v1.2.1...v1.2.2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Drone CI DingTalk Message Plugin
|
||||
[](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
||||
[](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
||||
|
||||
[中文说明](README_ZH.md)
|
||||
|
||||
@@ -28,9 +28,6 @@ pipeline:
|
||||
|
||||
`1.x`
|
||||
```yaml
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
...
|
||||
- name: notification
|
||||
@@ -39,7 +36,7 @@ steps:
|
||||
token: your-groupbot-token
|
||||
type: markdown
|
||||
secret: your-secret-for-generate-sign
|
||||
|
||||
debug: true
|
||||
```
|
||||
|
||||
### Plugin Parameter Reference
|
||||
@@ -59,6 +56,9 @@ String. Secret for generate sign.
|
||||
|
||||
String. Your custom `tpl`, it can be a local path, or a remote http link.
|
||||
|
||||
`debug`
|
||||
Boolean. Debug mode.
|
||||
|
||||
`tips_title`
|
||||
|
||||
String. You can customize the title for the message tips, just work when message type is markdown.
|
||||
@@ -185,6 +185,9 @@ $ ./drone-dingtalk-message -h
|
||||
### Todo
|
||||
It's sad, just support `text`, `markdown` and `link` type now.
|
||||
- implement all message type
|
||||
- i18N
|
||||
- batch send
|
||||
- retry(e.g., network error, etc.)
|
||||
|
||||
### Kubernetes Users
|
||||
Attention kubernetes users, [CHANGELOG](CHANGELOG.md#124---2020-04-28).It's the available versions:
|
||||
|
||||
+11
-6
@@ -1,5 +1,6 @@
|
||||
# Drone CI的钉钉群组机器人通知插件
|
||||
[](https://hub.docker.com/r/lddsb/drone-dingtalk-message) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
||||
[](https://github.com/lddsb/drone-dingtalk-message/actions?query=workflow%3A%22Publish+to+DockerHub+and+Github+Package%22) [](https://goreportcard.com/report/github.com/lddsb/drone-dingtalk-message) [](https://codecov.io/gh/lddsb/drone-dingtalk-message) [](https://app.dependabot.com/accounts/lddsb/repos/159822771) [](LICENSE)
|
||||
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
@@ -28,9 +29,6 @@ pipeline:
|
||||
|
||||
`1.x`
|
||||
```yaml
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
...
|
||||
- name: notification
|
||||
@@ -39,7 +37,7 @@ steps:
|
||||
token: your-groupbot-token
|
||||
type: markdown
|
||||
secret: your-secret-for-generate-sign
|
||||
|
||||
debug: true
|
||||
```
|
||||
|
||||
### 插件参数
|
||||
@@ -59,6 +57,10 @@ steps:
|
||||
|
||||
你可以通过该字段来自定义你的消息模版。该字段可以是一个本地路径也可以是一个远程的URL。
|
||||
|
||||
`debug`
|
||||
|
||||
通过该值可以打开`debug`模式,打印所有环境变量。
|
||||
|
||||
`tips_title`
|
||||
|
||||
你可以通过该字段自定义钉钉机器人的消息通知提醒标题。(注意,不是消息内容的标题,是收到钉钉机器人发的消息后,会有一个外显的标题)
|
||||
@@ -186,10 +188,13 @@ $ ./drone-dingtalk-message -h
|
||||
### 未来计划
|
||||
目前仅支持 `text`, `markdown` 以及 `link` 类型的消息,建议使用`markdown`类型。
|
||||
- 实现更多的消息类型
|
||||
- i18N国际化直接翻译环境变量
|
||||
- 批量发送给多个群机器人
|
||||
- 失败重试机制
|
||||
|
||||
### Kubernetes 用户请注意
|
||||
因为`Drone CI` [官方缺陷](https://docs.drone.io/runner/kubernetes/overview) ,所以较早版本将无法正常获取到需要用到的变量,会导致部分功能异常。为了能正常使用,所以请使用以下版本:
|
||||
- `1.1`(总会是`1.1.x`的最新版本)
|
||||
- `>=1.1.4`
|
||||
- `1.2`(总会是`1.2.x`的最新版本)
|
||||
- `>=1.2.4`
|
||||
- `>=1.2.4`
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// Version of cli
|
||||
var Version = "0.2.1130"
|
||||
var Version = "0.2.1219"
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
@@ -29,7 +29,7 @@ func main() {
|
||||
app.Version = Version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "config.debug",
|
||||
Name: "config.debug,debug",
|
||||
Usage: "debug mode",
|
||||
EnvVar: "PLUGIN_DEBUG",
|
||||
},
|
||||
@@ -49,17 +49,17 @@ func main() {
|
||||
EnvVar: "PLUGIN_SECRET",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.message.type,message_type",
|
||||
Name: "config.message.type,message_type,type",
|
||||
Usage: "DingTalk message type, like text, markdown, action card, link and feed card...",
|
||||
EnvVar: "PLUGIN_MSG_TYPE,PLUGIN_TYPE,PLUGIN_MESSAGE_TYPE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.message.at.all",
|
||||
Name: "config.message.at.all,at.all",
|
||||
Usage: "at all in a message(only text and markdown type message can at)",
|
||||
EnvVar: "PLUGIN_MSG_AT_ALL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "config.message.at.mobiles",
|
||||
Name: "config.message.at.mobiles,mobiles",
|
||||
Usage: "at someone in a DingTalk group need this guy bind's mobile",
|
||||
EnvVar: "PLUGIN_MSG_AT_MOBILES",
|
||||
},
|
||||
@@ -134,6 +134,16 @@ func main() {
|
||||
Usage: "provider the owner of the repository",
|
||||
EnvVar: "DRONE_REPO_OWNER",
|
||||
},
|
||||
cli.Uint64Flag{
|
||||
Name: "stage.started",
|
||||
Usage: "stage started ",
|
||||
EnvVar: "DRONE_STAGE_STARTED",
|
||||
},
|
||||
cli.Uint64Flag{
|
||||
Name: "stage.finished",
|
||||
Usage: "stage finished",
|
||||
EnvVar: "DRONE_STAGE_FINISHED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
@@ -150,12 +160,12 @@ func main() {
|
||||
Usage: "build event",
|
||||
EnvVar: "DRONE_BUILD_EVENT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.Uint64Flag{
|
||||
Name: "build.started",
|
||||
Usage: "build started",
|
||||
EnvVar: "DRONE_BUILD_STARTED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.Uint64Flag{
|
||||
Name: "build.finished",
|
||||
Usage: "build finished",
|
||||
EnvVar: "DRONE_BUILD_FINISHED",
|
||||
@@ -191,7 +201,7 @@ func main() {
|
||||
EnvVar: "FAILURE_COLOR,PLUGIN_FAILURE_COLOR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "custom.tpl",
|
||||
Name: "custom.tpl,tpl",
|
||||
Usage: "custom tpl",
|
||||
EnvVar: "PLUGIN_TPL,PLUGIN_CUSTOM_TPL",
|
||||
},
|
||||
@@ -210,6 +220,16 @@ func main() {
|
||||
Usage: "tpl custom commit branch name",
|
||||
EnvVar: "PLUGIN_TPL_COMMIT_BRANCH_NAME,TPL_COMMIT_BRANCH_NAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "custom.started,started",
|
||||
Usage: "started custom env name, eg., BUILD_STARTED",
|
||||
EnvVar: "PLUGIN_CUSTOM_STARTED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "custom.finished,finished",
|
||||
Usage: "finished custom env name, eg., BUILD_FINISHED",
|
||||
EnvVar: "PLUGIN_CUSTOM_FINISHED",
|
||||
},
|
||||
}
|
||||
|
||||
// kubernetes runner patch
|
||||
@@ -239,8 +259,8 @@ func run(c *cli.Context) {
|
||||
Status: c.String("build.status"),
|
||||
Link: c.String("build.link"),
|
||||
Event: c.String("build.event"),
|
||||
StartAt: c.Int64("build.started"),
|
||||
FinishedAt: c.Int64("build.finished"),
|
||||
StartAt: c.Uint64("build.started"),
|
||||
FinishedAt: c.Uint64("build.finished"),
|
||||
},
|
||||
Commit: Commit{
|
||||
Sha: c.String("commit.sha"),
|
||||
@@ -254,6 +274,10 @@ func run(c *cli.Context) {
|
||||
Username: c.String("commit.author.username"),
|
||||
},
|
||||
},
|
||||
Stage: Stage{
|
||||
StartedAt: c.Uint64("stage.started"),
|
||||
FinishedAt: c.Uint64("stage.finished"),
|
||||
},
|
||||
},
|
||||
// custom config
|
||||
Config: Config{
|
||||
@@ -275,6 +299,10 @@ func run(c *cli.Context) {
|
||||
FailureColor: c.String("custom.color.failure"),
|
||||
},
|
||||
Tpl: c.String("custom.tpl"),
|
||||
Consuming: Consuming{
|
||||
StartedEnv: c.String("custom.started"),
|
||||
FinishedEnv: c.String("custom.finished"),
|
||||
},
|
||||
},
|
||||
Tpl: Tpl{
|
||||
Repo: TplRepo{
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
webhook "github.com/lddsb/dingtalk-webhook"
|
||||
@@ -29,8 +30,8 @@ type (
|
||||
Status string // providers the current build status
|
||||
Link string // providers the current build link
|
||||
Event string // trigger event
|
||||
StartAt int64 // build start at ( unix timestamp )
|
||||
FinishedAt int64 // build finish at ( unix timestamp )
|
||||
StartAt uint64 // build start at ( unix timestamp )
|
||||
FinishedAt uint64 // build finish at ( unix timestamp )
|
||||
}
|
||||
|
||||
// Commit commit info
|
||||
@@ -43,6 +44,12 @@ type (
|
||||
Author CommitAuthor
|
||||
}
|
||||
|
||||
// Stage drone stage env
|
||||
Stage struct {
|
||||
StartedAt uint64
|
||||
FinishedAt uint64
|
||||
}
|
||||
|
||||
// CommitAuthor commit author info
|
||||
CommitAuthor struct {
|
||||
Avatar string // providers the author avatar for the current commit
|
||||
@@ -56,6 +63,7 @@ type (
|
||||
Repo Repo
|
||||
Build Build
|
||||
Commit Commit
|
||||
Stage Stage
|
||||
}
|
||||
|
||||
// Config plugin private config
|
||||
@@ -104,35 +112,48 @@ type (
|
||||
Message MessageConfig
|
||||
}
|
||||
|
||||
// Custom user custom env
|
||||
Custom struct {
|
||||
Tpl string
|
||||
Color Color
|
||||
Pic Pic
|
||||
Tpl string
|
||||
Color Color
|
||||
Pic Pic
|
||||
Consuming Consuming
|
||||
}
|
||||
|
||||
// Tpl TPL base
|
||||
Tpl struct {
|
||||
Repo TplRepo
|
||||
Commit TplCommit
|
||||
Build TplBuild
|
||||
}
|
||||
|
||||
// TplRepo TPL repo
|
||||
TplRepo struct {
|
||||
FullName string
|
||||
ShortName string
|
||||
}
|
||||
|
||||
// TplCommit TPL commit
|
||||
TplCommit struct {
|
||||
Branch string
|
||||
}
|
||||
|
||||
// TplBuild TPL build
|
||||
TplBuild struct {
|
||||
Status Status
|
||||
}
|
||||
|
||||
// Status status
|
||||
Status struct {
|
||||
Success string
|
||||
Failure string
|
||||
}
|
||||
|
||||
// Consuming custom consuming env
|
||||
Consuming struct {
|
||||
StartedEnv string
|
||||
FinishedEnv string
|
||||
}
|
||||
)
|
||||
|
||||
// Exec execute WebHook
|
||||
@@ -289,7 +310,20 @@ func (p *Plugin) getEnvs() map[string]interface{} {
|
||||
envs["TPL_BUILD_STATUS"] = p.getStatus()
|
||||
envs["TPL_BUILD_LINK"] = p.Drone.Build.Link
|
||||
envs["TPL_BUILD_EVENT"] = p.Drone.Build.Event
|
||||
envs["TPL_BUILD_CONSUMING"] = fmt.Sprintf("%v", p.Drone.Build.FinishedAt-p.Drone.Build.StartAt)
|
||||
|
||||
var consuming uint64
|
||||
// custom consuming env
|
||||
if p.Custom.Consuming.FinishedEnv != "" && p.Custom.Consuming.StartedEnv != "" {
|
||||
finishedAt, _ := strconv.ParseUint(os.Getenv(p.Custom.Consuming.FinishedEnv), 10, 64)
|
||||
startedAt, _ := strconv.ParseUint(os.Getenv(p.Custom.Consuming.StartedEnv), 10, 64)
|
||||
consuming = finishedAt - startedAt
|
||||
} else {
|
||||
consuming = p.Drone.Build.FinishedAt - p.Drone.Build.StartAt
|
||||
if consuming == 0 {
|
||||
consuming = p.Drone.Stage.FinishedAt - p.Drone.Stage.StartedAt
|
||||
}
|
||||
}
|
||||
envs["TPL_BUILD_CONSUMING"] = fmt.Sprintf("%v", consuming)
|
||||
|
||||
envs["TPL_COMMIT_SHA"] = p.Drone.Commit.Sha
|
||||
envs["TPL_COMMIT_REF"] = p.Drone.Commit.Ref
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
### **[CI_PROJECT_TITLE]**'s **[CI_COMMIT_BRANCH]** build **[TPL_BUILD_STATUS]**
|
||||
|
||||
Message: [CI_COMMIT_MESSAGE]
|
||||
|
||||
Detail: [[CI_COMMIT_SHA]]([CI_PROJECT_URL]/commit/[CI_COMMIT_SHA])
|
||||
|
||||
Author: [[GITLAB_USER_NAME]([GITLAB_USER_EMAIL])](mailto:[GITLAB_USER_EMAIL])
|
||||
|
||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([CI_PIPELINE_URL])
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
### [TPL_REPO_SHORT_NAME] build [TPL_BUILD_STATUS] (`takes [TPL_BUILD_CONSUMING]s`)
|
||||
|
||||
[TPL_COMMIT_MSG]
|
||||
Message: [TPL_COMMIT_MSG]
|
||||
|
||||
[[TPL_COMMIT_SHA]]([TPL_COMMIT_LINK])
|
||||
Detail: [[TPL_COMMIT_SHA]]([TPL_COMMIT_LINK])
|
||||
|
||||
[[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
|
||||
Author: [[TPL_AUTHOR_NAME]([TPL_AUTHOR_EMAIL])](mailto:[TPL_AUTHOR_EMAIL])
|
||||
|
||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([TPL_BUILD_LINK])
|
||||
[Click To The Build Detail Page [TPL_STATUS_EMOTICON]]([TPL_BUILD_LINK])
|
||||
|
||||
Reference in New Issue
Block a user