From 09fe408713a0b51bf10cecdde75abad569c33c25 Mon Sep 17 00:00:00 2001 From: Don Date: Wed, 18 Dec 2019 16:22:44 -0800 Subject: [PATCH] Add Starlark support --- .drone.jsonnet | 14 -- .drone.star | 267 +++++++++++++++++++++++++++++++++ .drone.windows.jsonnet | 9 -- .drone.windows.yml | 273 --------------------------------- .drone.yml | 332 ----------------------------------------- pipeline.libsonnet | 205 ------------------------- 6 files changed, 267 insertions(+), 833 deletions(-) delete mode 100644 .drone.jsonnet create mode 100644 .drone.star delete mode 100644 .drone.windows.jsonnet delete mode 100644 .drone.windows.yml delete mode 100644 .drone.yml delete mode 100644 pipeline.libsonnet diff --git a/.drone.jsonnet b/.drone.jsonnet deleted file mode 100644 index 82d4380..0000000 --- a/.drone.jsonnet +++ /dev/null @@ -1,14 +0,0 @@ -local pipeline = import 'pipeline.libsonnet'; -local name = 'drone-npm'; - -[ - 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..1e978db --- /dev/null +++ b/.drone.star @@ -0,0 +1,267 @@ +# drone-npm build + +def main(ctx): + before = testing() + + stages = [ + linux('amd64'), + linux('arm64'), + linux('arm'), + + ] + + after = manifest() + gitter() + + 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.13', + 'pull': 'always', + 'commands': [ + 'go version', + 'go vet ./...' + ], + 'volumes': [ + { + 'name': 'gopath', + 'path': '/go' + } + ] + }, + { + 'name': 'test', + 'image': 'golang:1.13', + 'pull': 'always', + 'commands': [ + 'go version', + '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': 'linux-%s' % arch, + 'platform': { + 'os': 'linux', + 'arch': arch, + }, + 'steps': [ + { + 'name': 'build-push', + 'image': 'golang:1.13', + 'pull': 'always', + 'environment': { + 'CGO_ENABLED': '0' + }, + 'commands': [ + 'go version', + 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/%s/drone-npm ./cmd/drone-npm' % arch, + ], + 'when': { + 'event': { + 'exclude': [ + 'tag' + ] + } + } + }, + { + 'name': 'build-tag', + 'image': 'golang:1.13', + 'pull': 'always', + 'environment': { + 'CGO_ENABLED': '0' + }, + 'commands': [ + 'go version', + 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/%s/drone-npm ./cmd/drone-npm' % arch, + ], + 'when': { + 'event': [ + 'tag' + ] + } + }, + { + 'name': 'executable', + 'image': 'golang:1.13', + 'pull': 'always', + 'commands': [ + './release/linux/%s/drone-npm --help' % arch + ] + }, + { + 'name': 'dryrun', + 'image': 'plugins/docker', + 'pull': 'always', + 'settings': { + 'dry_run': True, + 'tags': 'linux-%s' % arch, + 'dockerfile': 'docker/Dockerfile.linux.%s' % arch, + 'repo': 'plugins/npm', + 'username': { + 'from_secret': 'docker_username' + }, + 'password': { + 'from_secret': 'docker_password' + } + }, + 'when': { + 'event': [ + 'pull_request' + ] + } + }, + { + 'name': 'publish', + 'image': 'plugins/docker', + 'pull': 'always', + 'settings': { + 'auto_tag': True, + 'auto_tag_suffix': 'linux-%s' % arch, + 'dockerfile': 'docker/Dockerfile.linux.%s' % arch, + 'repo': 'plugins/npm', + '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 manifest(): + return [{ + 'kind': 'pipeline', + 'type': 'docker', + 'name': 'manifest', + 'steps': [ + { + 'name': 'manifest', + 'image': 'plugins/manifest', + 'pull': 'always', + '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', + 'pull': 'always', + 'settings': { + 'urls': { + 'from_secret': 'microbadger_url' + } + }, + } + ], + 'depends_on': [], + 'trigger': { + 'ref': [ + 'refs/heads/master', + 'refs/tags/**' + ] + } + }] + +def gitter(): + return [{ + 'kind': 'pipeline', + 'type': 'docker', + 'name': 'gitter', + 'clone': { + 'disable': True + }, + 'steps': [ + { + 'name': 'gitter', + 'image': 'plugins/gitter', + 'pull': 'always', + 'settings': { + 'webhook': { + 'from_secret': 'gitter_webhook' + } + }, + }, + ], + 'depends_on': [ + 'manifest' + ], + 'trigger': { + 'ref': [ + 'refs/heads/master', + 'refs/tags/**', + 'refs/pull/**' + ], + 'status': [ + 'failure' + ] + } + }] diff --git a/.drone.windows.jsonnet b/.drone.windows.jsonnet deleted file mode 100644 index 0dff5c8..0000000 --- a/.drone.windows.jsonnet +++ /dev/null @@ -1,9 +0,0 @@ -local pipeline = import 'pipeline.libsonnet'; -local name = 'drone-npm'; - -[ - 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 c67a6cd..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-npm.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-npm.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-npm.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/npm - 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/npm - 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-npm.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-npm.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-npm.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/npm - 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/npm - 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 26a4074..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-npm" - 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-npm" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/amd64/drone-npm --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/npm - 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/npm - 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-npm" - 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-npm" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/arm64/drone-npm --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/npm - 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/npm - 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-npm" - 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-npm" - environment: - CGO_ENABLED: 0 - GO111MODULE: on - when: - event: - - tag - -- name: executable - pull: always - image: golang:1.11 - commands: - - ./release/linux/arm/drone-npm --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/npm - 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/npm - 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/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, - }, -}