diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..b10aaff --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,317 @@ +local PipelineTest = { + kind: 'pipeline', + name: 'test', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + name: 'staticcheck', + image: 'golang:1.14', + commands: [ + 'go run honnef.co/go/tools/cmd/staticcheck ./...', + ], + volumes: [ + { + name: 'gopath', + path: '/go', + }, + ], + }, + { + name: 'lint', + image: 'golang:1.14', + commands: [ + 'go run golang.org/x/lint/golint -set_exit_status ./...', + ], + volumes: [ + { + name: 'gopath', + path: '/go', + }, + ], + }, + { + name: 'vet', + image: 'golang:1.14', + commands: [ + 'go vet ./...', + ], + volumes: [ + { + name: 'gopath', + path: '/go', + }, + ], + }, + { + name: 'test', + image: 'golang:1.14', + commands: [ + 'go test -cover ./...', + ], + volumes: [ + { + name: 'gopath', + path: '/go', + }, + ], + }, + ], + volumes: [ + { + name: 'gopath', + temp: {}, + }, + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, +}; + + +local PipelineBuildBinaries = { + kind: 'pipeline', + name: 'build-binaries', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + name: 'build', + image: 'techknowlogick/xgo:go-1.14.x', + commands: [ + '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', + 'mkdir -p release/', + "cd cmd/github-releases-notifier && xgo -ldflags \"-s -w -X main.version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier .", + 'mv /build/* /drone/src/release/', + ], + }, + { + name: 'executable', + image: 'alpine', + commands: [ + '$(find release/ -executable -type f | grep github-releases-notifier-linux-amd64) --help', + ], + }, + { + name: 'compress', + image: 'alpine', + commands: [ + 'apk add upx', + 'find release/ -maxdepth 1 -executable -type f -exec upx {} \\;', + 'ls -lh release/', + ], + }, + { + name: 'checksum', + image: 'alpine', + commands: [ + 'cd release/ && sha256sum * > sha256sum.txt', + ], + }, + { + name: 'publish', + image: 'plugins/github-release', + settings: { + overwrite: true, + api_key: { + from_secret: 'github_token', + }, + files: ['release/*'], + title: '${DRONE_TAG}', + note: 'CHANGELOG.md', + }, + when: { + ref: [ + 'refs/tags/**', + ], + }, + }, + ], + depends_on: [ + 'test', + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, +}; + +local PipelineBuildContainer(arch='amd64') = { + kind: 'pipeline', + name: 'build-container-' + arch, + platform: { + os: 'linux', + arch: arch, + }, + steps: [ + { + name: 'build', + image: 'golang:1.14', + commands: [ + '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', + 'go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/' + arch + '/github-releases-notifier ./cmd/github-releases-notifier', + ], + }, + { + name: 'dryrun', + image: 'plugins/docker:18-linux-' + arch, + settings: { + dry_run: true, + dockerfile: 'docker/Dockerfile.' + arch, + repo: 'thegeeklab/${DRONE_REPO_NAME}', + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + }, + depends_on: ['build'], + when: { + ref: ['refs/pull/**'], + }, + }, + { + name: 'publish-dockerhub', + image: 'plugins/docker:18-linux-' + arch, + settings: { + auto_tag: true, + auto_tag_suffix: arch, + dockerfile: 'docker/Dockerfile.' + arch, + repo: 'thegeeklab/${DRONE_REPO_NAME}', + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + }, + when: { + ref: ['refs/heads/master', 'refs/tags/**'], + }, + depends_on: ['dryrun'], + }, + { + name: 'publish-quay', + image: 'plugins/docker:18-linux-' + arch, + settings: { + auto_tag: true, + auto_tag_suffix: arch, + dockerfile: 'docker/Dockerfile.' + arch, + registry: 'quay.io', + repo: 'quay.io/thegeeklab/${DRONE_REPO_NAME}', + username: { from_secret: 'quay_username' }, + password: { from_secret: 'quay_password' }, + }, + when: { + ref: ['refs/heads/master', 'refs/tags/**'], + }, + depends_on: ['dryrun'], + }, + ], + depends_on: [ + 'test', + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, +}; + +local PipelineNotifications = { + kind: 'pipeline', + name: 'notifications', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + image: 'plugins/manifest', + name: 'manifest-dockerhub', + settings: { + ignore_missing: true, + auto_tag: true, + username: { from_secret: 'docker_username' }, + password: { from_secret: 'docker_password' }, + spec: 'docker/manifest.tmpl', + }, + when: { + status: ['success'], + }, + }, + { + image: 'plugins/manifest', + name: 'manifest-quay', + settings: { + ignore_missing: true, + auto_tag: true, + username: { from_secret: 'quay_username' }, + password: { from_secret: 'quay_password' }, + spec: 'docker/manifest-quay.tmpl', + }, + when: { + status: ['success'], + }, + }, + { + name: 'pushrm-dockerhub', + image: 'chko/docker-pushrm:1', + environment: { + DOCKER_PASS: { + from_secret: 'docker_password', + }, + DOCKER_USER: { + from_secret: 'docker_username', + }, + PUSHRM_FILE: 'README.md', + PUSHRM_SHORT: 'GitHub release notification bot', + PUSHRM_TARGET: 'thegeeklab/${DRONE_REPO_NAME}', + }, + when: { + status: ['success'], + }, + }, + { + name: 'pushrm-quay', + image: 'chko/docker-pushrm:1', + environment: { + APIKEY__QUAY_IO: { + from_secret: 'quay_token', + }, + PUSHRM_FILE: 'README.md', + PUSHRM_TARGET: 'quay.io/thegeeklab/${DRONE_REPO_NAME}', + }, + when: { + status: ['success'], + }, + }, + { + name: 'matrix', + image: 'plugins/matrix', + settings: { + homeserver: { from_secret: 'matrix_homeserver' }, + roomid: { from_secret: 'matrix_roomid' }, + template: 'Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}', + username: { from_secret: 'matrix_username' }, + password: { from_secret: 'matrix_password' }, + }, + when: { + status: ['success', 'failure'], + }, + }, + ], + depends_on: [ + 'build-binaries', + 'build-container-amd64', + 'build-container-arm', + 'build-container-arm64', + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**'], + status: ['success', 'failure'], + }, +}; + +[ + PipelineTest, + PipelineBuildBinaries, + PipelineBuildContainer(arch='amd64'), + PipelineBuildContainer(arch='arm64'), + PipelineBuildContainer(arch='arm'), + PipelineNotifications, +] diff --git a/.drone.star b/.drone.star deleted file mode 100644 index e02c4e7..0000000 --- a/.drone.star +++ /dev/null @@ -1,297 +0,0 @@ -def main(ctx): - before = testing() - - stages = [ - linux('amd64'), - linux('arm64'), - linux('arm'), - binaries([]), - ] - - after = notification() - - 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(): - return [{ - 'kind': 'pipeline', - 'type': 'docker', - 'name': 'testing', - 'platform': { - 'os': 'linux', - 'arch': 'amd64', - }, - 'steps': [ - { - 'name': 'vet', - 'image': 'golang:1.12', - 'commands': [ - 'go vet ./...' - ], - 'volumes': [ - { - 'name': 'gopath', - 'path': '/go' - } - ] - }, - { - 'name': 'test', - 'image': 'golang:1.12', - 'commands': [ - 'go test -cover ./...' - ], - 'volumes': [ - { - 'name': 'gopath', - 'path': '/go' - } - ] - } - ], - 'volumes': [ - { - 'name': 'gopath', - 'temp': {} - } - ], - 'trigger': { - 'ref': [ - 'refs/heads/master', - 'refs/tags/**', - 'refs/pull/**' - ] - } - }] - -def linux(arch): - return { - 'kind': 'pipeline', - 'type': 'docker', - 'name': 'build-container-%s' % arch, - 'platform': { - 'os': 'linux', - 'arch': arch, - }, - 'steps': [ - { - 'name': 'build', - 'image': 'golang:1.12', - 'environment': { - 'CGO_ENABLED': '0', - }, - 'commands': [ - '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', - 'go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/%s/github-releases-notifier' % arch - ], - }, - { - 'name': 'executable', - 'image': 'golang:1.12', - 'commands': [ - './release/%s/github-releases-notifier --help' % arch, - ] - }, - { - 'name': 'dryrun', - 'image': 'plugins/docker', - 'settings': { - 'dry_run': True, - 'tags': arch, - 'dockerfile': 'docker/Dockerfile.%s' % arch, - 'repo': 'xoxys/github-releases-notifier', - 'username': { - 'from_secret': 'docker_username' - }, - 'password': { - 'from_secret': 'docker_password' - } - }, - 'when': { - 'event': [ - 'pull_request' - ] - } - }, - { - 'name': 'publish', - 'image': 'plugins/docker', - 'settings': { - 'auto_tag': True, - 'auto_tag_suffix': arch, - 'dockerfile': 'docker/Dockerfile.%s' % arch, - 'repo': 'xoxys/github-releases-notifier', - 'username': { - 'from_secret': 'docker_username' - }, - 'password': { - 'from_secret': 'docker_password' - } - }, - 'when': { - 'event': { - 'exclude': [ - 'pull_request' - ] - } - } - } - ], - 'depends_on': [], - 'trigger': { - 'ref': [ - 'refs/heads/master', - 'refs/tags/**', - 'refs/pull/**' - ] - } - } - -def binaries(arch): - return { - 'kind': 'pipeline', - 'type': 'docker', - 'name': 'build-binaries', - 'steps': [ - { - 'name': 'build', - 'image': 'techknowlogick/xgo:latest', - 'commands': [ - '[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}', - 'mkdir -p release/', - "xgo -ldflags \"-X main.Version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier-$BUILD_VERSION .", - 'cp /build/* release/' - ] - }, - { - 'name': 'checksum', - 'image': 'alpine', - 'commands': [ - 'cd release/ && sha256sum * > sha256sum.txt', - ], - }, - { - 'name': 'publish', - 'image': 'plugins/github-release', - 'settings': { - 'overwrite': True, - 'api_key': { - 'from_secret': 'github_token' - }, - 'files': [ "release/*" ], - 'title': '${DRONE_TAG}', - 'note': 'CHANGELOG.md', - }, - 'when': { - 'ref': [ - 'refs/tags/**' - ] - } - } - ], - 'depends_on': [], - 'trigger': { - 'ref': [ - 'refs/heads/master', - 'refs/tags/**', - 'refs/pull/**' - ] - } - } - -def notification(): - return [{ - 'kind': 'pipeline', - 'type': 'docker', - 'name': 'notification', - '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', - }, - 'when' : { - 'status': [ - 'success', - ] - }, - }, - { - 'name': 'readme', - 'image': 'sheogorath/readme-to-dockerhub', - 'environment': { - 'DOCKERHUB_USERNAME': { - 'from_secret': 'docker_username' - }, - 'DOCKERHUB_PASSWORD': { - 'from_secret': 'docker_password' - }, - 'DOCKERHUB_REPO_PREFIX': 'xoxys', - 'DOCKERHUB_REPO_NAME': 'github-releases-notifier', - 'README_PATH': 'README.md', - 'SHORT_DESCRIPTION': 'Receive Slack notifications for new GitHub releases' - }, - }, - { - 'name': 'microbadger', - 'image': 'plugins/webhook', - 'settings': { - 'urls': { - 'from_secret': 'microbadger_url' - } - }, - 'when' : { - 'status': [ - 'success', - ] - }, - }, - { - 'name': 'matrix', - 'image': 'plugins/matrix', - 'settings': { - 'homeserver': { - 'from_secret': 'matrix_homeserver', - }, - 'password': { - 'from_secret': 'matrix_password', - }, - 'roomid': { - 'from_secret': 'matrix_roomid', - }, - 'template': 'Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}', - 'username': { - 'from_secret': 'matrix_username', - }, - }, - }, - ], - 'depends_on': [], - 'trigger': { - 'ref': [ - 'refs/heads/master', - 'refs/tags/**' - ], - 'status': [ - 'success', - 'failure' - ] - } - }] diff --git a/.drone.yml b/.drone.yml index ba6665a..b0fb996 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,15 +1,30 @@ --- kind: pipeline -type: docker -name: testing +name: test platform: os: linux arch: amd64 steps: +- name: staticcheck + image: golang:1.14 + commands: + - go run honnef.co/go/tools/cmd/staticcheck ./... + volumes: + - name: gopath + path: /go + +- name: lint + image: golang:1.14 + commands: + - go run golang.org/x/lint/golint -set_exit_status ./... + volumes: + - name: gopath + path: /go + - name: vet - image: golang:1.12 + image: golang:1.14 commands: - go vet ./... volumes: @@ -17,7 +32,7 @@ steps: path: /go - name: test - image: golang:1.12 + image: golang:1.14 commands: - go test -cover ./... volumes: @@ -36,196 +51,6 @@ trigger: --- kind: pipeline -type: docker -name: build-container-amd64 - -platform: - os: linux - arch: amd64 - -steps: -- name: build - image: golang:1.12 - commands: - - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - - go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/amd64/github-releases-notifier - environment: - CGO_ENABLED: 0 - -- name: executable - image: golang:1.12 - commands: - - ./release/amd64/github-releases-notifier --help - -- name: dryrun - image: plugins/docker - settings: - dockerfile: docker/Dockerfile.amd64 - dry_run: true - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - tags: amd64 - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: amd64 - dockerfile: docker/Dockerfile.amd64 - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - refs/tags/** - - refs/pull/** - -depends_on: -- testing - ---- -kind: pipeline -type: docker -name: build-container-arm64 - -platform: - os: linux - arch: arm64 - -steps: -- name: build - image: golang:1.12 - commands: - - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - - go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/arm64/github-releases-notifier - environment: - CGO_ENABLED: 0 - -- name: executable - image: golang:1.12 - commands: - - ./release/arm64/github-releases-notifier --help - -- name: dryrun - image: plugins/docker - settings: - dockerfile: docker/Dockerfile.arm64 - dry_run: true - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - tags: arm64 - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: arm64 - dockerfile: docker/Dockerfile.arm64 - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - refs/tags/** - - refs/pull/** - -depends_on: -- testing - ---- -kind: pipeline -type: docker -name: build-container-arm - -platform: - os: linux - arch: arm - -steps: -- name: build - image: golang:1.12 - commands: - - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - - go build -v -ldflags "-X main.Version=$BUILD_VERSION" -a -tags netgo -o release/arm/github-releases-notifier - environment: - CGO_ENABLED: 0 - -- name: executable - image: golang:1.12 - commands: - - ./release/arm/github-releases-notifier --help - -- name: dryrun - image: plugins/docker - settings: - dockerfile: docker/Dockerfile.arm - dry_run: true - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - tags: arm - username: - from_secret: docker_username - when: - event: - - pull_request - -- name: publish - image: plugins/docker - settings: - auto_tag: true - auto_tag_suffix: arm - dockerfile: docker/Dockerfile.arm - password: - from_secret: docker_password - repo: xoxys/github-releases-notifier - username: - from_secret: docker_username - when: - event: - exclude: - - pull_request - -trigger: - ref: - - refs/heads/master - - refs/tags/** - - refs/pull/** - -depends_on: -- testing - ---- -kind: pipeline -type: docker name: build-binaries platform: @@ -234,12 +59,24 @@ platform: steps: - name: build - image: techknowlogick/xgo:latest + image: techknowlogick/xgo:go-1.14.x commands: - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" - mkdir -p release/ - - xgo -ldflags "-X main.Version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier-$BUILD_VERSION . - - cp /build/* release/ + - cd cmd/github-releases-notifier && xgo -ldflags "-s -w -X main.version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out github-releases-notifier . + - mv /build/* /drone/src/release/ + +- name: executable + image: alpine + commands: + - $(find release/ -executable -type f | grep github-releases-notifier-linux-amd64) --help + +- name: compress + image: alpine + commands: + - apk add upx + - find release/ -maxdepth 1 -executable -type f -exec upx {} \; + - ls -lh release/ - name: checksum image: alpine @@ -267,19 +104,249 @@ trigger: - refs/pull/** depends_on: -- testing +- test --- kind: pipeline -type: docker -name: notification +name: build-container-amd64 platform: os: linux arch: amd64 steps: -- name: manifest +- name: build + image: golang:1.14 + commands: + - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" + - go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/amd64/github-releases-notifier ./cmd/github-releases-notifier + +- name: dryrun + image: plugins/docker:18-linux-amd64 + settings: + dockerfile: docker/Dockerfile.amd64 + dry_run: true + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/pull/** + depends_on: + - build + +- name: publish-dockerhub + image: plugins/docker:18-linux-amd64 + settings: + auto_tag: true + auto_tag_suffix: amd64 + dockerfile: docker/Dockerfile.amd64 + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +- name: publish-quay + image: plugins/docker:18-linux-amd64 + settings: + auto_tag: true + auto_tag_suffix: amd64 + dockerfile: docker/Dockerfile.amd64 + password: + from_secret: quay_password + registry: quay.io + repo: quay.io/thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: quay_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +depends_on: +- test + +--- +kind: pipeline +name: build-container-arm64 + +platform: + os: linux + arch: arm64 + +steps: +- name: build + image: golang:1.14 + commands: + - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" + - go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/arm64/github-releases-notifier ./cmd/github-releases-notifier + +- name: dryrun + image: plugins/docker:18-linux-arm64 + settings: + dockerfile: docker/Dockerfile.arm64 + dry_run: true + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/pull/** + depends_on: + - build + +- name: publish-dockerhub + image: plugins/docker:18-linux-arm64 + settings: + auto_tag: true + auto_tag_suffix: arm64 + dockerfile: docker/Dockerfile.arm64 + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +- name: publish-quay + image: plugins/docker:18-linux-arm64 + settings: + auto_tag: true + auto_tag_suffix: arm64 + dockerfile: docker/Dockerfile.arm64 + password: + from_secret: quay_password + registry: quay.io + repo: quay.io/thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: quay_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +depends_on: +- test + +--- +kind: pipeline +name: build-container-arm + +platform: + os: linux + arch: arm + +steps: +- name: build + image: golang:1.14 + commands: + - "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}" + - go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/arm/github-releases-notifier ./cmd/github-releases-notifier + +- name: dryrun + image: plugins/docker:18-linux-arm + settings: + dockerfile: docker/Dockerfile.arm + dry_run: true + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/pull/** + depends_on: + - build + +- name: publish-dockerhub + image: plugins/docker:18-linux-arm + settings: + auto_tag: true + auto_tag_suffix: arm + dockerfile: docker/Dockerfile.arm + password: + from_secret: docker_password + repo: thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: docker_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +- name: publish-quay + image: plugins/docker:18-linux-arm + settings: + auto_tag: true + auto_tag_suffix: arm + dockerfile: docker/Dockerfile.arm + password: + from_secret: quay_password + registry: quay.io + repo: quay.io/thegeeklab/${DRONE_REPO_NAME} + username: + from_secret: quay_username + when: + ref: + - refs/heads/master + - refs/tags/** + depends_on: + - dryrun + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +depends_on: +- test + +--- +kind: pipeline +name: notifications + +platform: + os: linux + arch: amd64 + +steps: +- name: manifest-dockerhub image: plugins/manifest settings: auto_tag: true @@ -293,23 +360,41 @@ steps: status: - success -- name: readme - image: sheogorath/readme-to-dockerhub - environment: - DOCKERHUB_PASSWORD: - from_secret: docker_password - DOCKERHUB_REPO_NAME: github-releases-notifier - DOCKERHUB_REPO_PREFIX: xoxys - DOCKERHUB_USERNAME: - from_secret: docker_username - README_PATH: README.md - SHORT_DESCRIPTION: Receive Slack notifications for new GitHub releases - -- name: microbadger - image: plugins/webhook +- name: manifest-quay + image: plugins/manifest settings: - urls: - from_secret: microbadger_url + auto_tag: true + ignore_missing: true + password: + from_secret: quay_password + spec: docker/manifest-quay.tmpl + username: + from_secret: quay_username + when: + status: + - success + +- name: pushrm-dockerhub + image: chko/docker-pushrm:1 + environment: + DOCKER_PASS: + from_secret: docker_password + DOCKER_USER: + from_secret: docker_username + PUSHRM_FILE: README.md + PUSHRM_SHORT: GitHub Comment - Drone plugin to add comments to GitHub Issues/PRs + PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME} + when: + status: + - success + +- name: pushrm-quay + image: chko/docker-pushrm:1 + environment: + APIKEY__QUAY_IO: + from_secret: quay_token + PUSHRM_FILE: README.md + PUSHRM_TARGET: quay.io/thegeeklab/${DRONE_REPO_NAME} when: status: - success @@ -326,6 +411,10 @@ steps: template: "Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}" username: from_secret: matrix_username + when: + status: + - success + - failure trigger: ref: @@ -336,13 +425,13 @@ trigger: - failure depends_on: -- build-container-amd64 -- build-container-arm64 -- build-container-arm - build-binaries +- build-container-amd64 +- build-container-arm +- build-container-arm64 --- kind: signature -hmac: 982d7a70f6cd3914794b3d085b7f949e72445698d9d4af06323239f98cf83058 +hmac: 7fd3a4a3d079dd575030424aa90c99900def6bd2a7af88449933143009e28d99 ... diff --git a/.env.example b/.env.example deleted file mode 100644 index 3fc6137..0000000 --- a/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -# This file is only used for local development -GITHUB_TOKEN=XXX -INTERVAL=1m -LOG_LEVEL=debug -SLACK_HOOK=https://hooks.slack.com/services/T02MTEVH7/BASDAHYRZ/XXX... diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..4451517 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,55 @@ +repository: + name: github-releases-notifier + description: GitHub release notification bot + topics: drone, drone-plugin + + private: false + has_issues: true + has_wiki: false + has_downloads: true + + default_branch: master + + allow_squash_merge: true + allow_merge_commit: true + allow_rebase_merge: true + +labels: + - name: bug + color: d73a4a + description: Something isn't working + - name: documentation + color: 0075ca + description: Improvements or additions to documentation + - name: duplicate + color: cfd3d7 + description: This issue or pull request already exists + - name: enhancement + color: a2eeef + description: New feature or request + - name: good first issue + color: 7057ff + description: Good for newcomers + - name: help wanted + color: 008672 + description: Extra attention is needed + - name: invalid + color: e4e669 + description: This doesn't seem right + - name: question + color: d876e3 + description: Further information is requested + - name: wontfix + color: ffffff + description: This will not be worked on + +branches: + - name: master + protection: + required_pull_request_reviews: null + required_status_checks: + strict: true + contexts: + - continuous-integration/drone/pr + enforce_admins: null + restrictions: null diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d2000e..89acff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,3 @@ -- FEATURE - - add env variable `GITHUB_REPOS` - - add env variable `IGNORE_PRE` -- BUGFIX - - add `required` flag for GitHub token and Slack hook - INTERNAL - - provide also binary releases - - switch to gomod instead of vendor folder + - publish to dockerhub and quay + - refactor project structure diff --git a/LICENSE b/LICENSE index 95ac905..44e4d67 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ MIT License -Copyright (c) 2020 xoxys +Copyright (c) 2020 Robert Kaussow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index bdf2e6a..98f0190 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,28 @@ # github-releases-notifier +GitHub release notification bot -[![Build Status](https://cloud.drone.io/api/badges/xoxys/github-releases-notifier/status.svg)](https://cloud.drone.io/xoxys/github-releases-notifier) -[![Go Report Card](https://goreportcard.com/badge/github.com/xoxys/github-releases-notifier)](https://goreportcard.com/report/github.com/xoxyscom/github-releases-notifier) -[![Docker Pulls](https://img.shields.io/docker/pulls/xoxys/github-releases-notifier.svg?maxAge=604800)](https://hub.docker.com/r/xoxys/github-releases-notifier) +[![Build Status](https://img.shields.io/drone/build/thegeeklab/github-releases-notifier?logo=drone)](https://cloud.drone.io/thegeeklab/github-releases-notifier) +[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/github-releases-notifier) +[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/github-releases-notifier) +[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/github-releases-notifier)](https://goreportcard.com/report/github.com/thegeeklabcom/github-releases-notifier) +[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/github-releases-notifier) +[![License: MIT](https://img.shields.io/github/license/thegeeklab/github-releases-notifier)](<[LICENSE](https://github.com/thegeeklab/github-releases-notifier/blob/master/LICENSE)>) Receive Slack notifications if a new release of your favorite software is available on GitHub. -![screenshot.png](screenshot.png) +## Setup -### Watching repositories +1. Get a URL to send WebHooks to your Slack. +2. Get a token for scraping GitHub: [https://help.github.com/](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). -To watch repositories simply add them to the list of arguments `-r=kubernetes/kubernetes -r=prometheus/prometheus` and so on. +To watch repositories simply add them to the list of arguments e.g. `-r=kubernetes/kubernetes -r=prometheus/prometheus`. -### Deploying - -1. Get a URL to send WebHooks to your Slack from https://api.slack.com/incoming-webhooks. -2. Get a token for scraping GitHub: [https://help.github.com/](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line). - -#### Docker +### Docker +```Shell +docker run --rm \ + -e GITHUB_TOKEN=XXX \ + -e SLACK_HOOK=https://hooks.slack.com/... \ + thegeeklab/github-releases-notifier -r=kubernetes/kubernetes ``` -docker run --rm -e GITHUB_TOKEN=XXX -e SLACK_HOOK=https://hooks.slack.com/... xoxys/github-releases-notifier -r=kubernetes/kubernetes -``` - -#### docker-compose - -1. Change into the `deployments/` folder. -2. Open `docker-compose.yml` -3. Change the token in the environment section to the ones obtained above. -4. `docker-compose up` - -#### Kubernetes - -```bash -kubectl create secret generic github-releases-notifier \ - --from-literal=github=XXX` \ - --from-literal=slack=XXX -``` - -After creating the secret with your credentials you can apply the deployment: - -`kubectl apply -f deployments/kubernetes.yml` - -That's it. diff --git a/main.go b/cmd/github-releases-notifier/main.go similarity index 90% rename from main.go rename to cmd/github-releases-notifier/main.go index 7dd2224..4a63b8b 100644 --- a/main.go +++ b/cmd/github-releases-notifier/main.go @@ -11,6 +11,8 @@ import ( "github.com/go-kit/kit/log/level" "github.com/joho/godotenv" "github.com/shurcooL/githubv4" + "github.com/thegeeklab/github-releases-notifier/internal/handler" + "github.com/thegeeklab/github-releases-notifier/internal/model" "golang.org/x/oauth2" ) @@ -70,10 +72,10 @@ func main() { client: githubv4.NewClient(client), } - releases := make(chan Repository) + releases := make(chan model.Repository) go checker.Run(c.Interval, c.Repositories, c.IgnorePre, releases) - slack := SlackSender{Hook: c.SlackHook} + slack := handler.SlackSender{Hook: c.SlackHook} level.Info(logger).Log("msg", "waiting for new releases") for repository := range releases { diff --git a/releasechecker.go b/cmd/github-releases-notifier/releasechecker.go similarity index 83% rename from releasechecker.go rename to cmd/github-releases-notifier/releasechecker.go index aa72889..6507651 100644 --- a/releasechecker.go +++ b/cmd/github-releases-notifier/releasechecker.go @@ -9,6 +9,7 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/shurcooL/githubv4" + "github.com/thegeeklab/github-releases-notifier/internal/model" ) // Checker has a githubv4 client to run queries and also knows about @@ -16,14 +17,14 @@ import ( type Checker struct { logger log.Logger client *githubv4.Client - releases map[string]Repository + releases map[string]model.Repository } // Run the queries and comparisons for the given repositories in a given interval. func (c *Checker) Run(interval time.Duration, repositories []string, - ignorePre bool, releases chan<- Repository) { + ignorePre bool, releases chan<- model.Repository) { if c.releases == nil { - c.releases = make(map[string]Repository) + c.releases = make(map[string]model.Repository) } for { @@ -78,7 +79,7 @@ func (c *Checker) Run(interval time.Duration, repositories []string, // This should be improved in the future to make batch requests for all watched repositories at once // TODO: https://github.com/shurcooL/githubv4/issues/17 -func (c *Checker) query(owner, name string) (Repository, error) { +func (c *Checker) query(owner, name string) (model.Repository, error) { var query struct { Repository struct { ID githubv4.ID @@ -109,32 +110,32 @@ func (c *Checker) query(owner, name string) (Repository, error) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := c.client.Query(ctx, &query, variables); err != nil { - return Repository{}, err + return model.Repository{}, err } repositoryID, ok := query.Repository.ID.(string) if !ok { - return Repository{}, fmt.Errorf("can't convert repository id to string: %v", query.Repository.ID) + return model.Repository{}, fmt.Errorf("can't convert repository id to string: %v", query.Repository.ID) } if len(query.Repository.Releases.Edges) == 0 { - return Repository{}, fmt.Errorf("can't find any releases for %s/%s", owner, name) + return model.Repository{}, fmt.Errorf("can't find any releases for %s/%s", owner, name) } latestRelease := query.Repository.Releases.Edges[0].Node releaseID, ok := latestRelease.ID.(string) if !ok { - return Repository{}, fmt.Errorf("can't convert release id to string: %v", query.Repository.ID) + return model.Repository{}, fmt.Errorf("can't convert release id to string: %v", query.Repository.ID) } - return Repository{ + return model.Repository{ ID: repositoryID, Name: string(query.Repository.Name), Owner: owner, Description: string(query.Repository.Description), URL: *query.Repository.URL.URL, - Release: Release{ + Release: model.Release{ ID: releaseID, Name: string(latestRelease.Name), Description: string(latestRelease.Description), diff --git a/deployments/docker-compose.yml b/deployments/docker-compose.yml deleted file mode 100644 index 83c47a5..0000000 --- a/deployments/docker-compose.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: '2' - -services: - github-releases-notifier: - restart: always - image: justwatch/github-releases-notifier - environment: - - GITHUB_TOKEN=XXX - - SLACK_HOOK=https://hooks.slack.com/services/T02MASDF7/B6WERHYRZ/XXX - command: - - '-r=golang/go' - - '-r=justwatchcom/elasticsearch_exporter' - - '-r=justwatchcom/gopass' - - '-r=justwatchcom/sql_exporter' - - '-r=kubernetes/minikube' - - '-r=prometheus/prometheus' - - '-r=shurcooL/githubql' diff --git a/deployments/kubernetes.yml b/deployments/kubernetes.yml deleted file mode 100644 index 6348e34..0000000 --- a/deployments/kubernetes.yml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: github-releases-notifier -spec: - replicas: 1 - revisionHistoryLimit: 10 - strategy: - rollingUpdate: - maxSurge: 0 - maxUnavailable: 1 - type: RollingUpdate - template: - metadata: - labels: - app: github-releases-notifier - spec: - securityContext: - runAsNonRoot: true - runAsUser: 1000 - containers: - - name: github-releases-notifier - image: justwatch/github-releases-notifier - env: - - name: GITHUB_TOKEN - valueFrom: - secretKeyRef: - name: github-releases-notifier - key: github - - name: SLACK_HOOK - valueFrom: - secretKeyRef: - name: github-releases-notifier - key: slack - command: - - '/bin/github-releases-notifier' - args: - - '-r=golang/go' - - '-r=justwatchcom/elasticsearch_exporter' - - '-r=justwatchcom/gopass' - - '-r=justwatchcom/sql_exporter' - - '-r=kubernetes/minikube' - - '-r=prometheus/prometheus' - - '-r=shurcooL/githubql' - resources: - limits: - cpu: 100m - memory: 128Mi - requests: - cpu: 25m - memory: 64Mi - restartPolicy: Always diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 500e04e..b5c01d6 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -1,4 +1,10 @@ -FROM alpine:3.10 +FROM alpine:3.12 + +LABEL maintainer="Robert Kaussow " \ + org.label-schema.name="GitHub Release Notifier" \ + org.label-schema.vendor="Robert Kaussow" \ + org.label-schema.schema-version="1.0" + RUN apk --no-cache add ca-certificates ADD release/amd64/github-releases-notifier /bin/ diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm index 350de95..0960954 100644 --- a/docker/Dockerfile.arm +++ b/docker/Dockerfile.arm @@ -1,4 +1,10 @@ -FROM alpine:3.10 +FROM alpine:3.12 + +LABEL maintainer="Robert Kaussow " \ + org.label-schema.name="GitHub Release Notifier" \ + org.label-schema.vendor="Robert Kaussow" \ + org.label-schema.schema-version="1.0" + RUN apk --no-cache add ca-certificates ADD release/arm/github-releases-notifier /bin/ diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 index 2a7f0c7..2bf7924 100644 --- a/docker/Dockerfile.arm64 +++ b/docker/Dockerfile.arm64 @@ -1,4 +1,10 @@ -FROM alpine:3.10 +FROM alpine:3.12 + +LABEL maintainer="Robert Kaussow " \ + org.label-schema.name="GitHub Release Notifier" \ + org.label-schema.vendor="Robert Kaussow" \ + org.label-schema.schema-version="1.0" + RUN apk --no-cache add ca-certificates ADD release/arm64/github-releases-notifier /bin/ diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl index 3581e3f..90a6c6a 100644 --- a/docker/manifest.tmpl +++ b/docker/manifest.tmpl @@ -1,4 +1,4 @@ -image: xoxys/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +image: thegeeklab/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} {{#if build.tags}} tags: {{#each build.tags}} @@ -6,18 +6,18 @@ tags: {{/each}} {{/if}} manifests: - - image: xoxys/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64 + - image: thegeeklab/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64 platform: architecture: amd64 os: linux - - image: xoxys/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64 + - image: thegeeklab/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64 platform: architecture: arm64 os: linux variant: v8 - - image: xoxys/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm + - image: thegeeklab/github-releases-notifier:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm platform: architecture: arm os: linux diff --git a/go.mod b/go.mod index ab88287..7d6a306 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/xoxys/github-releases-notifier +module github.com/thegeeklab/github-releases-notifier go 1.13 diff --git a/slack.go b/internal/handler/slack.go similarity index 89% rename from slack.go rename to internal/handler/slack.go index 41cd842..565299d 100644 --- a/slack.go +++ b/internal/handler/slack.go @@ -1,4 +1,4 @@ -package main +package handler import ( "bytes" @@ -8,6 +8,8 @@ import ( "io/ioutil" "net/http" "time" + + "github.com/thegeeklab/github-releases-notifier/internal/model" ) // SlackSender has the hook to send slack notifications. @@ -22,7 +24,7 @@ type slackPayload struct { } // Send a notification with a formatted message build from the repository. -func (s *SlackSender) Send(repository Repository) error { +func (s *SlackSender) Send(repository model.Repository) error { payload := slackPayload{ Username: "GitHub Releases", IconEmoji: ":github:", diff --git a/release.go b/internal/model/release.go similarity index 94% rename from release.go rename to internal/model/release.go index 852ccdd..0f043ef 100644 --- a/release.go +++ b/internal/model/release.go @@ -1,4 +1,4 @@ -package main +package model import ( "net/url" diff --git a/repository.go b/internal/model/repository.go similarity index 93% rename from repository.go rename to internal/model/repository.go index 412b961..779c815 100644 --- a/repository.go +++ b/internal/model/repository.go @@ -1,4 +1,4 @@ -package main +package model import "net/url"