mirror of
https://github.com/thegeeklab/drone-matrix.git
synced 2024-11-21 18:10:39 +00:00
Use the drone plugin lib
This commit is contained in:
parent
41199afa3c
commit
230d10feae
342
.drone.star
Normal file
342
.drone.star
Normal file
@ -0,0 +1,342 @@
|
||||
def main(ctx):
|
||||
before = testing(ctx)
|
||||
|
||||
stages = [
|
||||
linux(ctx, "amd64"),
|
||||
linux(ctx, "arm64"),
|
||||
linux(ctx, "arm"),
|
||||
windows(ctx, "1909"),
|
||||
windows(ctx, "1903"),
|
||||
windows(ctx, "1809"),
|
||||
]
|
||||
|
||||
after = manifest(ctx) + gitter(ctx)
|
||||
|
||||
for b in before:
|
||||
for s in stages:
|
||||
s["depends_on"].append(b["name"])
|
||||
|
||||
for s in stages:
|
||||
for a in after:
|
||||
a["depends_on"].append(s["name"])
|
||||
|
||||
return before + stages + after
|
||||
|
||||
def testing(ctx):
|
||||
return [{
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "testing",
|
||||
"platform": {
|
||||
"os": "linux",
|
||||
"arch": "amd64",
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"name": "staticcheck",
|
||||
"image": "golang:1.15",
|
||||
"pull": "always",
|
||||
"commands": [
|
||||
"go run honnef.co/go/tools/cmd/staticcheck ./...",
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "gopath",
|
||||
"path": "/go",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "lint",
|
||||
"image": "golang:1.15",
|
||||
"commands": [
|
||||
"go run golang.org/x/lint/golint -set_exit_status ./...",
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "gopath",
|
||||
"path": "/go",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "vet",
|
||||
"image": "golang:1.15",
|
||||
"commands": [
|
||||
"go vet ./...",
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "gopath",
|
||||
"path": "/go",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "test",
|
||||
"image": "golang:1.15",
|
||||
"commands": [
|
||||
"go test -cover ./...",
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "gopath",
|
||||
"path": "/go",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "gopath",
|
||||
"temp": {},
|
||||
},
|
||||
],
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
"refs/tags/**",
|
||||
"refs/pull/**",
|
||||
],
|
||||
},
|
||||
}]
|
||||
|
||||
def linux(ctx, arch):
|
||||
if ctx.build.event == "tag":
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-matrix ./cmd/drone-matrix' % (ctx.build.ref.replace("refs/tags/v", ""), arch),
|
||||
]
|
||||
else:
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-matrix ./cmd/drone-matrix' % (ctx.build.commit[0:8], arch),
|
||||
]
|
||||
|
||||
steps = [
|
||||
{
|
||||
"name": "environment",
|
||||
"image": "golang:1.15",
|
||||
"pull": "always",
|
||||
"environment": {
|
||||
"CGO_ENABLED": "0",
|
||||
},
|
||||
"commands": [
|
||||
"go version",
|
||||
"go env",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "build",
|
||||
"image": "golang:1.15",
|
||||
"environment": {
|
||||
"CGO_ENABLED": "0",
|
||||
},
|
||||
"commands": build,
|
||||
},
|
||||
{
|
||||
"name": "executable",
|
||||
"image": "golang:1.15",
|
||||
"commands": [
|
||||
"./release/linux/%s/drone-matrix --help" % (arch),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
if ctx.build.event != "pull_request":
|
||||
steps.append({
|
||||
"name": "docker",
|
||||
"image": "plugins/docker",
|
||||
"settings": {
|
||||
"dockerfile": "docker/Dockerfile.linux.%s" % (arch),
|
||||
"repo": "plugins/matrix",
|
||||
"username": {
|
||||
"from_secret": "docker_username",
|
||||
},
|
||||
"password": {
|
||||
"from_secret": "docker_password",
|
||||
},
|
||||
"auto_tag": True,
|
||||
"auto_tag_suffix": "linux-%s" % (arch),
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "linux-%s" % (arch),
|
||||
"platform": {
|
||||
"os": "linux",
|
||||
"arch": arch,
|
||||
},
|
||||
"steps": steps,
|
||||
"depends_on": [],
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
"refs/tags/**",
|
||||
"refs/pull/**",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
def windows(ctx, version):
|
||||
docker = [
|
||||
"echo $env:PASSWORD | docker login --username $env:USERNAME --password-stdin",
|
||||
]
|
||||
|
||||
if ctx.build.event == "tag":
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-matrix.exe ./cmd/drone-matrix' % (ctx.build.ref.replace("refs/tags/v", "")),
|
||||
]
|
||||
|
||||
docker = docker + [
|
||||
"docker build --pull -f docker/Dockerfile.windows.%s -t plugins/matrix:%s-windows-%s-amd64 ." % (version, ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
"docker run --rm plugins/matrix:%s-windows-%s-amd64 --help" % (ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
"docker push plugins/matrix:%s-windows-%s-amd64" % (ctx.build.ref.replace("refs/tags/v", ""), version),
|
||||
]
|
||||
else:
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-matrix.exe ./cmd/drone-matrix' % (ctx.build.commit[0:8]),
|
||||
]
|
||||
|
||||
docker = docker + [
|
||||
"docker build --pull -f docker/Dockerfile.windows.%s -t plugins/matrix:windows-%s-amd64 ." % (version, version),
|
||||
"docker run --rm plugins/matrix:windows-%s-amd64 --help" % (version),
|
||||
"docker push plugins/matrix:windows-%s-amd64" % (version),
|
||||
]
|
||||
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"type": "ssh",
|
||||
"name": "windows-%s" % (version),
|
||||
"platform": {
|
||||
"os": "windows",
|
||||
},
|
||||
"server": {
|
||||
"host": {
|
||||
"from_secret": "windows_server_%s" % (version),
|
||||
},
|
||||
"user": {
|
||||
"from_secret": "windows_username",
|
||||
},
|
||||
"password": {
|
||||
"from_secret": "windows_password",
|
||||
},
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"name": "environment",
|
||||
"environment": {
|
||||
"CGO_ENABLED": "0",
|
||||
},
|
||||
"commands": [
|
||||
"go version",
|
||||
"go env",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "build",
|
||||
"environment": {
|
||||
"CGO_ENABLED": "0",
|
||||
},
|
||||
"commands": build,
|
||||
},
|
||||
{
|
||||
"name": "executable",
|
||||
"commands": [
|
||||
"./release/windows/amd64/drone-matrix.exe --help",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "docker",
|
||||
"environment": {
|
||||
"USERNAME": {
|
||||
"from_secret": "docker_username",
|
||||
},
|
||||
"PASSWORD": {
|
||||
"from_secret": "docker_password",
|
||||
},
|
||||
},
|
||||
"commands": docker,
|
||||
},
|
||||
],
|
||||
"depends_on": [],
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
"refs/tags/**",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
def manifest(ctx):
|
||||
return [{
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "manifest",
|
||||
"steps": [
|
||||
{
|
||||
"name": "manifest",
|
||||
"image": "plugins/manifest",
|
||||
"settings": {
|
||||
"auto_tag": "true",
|
||||
"username": {
|
||||
"from_secret": "docker_username",
|
||||
},
|
||||
"password": {
|
||||
"from_secret": "docker_password",
|
||||
},
|
||||
"spec": "docker/manifest.tmpl",
|
||||
"ignore_missing": "true",
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "microbadger",
|
||||
"image": "plugins/webhook",
|
||||
"settings": {
|
||||
"urls": {
|
||||
"from_secret": "microbadger_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
"depends_on": [],
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
"refs/tags/**",
|
||||
],
|
||||
},
|
||||
}]
|
||||
|
||||
def gitter(ctx):
|
||||
return [{
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "gitter",
|
||||
"clone": {
|
||||
"disable": True,
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"name": "gitter",
|
||||
"image": "plugins/gitter",
|
||||
"settings": {
|
||||
"webhook": {
|
||||
"from_secret": "gitter_webhook",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
"depends_on": [
|
||||
"manifest",
|
||||
],
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
"refs/tags/**",
|
||||
],
|
||||
"status": [
|
||||
"failure",
|
||||
],
|
||||
},
|
||||
}]
|
6
.github/settings.yml
vendored
6
.github/settings.yml
vendored
@ -69,5 +69,9 @@ branches:
|
||||
- continuous-integration/drone/pr
|
||||
enforce_admins: false
|
||||
restrictions:
|
||||
apps:
|
||||
- renovate
|
||||
users: []
|
||||
teams: []
|
||||
teams:
|
||||
- Admins
|
||||
- Maintainers
|
||||
|
31
.gitignore
vendored
31
.gitignore
vendored
@ -1,30 +1,5 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
release/
|
||||
vendor/
|
||||
/release/
|
||||
/drone-matrix*
|
||||
|
||||
coverage.out
|
||||
drone-matrix
|
||||
.drone.yml
|
||||
|
1
LICENSE
1
LICENSE
@ -199,4 +199,3 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
61
cmd/drone-matrix/config.go
Normal file
61
cmd/drone-matrix/config.go
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-matrix/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "username for authentication",
|
||||
EnvVars: []string{"PLUGIN_USERNAME", "MATRIX_USERNAME"},
|
||||
Destination: &settings.Username,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "password for authentication",
|
||||
EnvVars: []string{"PLUGIN_PASSWORD", "MATRIX_PASSWORD"},
|
||||
Destination: &settings.Password,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "userid",
|
||||
Usage: "userid for authentication",
|
||||
EnvVars: []string{"PLUGIN_USERID,PLUGIN_USER_ID", "MATRIX_USERID", "MATRIX_USER_ID"},
|
||||
Destination: &settings.UserID,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "accesstoken",
|
||||
Usage: "accesstoken for authentication",
|
||||
EnvVars: []string{"PLUGIN_ACCESSTOKEN,PLUGIN_ACCESS_TOKEN", "MATRIX_ACCESSTOKEN", "MATRIX_ACCESS_TOKEN"},
|
||||
Destination: &settings.AccessToken,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "homeserver",
|
||||
Usage: "matrix home server",
|
||||
EnvVars: []string{"PLUGIN_HOMESERVER", "MATRIX_HOMESERVER"},
|
||||
Value: "https://matrix.org",
|
||||
Destination: &settings.Homeserver,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "roomid",
|
||||
Usage: "roomid to send messages",
|
||||
EnvVars: []string{"PLUGIN_ROOMID", "MATRIX_ROOMID"},
|
||||
Destination: &settings.RoomID,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "template",
|
||||
Usage: "template for the message",
|
||||
EnvVars: []string{"PLUGIN_TEMPLATE", "MATRIX_TEMPLATE"},
|
||||
Value: "Build {{ build.status }} [{{ repo.Owner }}/{{ repo.Name }}#{{ truncate build.commit 8 }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}",
|
||||
Destination: &settings.Template,
|
||||
},
|
||||
}
|
||||
}
|
70
cmd/drone-matrix/main.go
Normal file
70
cmd/drone-matrix/main.go
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// DO NOT MODIFY THIS FILE DIRECTLY
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/drone-plugins/drone-matrix/plugin"
|
||||
"github.com/drone-plugins/drone-plugin-lib/errors"
|
||||
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var version = "unknown"
|
||||
|
||||
func main() {
|
||||
settings := &plugin.Settings{}
|
||||
|
||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||
godotenv.Overload("/run/drone/env")
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "drone-matrix",
|
||||
Usage: "build notifications for matrix",
|
||||
Version: version,
|
||||
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
||||
Action: run(settings),
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
errors.HandleExit(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(settings *plugin.Settings) cli.ActionFunc {
|
||||
return func(ctx *cli.Context) error {
|
||||
urfave.LoggingFromContext(ctx)
|
||||
|
||||
plugin := plugin.New(
|
||||
*settings,
|
||||
urfave.PipelineFromContext(ctx),
|
||||
urfave.NetworkFromContext(ctx),
|
||||
)
|
||||
|
||||
if err := plugin.Validate(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
|
||||
return errors.ExitMessagef("validation failed: %w", err)
|
||||
}
|
||||
|
||||
if err := plugin.Execute(); err != nil {
|
||||
if e, ok := err.(errors.ExitCoder); ok {
|
||||
return e
|
||||
}
|
||||
|
||||
return errors.ExitMessagef("execution failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/amd64/drone-matrix /bin/
|
||||
ENTRYPOINT ["/bin/drone-matrix"]
|
||||
ENTRYPOINT [ "/bin/drone-matrix" ]
|
||||
|
@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/arm/drone-matrix /bin/
|
||||
ENTRYPOINT ["/bin/drone-matrix"]
|
||||
ENTRYPOINT [ "/bin/drone-matrix" ]
|
||||
|
@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/linux/arm64/drone-matrix /bin/
|
||||
ENTRYPOINT ["/bin/drone-matrix"]
|
||||
ENTRYPOINT [ "/bin/drone-matrix" ]
|
||||
|
@ -1,5 +1,5 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1809
|
||||
FROM plugins/base:windows-1809-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Matrix" `
|
||||
|
@ -1,5 +1,5 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1803
|
||||
FROM plugins/base:windows-1903-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Matrix" `
|
10
docker/Dockerfile.windows.1909
Normal file
10
docker/Dockerfile.windows.1909
Normal file
@ -0,0 +1,10 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1909-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Matrix" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-matrix.exe C:/bin/drone-matrix.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-matrix.exe" ]
|
10
docker/Dockerfile.windows.2004
Normal file
10
docker/Dockerfile.windows.2004
Normal file
@ -0,0 +1,10 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-2004-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone Matrix" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-matrix.exe C:/bin/drone-matrix.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-matrix.exe" ]
|
@ -1,36 +1,43 @@
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||
|
||||
{{#if build.tags}}
|
||||
tags:
|
||||
{{#each build.tags}}
|
||||
- {{this}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
manifests:
|
||||
-
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: linux
|
||||
-
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||
platform:
|
||||
architecture: arm64
|
||||
os: linux
|
||||
variant: v8
|
||||
-
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||
platform:
|
||||
architecture: arm
|
||||
os: linux
|
||||
variant: v7
|
||||
-
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-2004-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1803
|
||||
-
|
||||
image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809
|
||||
version: 2004
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1909
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1903
|
||||
- image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
|
18
go.mod
18
go.mod
@ -1,13 +1,13 @@
|
||||
module github.com/drone-plugins/drone-matrix
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/aymerick/raymond v2.0.2+incompatible
|
||||
github.com/drone/drone-template-lib v0.0.0-20180401170447-5748d3149f48
|
||||
github.com/matrix-org/gomatrix v0.0.0-20171003113848-a7fc80c8060c
|
||||
github.com/microcosm-cc/bluemonday v1.0.0
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95
|
||||
github.com/urfave/cli v1.20.0
|
||||
golang.org/x/net v0.0.0-20180801234040-f4c29de78a2a
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
||||
github.com/drone/drone-template-lib v1.0.0
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd
|
||||
github.com/microcosm-cc/bluemonday v1.0.4
|
||||
github.com/russross/blackfriday/v2 v2.0.1
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
)
|
||||
|
88
go.sum
88
go.sum
@ -1,18 +1,78 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
|
||||
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
|
||||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI=
|
||||
github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0=
|
||||
github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||
github.com/drone/drone-template-lib v0.0.0-20180401170447-5748d3149f48 h1:hP2l5isqaiJVvOUM8X/1WDNeeJKlVmM8I1B9aDNT/xw=
|
||||
github.com/drone/drone-template-lib v0.0.0-20180401170447-5748d3149f48/go.mod h1:u34woe41m58Whrf21iH6z/xLOIRM3650LhWAyUc7Oik=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20171003113848-a7fc80c8060c h1:aZap604NyBGhAUE0CyNHz6+Pryye5A5mHnYyO4KPPW8=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20171003113848-a7fc80c8060c/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||
github.com/microcosm-cc/bluemonday v1.0.0 h1:dr58SIfmOwOVr+m4Ye1xLWv8Dk9OFwXAtYnbJSmJ65k=
|
||||
github.com/microcosm-cc/bluemonday v1.0.0/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
github.com/bouk/monkey v1.0.0 h1:k6z8fLlPhETfn5l9rlWVE7Q6B23DoaqosTdArvNQRdc=
|
||||
github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE=
|
||||
github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU=
|
||||
github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
|
||||
github.com/drone/drone-template-lib v1.0.0 h1:PNBBfUhifRnrPCoWBlTitk3jipXdv8u8WLbIf7h7j00=
|
||||
github.com/drone/drone-template-lib v1.0.0/go.mod h1:Hqy1tgqPH5mtbFOZmow19l4jOkZvp+WZ00cB4W3MJhg=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
|
||||
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
||||
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
|
||||
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
||||
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
|
||||
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd h1:xVrqJK3xHREMNjwjljkAUaadalWc0rRbmVuQatzmgwg=
|
||||
github.com/matrix-org/gomatrix v0.0.0-20200827122206-7dd5e2a05bcd/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4 h1:p0L+CTpo/PLFdkoPcJemLXG+fpMD7pYOoDEq1axMbGg=
|
||||
github.com/microcosm-cc/bluemonday v1.0.4/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95 h1:/vdW8Cb7EXrkqWGufVMES1OH2sU9gKVb2n9/1y5NMBY=
|
||||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
golang.org/x/net v0.0.0-20180801234040-f4c29de78a2a h1:8fCF9zjAir2SP3N+axz9xs+0r4V8dqPzqsWO10t8zoo=
|
||||
golang.org/x/net v0.0.0-20180801234040-f4c29de78a2a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0 h1:+FlnIV8DSQnT7NZ43hcVKcdJdzZoeCmJj4Ql8gq5keA=
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0/go.mod h1:6sSBNz/GtOm/pJTuh5UmBK2ZHfmnxGbl2NZg1UliSOI=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643 h1:ii/sHfgFMByozryLeiDmn1ClZ/Pena4NgpJ4P7UuX9o=
|
||||
github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0=
|
||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
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/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||
|
186
main.go
186
main.go
@ -1,186 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "matrix plugin"
|
||||
app.Usage = "matrix plugin"
|
||||
app.Action = run
|
||||
app.Version = version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "username for authentication",
|
||||
EnvVar: "PLUGIN_USERNAME,MATRIX_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "password for authentication",
|
||||
EnvVar: "PLUGIN_PASSWORD,MATRIX_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "userid",
|
||||
Usage: "userid for authentication",
|
||||
EnvVar: "PLUGIN_USERID,PLUGIN_USER_ID,MATRIX_USERID,MATRIX_USER_ID",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "accesstoken",
|
||||
Usage: "accesstoken for authentication",
|
||||
EnvVar: "PLUGIN_ACCESSTOKEN,PLUGIN_ACCESS_TOKEN,MATRIX_ACCESSTOKEN,MATRIX_ACCESS_TOKEN",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "homeserver",
|
||||
Usage: "matrix home server",
|
||||
EnvVar: "PLUGIN_HOMESERVER,MATRIX_HOMESERVER",
|
||||
Value: "https://matrix.org",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "roomid",
|
||||
Usage: "roomid to send messages",
|
||||
EnvVar: "PLUGIN_ROOMID,MATRIX_ROOMID",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "template",
|
||||
Usage: "template for the message",
|
||||
EnvVar: "PLUGIN_TEMPLATE,MATRIX_TEMPLATE",
|
||||
Value: "Build {{ build.status }} [{{ repo.Owner }}/{{ repo.Name }}#{{ truncate build.commit 8 }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repository owner",
|
||||
EnvVar: "DRONE_REPO_OWNER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repository name",
|
||||
EnvVar: "DRONE_REPO_NAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "git commit sha",
|
||||
EnvVar: "DRONE_COMMIT_SHA",
|
||||
Value: "00000000",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.ref",
|
||||
Value: "refs/heads/master",
|
||||
Usage: "git commit ref",
|
||||
EnvVar: "DRONE_COMMIT_REF",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Value: "master",
|
||||
Usage: "git commit branch",
|
||||
EnvVar: "DRONE_COMMIT_BRANCH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.author",
|
||||
Usage: "git author name",
|
||||
EnvVar: "DRONE_COMMIT_AUTHOR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVar: "DRONE_COMMIT_MESSAGE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.event",
|
||||
Value: "push",
|
||||
Usage: "build event",
|
||||
EnvVar: "DRONE_BUILD_EVENT",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "build.number",
|
||||
Usage: "build number",
|
||||
EnvVar: "DRONE_BUILD_NUMBER",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.status",
|
||||
Usage: "build status",
|
||||
Value: "success",
|
||||
EnvVar: "DRONE_BUILD_STATUS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.link",
|
||||
Usage: "build link",
|
||||
EnvVar: "DRONE_BUILD_LINK",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "build.started",
|
||||
Usage: "build started",
|
||||
EnvVar: "DRONE_BUILD_STARTED",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "build.created",
|
||||
Usage: "build created",
|
||||
EnvVar: "DRONE_BUILD_CREATED",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.tag",
|
||||
Usage: "build tag",
|
||||
EnvVar: "DRONE_TAG",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "build.deployTo",
|
||||
Usage: "environment deployed to",
|
||||
EnvVar: "DRONE_DEPLOY_TO",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "job.started",
|
||||
Usage: "job started",
|
||||
EnvVar: "DRONE_JOB_STARTED",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
plugin := Plugin{
|
||||
Repo: Repo{
|
||||
Owner: c.String("repo.owner"),
|
||||
Name: c.String("repo.name"),
|
||||
},
|
||||
Build: Build{
|
||||
Tag: c.String("build.tag"),
|
||||
Number: c.Int("build.number"),
|
||||
Event: c.String("build.event"),
|
||||
Status: c.String("build.status"),
|
||||
Commit: c.String("commit.sha"),
|
||||
Ref: c.String("commit.ref"),
|
||||
Branch: c.String("commit.branch"),
|
||||
Author: c.String("commit.author"),
|
||||
Message: c.String("commit.message"),
|
||||
DeployTo: c.String("build.deployTo"),
|
||||
Link: c.String("build.link"),
|
||||
Started: c.Int64("build.started"),
|
||||
Created: c.Int64("build.created"),
|
||||
},
|
||||
Job: Job{
|
||||
Started: c.Int64("job.started"),
|
||||
},
|
||||
Config: Config{
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
UserID: c.String("userid"),
|
||||
AccessToken: c.String("accesstoken"),
|
||||
Homeserver: c.String("homeserver"),
|
||||
RoomID: c.String("roomid"),
|
||||
Template: c.String("template"),
|
||||
},
|
||||
}
|
||||
|
||||
return plugin.Exec()
|
||||
}
|
119
plugin.go
119
plugin.go
@ -1,119 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone-template-lib/template"
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
)
|
||||
|
||||
type (
|
||||
Repo struct {
|
||||
Owner string
|
||||
Name string
|
||||
}
|
||||
|
||||
Build struct {
|
||||
Tag string
|
||||
Event string
|
||||
Number int
|
||||
Commit string
|
||||
Ref string
|
||||
Branch string
|
||||
Author string
|
||||
Message string
|
||||
DeployTo string
|
||||
Status string
|
||||
Link string
|
||||
Started int64
|
||||
Created int64
|
||||
}
|
||||
|
||||
Job struct {
|
||||
Started int64
|
||||
}
|
||||
|
||||
Config struct {
|
||||
Username string
|
||||
Password string
|
||||
UserID string
|
||||
AccessToken string
|
||||
Homeserver string
|
||||
RoomID string
|
||||
Template string
|
||||
}
|
||||
|
||||
Plugin struct {
|
||||
Repo Repo
|
||||
Build Build
|
||||
Job Job
|
||||
Config Config
|
||||
}
|
||||
)
|
||||
|
||||
func (p Plugin) Exec() error {
|
||||
m, err := gomatrix.NewClient(p.Config.Homeserver, prepend("@", p.Config.UserID), p.Config.AccessToken)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize client")
|
||||
}
|
||||
|
||||
if p.Config.UserID == "" || p.Config.AccessToken == "" {
|
||||
r, err := m.Login(&gomatrix.ReqLogin{
|
||||
Type: "m.login.password",
|
||||
User: p.Config.Username,
|
||||
Password: p.Config.Password,
|
||||
InitialDeviceDisplayName: "Drone",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to authenticate user")
|
||||
}
|
||||
|
||||
m.SetCredentials(r.UserID, r.AccessToken)
|
||||
}
|
||||
|
||||
joined, err := m.JoinRoom(prepend("!", p.Config.RoomID), "", nil)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to join room")
|
||||
}
|
||||
|
||||
message, err := template.RenderTrim(p.Config.Template, p)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to render template")
|
||||
}
|
||||
|
||||
formatted := bluemonday.UGCPolicy().SanitizeBytes(
|
||||
blackfriday.Run([]byte(message)),
|
||||
)
|
||||
|
||||
content := gomatrix.HTMLMessage{
|
||||
Body: message,
|
||||
MsgType: "m.notice",
|
||||
Format: "org.matrix.custom.html",
|
||||
FormattedBody: string(formatted),
|
||||
}
|
||||
|
||||
if _, err := m.SendMessageEvent(joined.RoomID, "m.room.message", content); err != nil {
|
||||
return errors.Wrap(err, "failed to submit message")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepend(prefix, s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
|
||||
if strings.HasPrefix(s, prefix) {
|
||||
return s
|
||||
}
|
||||
|
||||
return prefix + s
|
||||
}
|
98
plugin/impl.go
Normal file
98
plugin/impl.go
Normal file
@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone-template-lib/template"
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
// Settings for the plugin.
|
||||
type Settings struct {
|
||||
Username string
|
||||
Password string
|
||||
UserID string
|
||||
AccessToken string
|
||||
Homeserver string
|
||||
RoomID string
|
||||
Template string
|
||||
}
|
||||
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
// Currently there's no validation
|
||||
return nil
|
||||
}
|
||||
|
||||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
m, err := gomatrix.NewClient(p.settings.Homeserver, prepend("@", p.settings.UserID), p.settings.AccessToken)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize client: %w", err)
|
||||
}
|
||||
|
||||
if p.settings.UserID == "" || p.settings.AccessToken == "" {
|
||||
r, err := m.Login(&gomatrix.ReqLogin{
|
||||
Type: "m.login.password",
|
||||
User: p.settings.Username,
|
||||
Password: p.settings.Password,
|
||||
InitialDeviceDisplayName: "Drone",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to authenticate user: %w", err)
|
||||
}
|
||||
|
||||
m.SetCredentials(r.UserID, r.AccessToken)
|
||||
}
|
||||
|
||||
joined, err := m.JoinRoom(prepend("!", p.settings.RoomID), "", nil)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to join room: %w", err)
|
||||
}
|
||||
|
||||
message, err := template.RenderTrim(p.settings.Template, p)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to render template: %w", err)
|
||||
}
|
||||
|
||||
formatted := bluemonday.UGCPolicy().SanitizeBytes(
|
||||
blackfriday.Run([]byte(message)),
|
||||
)
|
||||
|
||||
content := gomatrix.HTMLMessage{
|
||||
Body: message,
|
||||
MsgType: "m.notice",
|
||||
Format: "org.matrix.custom.html",
|
||||
FormattedBody: string(formatted),
|
||||
}
|
||||
|
||||
if _, err := m.SendMessageEvent(joined.RoomID, "m.room.message", content); err != nil {
|
||||
return fmt.Errorf("failed to submit message: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepend(prefix, s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
|
||||
if strings.HasPrefix(s, prefix) {
|
||||
return s
|
||||
}
|
||||
|
||||
return prefix + s
|
||||
}
|
18
plugin/impl_test.go
Normal file
18
plugin/impl_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
26
plugin/plugin.go
Normal file
26
plugin/plugin.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||
)
|
||||
|
||||
// Plugin implements drone.Plugin to provide the plugin implementation.
|
||||
type Plugin struct {
|
||||
settings Settings
|
||||
pipeline drone.Pipeline
|
||||
network drone.Network
|
||||
}
|
||||
|
||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
||||
return &Plugin{
|
||||
settings: settings,
|
||||
pipeline: pipeline,
|
||||
network: network,
|
||||
}
|
||||
}
|
14
plugin/plugin_test.go
Normal file
14
plugin/plugin_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
26
renovate.json
Normal file
26
renovate.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base",
|
||||
":automergeMinor",
|
||||
":automergeDigest"
|
||||
],
|
||||
"enabledManagers": [
|
||||
"dockerfile",
|
||||
"gomod"
|
||||
],
|
||||
"dockerfile": {
|
||||
"fileMatch": [
|
||||
"docker/Dockerfile\\.linux\\.(arm|arm64|amd64|multiarch)",
|
||||
"docker/Dockerfile\\.windows\\.(1809|1903|1909|2004)"
|
||||
],
|
||||
"pinDigests": true
|
||||
},
|
||||
"gomod": {
|
||||
"postUpdateOptions": [
|
||||
"gomodTidy"
|
||||
]
|
||||
},
|
||||
"labels": [
|
||||
"renovate"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user