From 22446153871d78bdaaa0eda41881e5a13516a2fd Mon Sep 17 00:00:00 2001 From: TP Honey Date: Thu, 15 Dec 2022 13:35:46 +0000 Subject: [PATCH] (maint) move to harness.drone.io --- .drone.star | 342 ------------------ .drone.yml | 254 +++++++++++++ .gitignore | 1 - cmd/drone-matrix/main.go | 70 ---- docker/Dockerfile.linux.arm | 9 - docker/Dockerfile.windows.1909 | 10 - docker/Dockerfile.windows.2004 | 10 - ...ndows.1903 => Dockerfile.windows.ltsc2022} | 2 +- docker/manifest.tmpl | 23 +- go.mod | 35 +- go.sum | 112 +++--- cmd/drone-matrix/config.go => main.go | 59 +++ 12 files changed, 414 insertions(+), 513 deletions(-) delete mode 100644 .drone.star create mode 100644 .drone.yml delete mode 100644 cmd/drone-matrix/main.go delete mode 100644 docker/Dockerfile.linux.arm delete mode 100644 docker/Dockerfile.windows.1909 delete mode 100644 docker/Dockerfile.windows.2004 rename docker/{Dockerfile.windows.1903 => Dockerfile.windows.ltsc2022} (74%) rename cmd/drone-matrix/config.go => main.go (63%) diff --git a/.drone.star b/.drone.star deleted file mode 100644 index 55f059d..0000000 --- a/.drone.star +++ /dev/null @@ -1,342 +0,0 @@ -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.yml b/.drone.yml new file mode 100644 index 0000000..36b4b3d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,254 @@ +kind: pipeline +type: vm +name: testing +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +steps: + - name: lint + image: golang:1.19 + pull: always + commands: + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - golangci-lint version + - golangci-lint run + volumes: + - name: gopath + path: "/go" + - name: test + image: golang:1.19 + commands: + - go test -cover ./... + volumes: + - name: gopath + path: "/go" +volumes: + - name: gopath + temp: {} +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: linux-amd64 +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-matrix . + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.linux.amd64 + repo: plugins/matrix + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: linux-amd64 +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: linux-arm64 +platform: + os: linux + arch: arm64 +pool: + use: ubuntu_arm64 + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-matrix . + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.linux.arm64 + repo: plugins/matrix + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: linux-arm64 +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: windows-1809 +platform: + os: windows + arch: amd64 +pool: + use: windows + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-matrix.exe . + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.windows.1809 + repo: plugins/matrix + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: windows-1809-amd64 + daemon_off: true + purge: false + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: windows-ltsc2022 +platform: + os: windows + arch: amd64 +pool: + use: windows-2022 + +steps: + - name: environment + image: golang:1.19 + pull: always + environment: + CGO_ENABLED: "0" + commands: + - go version + - go env + - name: build + image: golang:1.19 + environment: + CGO_ENABLED: "0" + commands: + - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-matrix.exe . + - name: docker + image: plugins/docker + settings: + dockerfile: docker/Dockerfile.windows.ltsc2022 + repo: plugins/matrix + username: + from_secret: docker_username + password: + from_secret: docker_password + auto_tag: true + auto_tag_suffix: windows-ltsc2022-amd64 + daemon_off: true + purge: false + when: + ref: + - refs/heads/master + - refs/tags/** +depends_on: + - testing +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +type: vm +name: manifest +platform: + os: linux + arch: amd64 +pool: + use: ubuntu + +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 +depends_on: + - linux-amd64 + - linux-arm64 + - windows-1809 + - windows-ltsc2022 +trigger: + ref: + - refs/heads/master + - refs/tags/** diff --git a/.gitignore b/.gitignore index 3f44407..9948a4e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ /drone-matrix* coverage.out -.drone.yml diff --git a/cmd/drone-matrix/main.go b/cmd/drone-matrix/main.go deleted file mode 100644 index 1905a55..0000000 --- a/cmd/drone-matrix/main.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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.arm b/docker/Dockerfile.linux.arm deleted file mode 100644 index ff239d1..0000000 --- a/docker/Dockerfile.linux.arm +++ /dev/null @@ -1,9 +0,0 @@ -FROM plugins/base:multiarch - -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/linux/arm/drone-matrix /bin/ -ENTRYPOINT [ "/bin/drone-matrix" ] diff --git a/docker/Dockerfile.windows.1909 b/docker/Dockerfile.windows.1909 deleted file mode 100644 index 83daa41..0000000 --- a/docker/Dockerfile.windows.1909 +++ /dev/null @@ -1,10 +0,0 @@ -# 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 deleted file mode 100644 index e4b3fed..0000000 --- a/docker/Dockerfile.windows.2004 +++ /dev/null @@ -1,10 +0,0 @@ -# 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/Dockerfile.windows.1903 b/docker/Dockerfile.windows.ltsc2022 similarity index 74% rename from docker/Dockerfile.windows.1903 rename to docker/Dockerfile.windows.ltsc2022 index 85bc024..b25e0cd 100644 --- a/docker/Dockerfile.windows.1903 +++ b/docker/Dockerfile.windows.ltsc2022 @@ -1,5 +1,5 @@ # escape=` -FROM plugins/base:windows-1903-amd64 +FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4 LABEL maintainer="Drone.IO Community " ` org.label-schema.name="Drone Matrix" ` diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl index 3df2fb6..b5d9681 100644 --- a/docker/manifest.tmpl +++ b/docker/manifest.tmpl @@ -17,28 +17,13 @@ manifests: architecture: arm64 os: linux variant: v8 - - 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-2004-amd64 - platform: - architecture: amd64 - os: windows - 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 + - image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 platform: architecture: amd64 os: windows - version: 1903 - - image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 + version: 1809 + - image: plugins/matrix:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 platform: architecture: amd64 os: windows - version: 1809 + version: ltsc2022 \ No newline at end of file diff --git a/go.mod b/go.mod index 685d043..63b7066 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,34 @@ module github.com/drone-plugins/drone-matrix -go 1.15 +go 1.19 require ( 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 + github.com/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca + github.com/joho/godotenv v1.4.0 + github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 + github.com/microcosm-cc/bluemonday v1.0.21 + github.com/russross/blackfriday/v2 v2.1.0 + github.com/urfave/cli/v2 v2.23.7 +) + +require ( + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/sprig/v3 v3.1.0 // indirect + github.com/aymerick/douceur v0.2.0 // indirect + github.com/aymerick/raymond v2.0.2+incompatible // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/gorilla/css v1.0.0 // indirect + github.com/huandu/xstrings v1.4.0 // indirect + github.com/imdario/mergo v0.3.13 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/sirupsen/logrus v1.9.0 // indirect + github.com/spf13/cast v1.5.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/crypto v0.4.0 // indirect + golang.org/x/net v0.4.0 // indirect + golang.org/x/sys v0.3.0 // indirect ) diff --git a/go.sum b/go.sum index 1ad8a92..cc3cfc3 100644 --- a/go.sum +++ b/go.sum @@ -1,78 +1,102 @@ 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/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/sprig/v3 v3.1.0 h1:j7GpgZ7PdFqNsmncycTHsLmVPf5/3wJtlgW9TNDYD9Y= +github.com/Masterminds/sprig/v3 v3.1.0/go.mod h1:ONGMf7UfYGAbMXCZmQLy8x3lCDIPrEZE/rU8pmrbihA= github.com/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/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/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca h1:8kk7qaQJ1R3aIDMQ04NhKRZQZZgBE9veNYme2Wjudts= +github.com/drone/drone-template-lib v1.0.1-0.20201006172840-a58a3f26ebca/go.mod h1:4DHXhrDoAGam5Sx6LHygmi2tkhWt2dWXqNFLQNxmWTc= +github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= 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/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.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/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= +github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= +github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 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/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= +github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= +github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= +github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/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/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= 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/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/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/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= +github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= 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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/urfave/cli/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= +github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= +github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= 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/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= +golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= +golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= 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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= diff --git a/cmd/drone-matrix/config.go b/main.go similarity index 63% rename from cmd/drone-matrix/config.go rename to main.go index fa7fd48..ec6133f 100644 --- a/cmd/drone-matrix/config.go +++ b/main.go @@ -3,13 +3,72 @@ // 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 + } +} + // settingsFlags has the cli.Flags for the plugin.Settings. func settingsFlags(settings *plugin.Settings) []cli.Flag { return []cli.Flag{