diff --git a/.drone.jsonnet b/.drone.jsonnet deleted file mode 100644 index d66c94e..0000000 --- a/.drone.jsonnet +++ /dev/null @@ -1,14 +0,0 @@ -local pipeline = import 'pipeline.libsonnet'; -local name = 'drone-matrix'; - -[ - pipeline.test('linux', 'amd64'), - pipeline.build(name, 'linux', 'amd64'), - pipeline.build(name, 'linux', 'arm64'), - pipeline.build(name, 'linux', 'arm'), - pipeline.notifications(depends_on=[ - 'linux-amd64', - 'linux-arm64', - 'linux-arm', - ]), -] diff --git a/.drone.star b/.drone.star new file mode 100644 index 0000000..55f059d --- /dev/null +++ b/.drone.star @@ -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", + ], + }, + }] diff --git a/.drone.windows.jsonnet b/.drone.windows.jsonnet deleted file mode 100644 index 6196337..0000000 --- a/.drone.windows.jsonnet +++ /dev/null @@ -1,9 +0,0 @@ -local pipeline = import 'pipeline.libsonnet'; -local name = 'drone-matrix'; - -[ - pipeline.test('windows', 'amd64', '1803'), - pipeline.build(name, 'windows', 'amd64', '1803'), - pipeline.build(name, 'windows', 'amd64', '1809'), - pipeline.notifications('windows', 'amd64', '1809', ['windows-1803', 'windows-1809']), -] diff --git a/.drone.windows.yml b/.drone.windows.yml deleted file mode 100644 index 54c6b4b..0000000 --- a/.drone.windows.yml +++ /dev/null @@ -1,273 +0,0 @@ ---- -kind: pipeline -name: testing - -platform: - os: windows - arch: amd64 - version: 1803 - -steps: -- name: vet - pull: always - image: golang:1.11-windowsservercore-1803 - commands: - - go vet ./... - environment: - GO111MODULE: on - volumes: - - name: gopath - path: C:\\gopath - -- name: test - pull: always - image: golang:1.11-windowsservercore-1803 - commands: - - go test -cover ./... - environment: - GO111MODULE: on - volumes: - - name: gopath - path: C:\\gopath - -volumes: -- name: gopath - temp: {} - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - ---- -kind: pipeline -name: windows-1803 - -platform: - os: windows - arch: amd64 - version: 1803 - -steps: -- name: build-push - pull: always - image: golang:1.11-windowsservercore-1803 - commands: - - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-matrix.exe" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - exclude: - - tag - -- name: build-tag - pull: always - image: golang:1.11-windowsservercore-1803 - commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-matrix.exe" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11-windowsservercore-1803 - commands: - - ./release/windows/amd64/drone-matrix.exe --help - -- name: dryrun - pull: always - image: plugins/docker:windows-1803 - settings: - daemon_off: true - dockerfile: docker/Dockerfile.windows.1803 - dry_run: true - password: - from_secret: docker_password - repo: plugins/matrix - tags: windows-1803 - username: - from_secret: docker_username - volumes: - - name: docker_pipe - path: \\\\.\\pipe\\docker_engine - when: - event: - - pull_request - -- name: publish - pull: always - image: plugins/docker:windows-1803 - settings: - auto_tag: true - auto_tag_suffix: windows-1803 - daemon_off: true - dockerfile: docker/Dockerfile.windows.1803 - password: - from_secret: docker_password - repo: plugins/matrix - username: - from_secret: docker_username - volumes: - - name: docker_pipe - path: \\\\.\\pipe\\docker_engine - when: - event: - exclude: - - pull_request - -volumes: -- name: docker_pipe - host: - path: \\\\.\\pipe\\docker_engine - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - -depends_on: -- testing - ---- -kind: pipeline -name: windows-1809 - -platform: - os: windows - arch: amd64 - version: 1809 - -steps: -- name: build-push - pull: always - image: golang:1.11-windowsservercore-1809 - commands: - - "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-matrix.exe" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - exclude: - - tag - -- name: build-tag - pull: always - image: golang:1.11-windowsservercore-1809 - commands: - - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-matrix.exe" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11-windowsservercore-1809 - commands: - - ./release/windows/amd64/drone-matrix.exe --help - -- name: dryrun - pull: always - image: plugins/docker:windows-1809 - settings: - daemon_off: true - dockerfile: docker/Dockerfile.windows.1809 - dry_run: true - password: - from_secret: docker_password - repo: plugins/matrix - tags: windows-1809 - username: - from_secret: docker_username - volumes: - - name: docker_pipe - path: \\\\.\\pipe\\docker_engine - when: - event: - - pull_request - -- name: publish - pull: always - image: plugins/docker:windows-1809 - settings: - auto_tag: true - auto_tag_suffix: windows-1809 - daemon_off: true - dockerfile: docker/Dockerfile.windows.1809 - password: - from_secret: docker_password - repo: plugins/matrix - username: - from_secret: docker_username - volumes: - - name: docker_pipe - path: \\\\.\\pipe\\docker_engine - when: - event: - exclude: - - pull_request - -volumes: -- name: docker_pipe - host: - path: \\\\.\\pipe\\docker_engine - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - -depends_on: -- testing - ---- -kind: pipeline -name: notifications - -platform: - os: windows - arch: amd64 - version: 1809 - -steps: -- name: manifest - pull: always - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.tmpl - username: - from_secret: docker_username - -- name: microbadger - pull: always - image: plugins/webhook - settings: - urls: - from_secret: microbadger_url - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - -depends_on: -- windows-1803 -- windows-1809 - -... diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 09b7b01..0000000 --- a/.drone.yml +++ /dev/null @@ -1,332 +0,0 @@ ---- -kind: pipeline -name: testing - -platform: - os: linux - arch: amd64 - -steps: -- name: vet - pull: always - image: golang:1.11 - commands: - - go vet ./... - environment: - GO111MODULE: on - volumes: - - name: gopath - path: /go - -- name: test - pull: always - image: golang:1.11 - commands: - - go test -cover ./... - environment: - GO111MODULE: on - volumes: - - name: gopath - path: /go - -volumes: -- name: gopath - temp: {} - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - ---- -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.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-matrix" - 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}\" -a -tags netgo -o release/linux/amd64/drone-matrix" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/amd64/drone-matrix --help - -- name: dryrun - pull: always - image: plugins/docker:linux-amd64 - settings: - daemon_off: false - dockerfile: docker/Dockerfile.linux.amd64 - dry_run: true - password: - from_secret: docker_password - repo: plugins/matrix - tags: linux-amd64 - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - pull: always - image: plugins/docker:linux-amd64 - settings: - auto_tag: true - auto_tag_suffix: linux-amd64 - daemon_off: false - dockerfile: docker/Dockerfile.linux.amd64 - password: - from_secret: docker_password - repo: plugins/matrix - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - -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.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-matrix" - 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}\" -a -tags netgo -o release/linux/arm64/drone-matrix" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/arm64/drone-matrix --help - -- name: dryrun - pull: always - image: plugins/docker:linux-arm64 - settings: - daemon_off: false - dockerfile: docker/Dockerfile.linux.arm64 - dry_run: true - password: - from_secret: docker_password - repo: plugins/matrix - tags: linux-arm64 - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - pull: always - image: plugins/docker:linux-arm64 - settings: - auto_tag: true - auto_tag_suffix: linux-arm64 - daemon_off: false - dockerfile: docker/Dockerfile.linux.arm64 - password: - from_secret: docker_password - repo: plugins/matrix - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - -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.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-matrix" - 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}\" -a -tags netgo -o release/linux/arm/drone-matrix" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/arm/drone-matrix --help - -- name: dryrun - pull: always - image: plugins/docker:linux-arm - settings: - daemon_off: false - dockerfile: docker/Dockerfile.linux.arm - dry_run: true - password: - from_secret: docker_password - repo: plugins/matrix - tags: linux-arm - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - pull: always - image: plugins/docker:linux-arm - settings: - auto_tag: true - auto_tag_suffix: linux-arm - daemon_off: false - dockerfile: docker/Dockerfile.linux.arm - password: - from_secret: docker_password - repo: plugins/matrix - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - - "refs/pull/**" - -depends_on: -- testing - ---- -kind: pipeline -name: notifications - -platform: - os: linux - arch: amd64 - -steps: -- name: manifest - pull: always - image: plugins/manifest - settings: - auto_tag: true - ignore_missing: true - password: - from_secret: docker_password - spec: docker/manifest.tmpl - username: - from_secret: docker_username - -- name: microbadger - pull: always - image: plugins/webhook - settings: - urls: - from_secret: microbadger_url - -trigger: - ref: - - refs/heads/master - - "refs/tags/**" - -depends_on: -- linux-amd64 -- linux-arm64 -- linux-arm - -... diff --git a/.github/settings.yml b/.github/settings.yml index ee96a2c..1b54d55 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -69,5 +69,9 @@ branches: - continuous-integration/drone/pr enforce_admins: false restrictions: + apps: + - renovate users: [] - teams: [] + teams: + - Admins + - Maintainers diff --git a/.gitignore b/.gitignore index 0779c6e..3f44407 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/LICENSE b/LICENSE index 8f71f43..8dada3e 100644 --- a/LICENSE +++ b/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. - diff --git a/cmd/drone-matrix/config.go b/cmd/drone-matrix/config.go new file mode 100644 index 0000000..fa7fd48 --- /dev/null +++ b/cmd/drone-matrix/config.go @@ -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, + }, + } +} diff --git a/cmd/drone-matrix/main.go b/cmd/drone-matrix/main.go new file mode 100644 index 0000000..1905a55 --- /dev/null +++ b/cmd/drone-matrix/main.go @@ -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 + } +} diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile.linux.amd64 index 1429bc1..18c80a0 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile.linux.amd64 @@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community " \ org.label-schema.schema-version="1.0" ADD release/linux/amd64/drone-matrix /bin/ -ENTRYPOINT ["/bin/drone-matrix"] +ENTRYPOINT [ "/bin/drone-matrix" ] diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm index 4f10bd9..ff239d1 100644 --- a/docker/Dockerfile.linux.arm +++ b/docker/Dockerfile.linux.arm @@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community " \ org.label-schema.schema-version="1.0" ADD release/linux/arm/drone-matrix /bin/ -ENTRYPOINT ["/bin/drone-matrix"] +ENTRYPOINT [ "/bin/drone-matrix" ] diff --git a/docker/Dockerfile.linux.arm64 b/docker/Dockerfile.linux.arm64 index dba8bf6..db0b28e 100644 --- a/docker/Dockerfile.linux.arm64 +++ b/docker/Dockerfile.linux.arm64 @@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community " \ org.label-schema.schema-version="1.0" ADD release/linux/arm64/drone-matrix /bin/ -ENTRYPOINT ["/bin/drone-matrix"] +ENTRYPOINT [ "/bin/drone-matrix" ] diff --git a/docker/Dockerfile.windows.1809 b/docker/Dockerfile.windows.1809 index 20e4115..c081a66 100644 --- a/docker/Dockerfile.windows.1809 +++ b/docker/Dockerfile.windows.1809 @@ -1,5 +1,5 @@ # escape=` -FROM plugins/base:windows-1809 +FROM plugins/base:windows-1809-amd64 LABEL maintainer="Drone.IO Community " ` org.label-schema.name="Drone Matrix" ` diff --git a/docker/Dockerfile.windows.1803 b/docker/Dockerfile.windows.1903 similarity index 89% rename from docker/Dockerfile.windows.1803 rename to docker/Dockerfile.windows.1903 index abda827..85bc024 100644 --- a/docker/Dockerfile.windows.1803 +++ b/docker/Dockerfile.windows.1903 @@ -1,5 +1,5 @@ # escape=` -FROM plugins/base:windows-1803 +FROM plugins/base:windows-1903-amd64 LABEL maintainer="Drone.IO Community " ` org.label-schema.name="Drone Matrix" ` diff --git a/docker/Dockerfile.windows.1909 b/docker/Dockerfile.windows.1909 new file mode 100644 index 0000000..83daa41 --- /dev/null +++ b/docker/Dockerfile.windows.1909 @@ -0,0 +1,10 @@ +# escape=` +FROM plugins/base:windows-1909-amd64 + +LABEL maintainer="Drone.IO Community " ` + 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" ] diff --git a/docker/Dockerfile.windows.2004 b/docker/Dockerfile.windows.2004 new file mode 100644 index 0000000..e4b3fed --- /dev/null +++ b/docker/Dockerfile.windows.2004 @@ -0,0 +1,10 @@ +# escape=` +FROM plugins/base:windows-2004-amd64 + +LABEL maintainer="Drone.IO Community " ` + 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" ] diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl index 5c60793..3df2fb6 100644 --- a/docker/manifest.tmpl +++ b/docker/manifest.tmpl @@ -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 diff --git a/go.mod b/go.mod index 665bc61..685d043 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index adc5de6..1ad8a92 100644 --- a/go.sum +++ b/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= diff --git a/main.go b/main.go deleted file mode 100644 index 57cad58..0000000 --- a/main.go +++ /dev/null @@ -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() -} diff --git a/pipeline.libsonnet b/pipeline.libsonnet deleted file mode 100644 index 54a07b2..0000000 --- a/pipeline.libsonnet +++ /dev/null @@ -1,205 +0,0 @@ -local windows_pipe = '\\\\\\\\.\\\\pipe\\\\docker_engine'; -local windows_pipe_volume = 'docker_pipe'; -local test_pipeline_name = 'testing'; - -local windows(os) = os == 'windows'; - -local golang_image(os, version) = - 'golang:' + '1.11' + if windows(os) then '-windowsservercore-' + version else ''; - -{ - test(os='linux', arch='amd64', version=''):: - local is_windows = windows(os); - local golang = golang_image(os, version); - local volumes = if is_windows then [{name: 'gopath', path: 'C:\\\\gopath'}] else [{name: 'gopath', path: '/go',}]; - { - kind: 'pipeline', - name: test_pipeline_name, - platform: { - os: os, - arch: arch, - version: if std.length(version) > 0 then version, - }, - steps: [ - { - name: 'vet', - image: golang, - pull: 'always', - environment: { - GO111MODULE: 'on', - }, - commands: [ - 'go vet ./...', - ], - volumes: volumes, - }, - { - name: 'test', - image: golang, - pull: 'always', - environment: { - GO111MODULE: 'on', - }, - commands: [ - 'go test -cover ./...', - ], - volumes: volumes, - }, - ], - trigger: { - ref: [ - 'refs/heads/master', - 'refs/tags/**', - 'refs/pull/**', - ], - }, - volumes: [{name: 'gopath', temp: {}}] - }, - - build(name, os='linux', arch='amd64', version=''):: - local is_windows = windows(os); - local tag = if is_windows then os + '-' + version else os + '-' + arch; - local file_suffix = std.strReplace(tag, '-', '.'); - local volumes = if is_windows then [{ name: windows_pipe_volume, path: windows_pipe }] else []; - local golang = golang_image(os, version); - local plugin_repo = 'plugins/' + std.splitLimit(name, '-', 1)[1]; - local extension = if is_windows then '.exe' else ''; - { - kind: 'pipeline', - name: tag, - platform: { - os: os, - arch: arch, - version: if std.length(version) > 0 then version, - }, - steps: [ - { - name: 'build-push', - image: golang, - pull: 'always', - environment: { - CGO_ENABLED: '0', - GO111MODULE: 'on', - }, - commands: [ - 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/' + os + '/' + arch + '/' + name + extension, - ], - when: { - event: { - exclude: ['tag'], - }, - }, - }, - { - name: 'build-tag', - image: golang, - pull: 'always', - environment: { - CGO_ENABLED: '0', - GO111MODULE: 'on', - }, - commands: [ - 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/' + os + '/' + arch + '/' + name + extension, - ], - when: { - event: ['tag'], - }, - }, - { - name: 'executable', - image: golang, - pull: 'always', - commands: [ - './release/' + os + '/' + arch + '/' + name + extension + ' --help', - ], - }, - { - name: 'dryrun', - image: 'plugins/docker:' + tag, - pull: 'always', - settings: { - dry_run: true, - tags: tag, - dockerfile: 'docker/Dockerfile.' + file_suffix, - daemon_off: if is_windows then 'true' else 'false', - repo: plugin_repo, - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - }, - volumes: if std.length(volumes) > 0 then volumes, - when: { - event: ['pull_request'], - }, - }, - { - name: 'publish', - image: 'plugins/docker:' + tag, - pull: 'always', - settings: { - auto_tag: true, - auto_tag_suffix: tag, - daemon_off: if is_windows then 'true' else 'false', - dockerfile: 'docker/Dockerfile.' + file_suffix, - repo: plugin_repo, - username: { from_secret: 'docker_username' }, - password: { from_secret: 'docker_password' }, - }, - volumes: if std.length(volumes) > 0 then volumes, - when: { - event: { - exclude: ['pull_request'], - }, - }, - }, - ], - trigger: { - ref: [ - 'refs/heads/master', - 'refs/tags/**', - 'refs/pull/**', - ], - }, - depends_on: [test_pipeline_name], - volumes: if is_windows then [{ name: windows_pipe_volume, host: { path: windows_pipe } }], - }, - - notifications(os='linux', arch='amd64', version='', depends_on=[]):: - { - kind: 'pipeline', - name: 'notifications', - platform: { - os: os, - arch: arch, - version: if std.length(version) > 0 then version, - }, - 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, - auto_tag: true, - }, - }, - { - name: 'microbadger', - image: 'plugins/webhook', - pull: 'always', - settings: { - urls: { from_secret: 'microbadger_url' }, - }, - }, - ], - trigger: { - ref: [ - 'refs/heads/master', - 'refs/tags/**', - ], - }, - depends_on: depends_on, - }, -} diff --git a/plugin.go b/plugin.go deleted file mode 100644 index 9971dbc..0000000 --- a/plugin.go +++ /dev/null @@ -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 -} diff --git a/plugin/impl.go b/plugin/impl.go new file mode 100644 index 0000000..5e36652 --- /dev/null +++ b/plugin/impl.go @@ -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 +} diff --git a/plugin/impl_test.go b/plugin/impl_test.go new file mode 100644 index 0000000..badfaa0 --- /dev/null +++ b/plugin/impl_test.go @@ -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() +} diff --git a/plugin/plugin.go b/plugin/plugin.go new file mode 100644 index 0000000..bb8248b --- /dev/null +++ b/plugin/plugin.go @@ -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, + } +} diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go new file mode 100644 index 0000000..3cb461f --- /dev/null +++ b/plugin/plugin_test.go @@ -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() +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..a88a8a2 --- /dev/null +++ b/renovate.json @@ -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" + ] +}