mirror of
https://github.com/drone-plugins/drone-npm.git
synced 2026-06-04 18:23:52 +08:00
Merge pull request #54 from drone-plugins/v2-again
Update to use drone-plugin-lib
This commit is contained in:
@@ -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',
|
||||
]),
|
||||
]
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
def main(ctx):
|
||||
before = testing(ctx)
|
||||
|
||||
stages = [
|
||||
linux(ctx, 'amd64'),
|
||||
linux(ctx, 'arm64'),
|
||||
linux(ctx, 'arm'),
|
||||
]
|
||||
|
||||
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.14',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go run honnef.co/go/tools/cmd/staticcheck ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'lint',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go run golang.org/x/lint/golint -set_exit_status ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'vet',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'go vet ./...',
|
||||
],
|
||||
'volumes': [
|
||||
{
|
||||
'name': 'gopath',
|
||||
'path': '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'test',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'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):
|
||||
docker = {
|
||||
'dockerfile': 'docker/Dockerfile.linux.%s' % (arch),
|
||||
'repo': 'plugins/npm',
|
||||
'username': {
|
||||
'from_secret': 'docker_username',
|
||||
},
|
||||
'password': {
|
||||
'from_secret': 'docker_password',
|
||||
},
|
||||
}
|
||||
|
||||
if ctx.build.event == 'pull_request':
|
||||
docker.update({
|
||||
'dry_run': True,
|
||||
'tags': 'linux-%s' % (arch),
|
||||
})
|
||||
else:
|
||||
docker.update({
|
||||
'auto_tag': True,
|
||||
'auto_tag_suffix': 'linux-%s' % (arch),
|
||||
})
|
||||
|
||||
if ctx.build.event == 'tag':
|
||||
build = [
|
||||
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-npm ./cmd/drone-npm' % (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-npm ./cmd/drone-npm' % (ctx.build.commit[0:8], arch),
|
||||
]
|
||||
|
||||
return {
|
||||
'kind': 'pipeline',
|
||||
'type': 'docker',
|
||||
'name': 'linux-%s' % (arch),
|
||||
'platform': {
|
||||
'os': 'linux',
|
||||
'arch': arch,
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'name': 'environment',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': [
|
||||
'go version',
|
||||
'go env',
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'build',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'environment': {
|
||||
'CGO_ENABLED': '0',
|
||||
},
|
||||
'commands': build,
|
||||
},
|
||||
{
|
||||
'name': 'executable',
|
||||
'image': 'golang:1.14',
|
||||
'pull': 'always',
|
||||
'commands': [
|
||||
'./release/linux/%s/drone-npm --help' % (arch),
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'docker',
|
||||
'image': 'plugins/docker',
|
||||
'pull': 'always',
|
||||
'settings': docker,
|
||||
},
|
||||
],
|
||||
'depends_on': [],
|
||||
'trigger': {
|
||||
'ref': [
|
||||
'refs/heads/master',
|
||||
'refs/tags/**',
|
||||
'refs/pull/**',
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
def manifest(ctx):
|
||||
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(ctx):
|
||||
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/**',
|
||||
],
|
||||
'status': [
|
||||
'failure',
|
||||
],
|
||||
},
|
||||
}]
|
||||
@@ -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']),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
...
|
||||
-332
@@ -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
|
||||
|
||||
...
|
||||
+3
-28
@@ -1,30 +1,5 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
release/
|
||||
vendor/
|
||||
/release/
|
||||
/drone-npm*
|
||||
|
||||
coverage.out
|
||||
drone-npm
|
||||
.drone.yml
|
||||
|
||||
@@ -199,4 +199,3 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-npm/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "NPM username",
|
||||
EnvVars: []string{"PLUGIN_USERNAME", "NPM_USERNAME"},
|
||||
Destination: &settings.Username,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "NPM password",
|
||||
EnvVars: []string{"PLUGIN_PASSWORD", "NPM_PASSWORD"},
|
||||
Destination: &settings.Password,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "email",
|
||||
Usage: "NPM email",
|
||||
EnvVars: []string{"PLUGIN_EMAIL", "NPM_EMAIL"},
|
||||
Destination: &settings.Email,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "token",
|
||||
Usage: "NPM deploy token",
|
||||
EnvVars: []string{"PLUGIN_TOKEN", "NPM_TOKEN"},
|
||||
Destination: &settings.Token,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "registry",
|
||||
Usage: "NPM registry",
|
||||
EnvVars: []string{"PLUGIN_REGISTRY", "NPM_REGISTRY"},
|
||||
Destination: &settings.Registry,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "folder",
|
||||
Usage: "folder containing package.json",
|
||||
EnvVars: []string{"PLUGIN_FOLDER"},
|
||||
Destination: &settings.Folder,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "fail-on-version-conflict",
|
||||
Usage: "fail NPM publish if version already exists in NPM registry",
|
||||
EnvVars: []string{"PLUGIN_FAIL_ON_VERSION_CONFLICT"},
|
||||
Destination: &settings.FailOnVersionConflict,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "tag",
|
||||
Usage: "NPM publish tag",
|
||||
EnvVars: []string{"PLUGIN_TAG"},
|
||||
Destination: &settings.Tag,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "access",
|
||||
Usage: "NPM scoped package access",
|
||||
EnvVars: []string{"PLUGIN_ACCESS"},
|
||||
Destination: &settings.Access,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// DO NOT MODIFY THIS FILE DIRECTLY
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/drone-plugins/drone-npm/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-npm",
|
||||
Usage: "push a package to a npm repository",
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
|
||||
RUN apk add --no-cache git nodejs nodejs-npm
|
||||
|
||||
ADD release/linux/amd64/drone-npm /bin/
|
||||
ENTRYPOINT ["/bin/drone-npm"]
|
||||
ENTRYPOINT [ "/bin/drone-npm" ]
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1803
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone NPM" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
# TODO: install required tools
|
||||
|
||||
ADD release\drone-npm.exe c:\drone-npm.exe
|
||||
ENTRYPOINT [ "c:\\drone-npm.exe" ]
|
||||
@@ -1,12 +0,0 @@
|
||||
# escape=`
|
||||
FROM plugins/base:windows-1809
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone NPM" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
# TODO: install required tools
|
||||
|
||||
ADD release\drone-npm.exe c:\drone-npm.exe
|
||||
ENTRYPOINT [ "c:\\drone-npm.exe" ]
|
||||
+5
-18
@@ -1,37 +1,24 @@
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||
|
||||
{{#if build.tags}}
|
||||
tags:
|
||||
{{#each build.tags}}
|
||||
- {{this}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
manifests:
|
||||
-
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
- image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: linux
|
||||
-
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||
- image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||
platform:
|
||||
architecture: arm64
|
||||
os: linux
|
||||
variant: v8
|
||||
-
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||
- image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||
platform:
|
||||
architecture: arm
|
||||
os: linux
|
||||
variant: v7
|
||||
-
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1803
|
||||
-
|
||||
image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1809
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
module github.com/drone-plugins/drone-npm
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/drone-plugins/drone-plugin-lib v0.3.1
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/sirupsen/logrus v1.3.0
|
||||
github.com/urfave/cli v1.20.0
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
github.com/urfave/cli/v2 v2.2.0
|
||||
)
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.3.1 h1:Br43wRnot2CpDGKPIKOnIxkTsuII5q4xxKROirs5hxc=
|
||||
github.com/drone-plugins/drone-plugin-lib v0.3.1/go.mod h1:ZUKtwSoUmeCj7DXMS3WktDdMAWudW7O6dYAZZRISv4M=
|
||||
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.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
|
||||
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
|
||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "npm plugin"
|
||||
app.Usage = "npm plugin"
|
||||
app.Action = run
|
||||
app.Version = version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "username",
|
||||
Usage: "NPM username",
|
||||
EnvVar: "PLUGIN_USERNAME,NPM_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "NPM password",
|
||||
EnvVar: "PLUGIN_PASSWORD,NPM_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "email",
|
||||
Usage: "NPM email",
|
||||
EnvVar: "PLUGIN_EMAIL,NPM_EMAIL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "token",
|
||||
Usage: "NPM deploy token",
|
||||
EnvVar: "PLUGIN_TOKEN,NPM_TOKEN",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "registry",
|
||||
Usage: "NPM registry",
|
||||
Value: GlobalRegistry,
|
||||
EnvVar: "PLUGIN_REGISTRY,NPM_REGISTRY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "folder",
|
||||
Usage: "folder containing package.json",
|
||||
EnvVar: "PLUGIN_FOLDER",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip_verify",
|
||||
Usage: "skip SSL verification",
|
||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "fail_on_version_conflict",
|
||||
Usage: "fail NPM publish if version already exists in NPM registry",
|
||||
EnvVar: "PLUGIN_FAIL_ON_VERSION_CONFLICT",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "env-file",
|
||||
Usage: "source env file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "tag",
|
||||
Usage: "NPM publish tag",
|
||||
EnvVar: "PLUGIN_TAG",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "access",
|
||||
Usage: "NPM scoped package access",
|
||||
EnvVar: "PLUGIN_ACCESS",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
if c.String("env-file") != "" {
|
||||
_ = godotenv.Load(c.String("env-file"))
|
||||
}
|
||||
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
Token: c.String("token"),
|
||||
Email: c.String("email"),
|
||||
Registry: c.String("registry"),
|
||||
Folder: c.String("folder"),
|
||||
SkipVerify: c.Bool("skip_verify"),
|
||||
FailOnVersionConflict: c.Bool("fail_on_version_conflict"),
|
||||
Tag: c.String("tag"),
|
||||
Access: c.String("access"),
|
||||
},
|
||||
}
|
||||
|
||||
return plugin.Exec()
|
||||
}
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
+177
-166
@@ -1,9 +1,13 @@
|
||||
package main
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
@@ -13,22 +17,23 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type (
|
||||
// Config for the plugin.
|
||||
Config struct {
|
||||
// Settings for the Plugin.
|
||||
Settings struct {
|
||||
Username string
|
||||
Password string
|
||||
Token string
|
||||
Email string
|
||||
Registry string
|
||||
Folder string
|
||||
SkipVerify bool
|
||||
FailOnVersionConflict bool
|
||||
Tag string
|
||||
Access string
|
||||
|
||||
npm *npmPackage
|
||||
}
|
||||
|
||||
npmPackage struct {
|
||||
@@ -40,89 +45,96 @@ type (
|
||||
npmConfig struct {
|
||||
Registry string `json:"registry"`
|
||||
}
|
||||
|
||||
// Plugin values
|
||||
Plugin struct {
|
||||
Config Config
|
||||
}
|
||||
)
|
||||
|
||||
// GlobalRegistry defines the default NPM registry.
|
||||
const GlobalRegistry = "https://registry.npmjs.org/"
|
||||
// globalRegistry defines the default NPM registry.
|
||||
const globalRegistry = "https://registry.npmjs.org/"
|
||||
|
||||
// Exec executes the plugin.
|
||||
func (p Plugin) Exec() error {
|
||||
// write npmrc for authentication
|
||||
err := writeNpmrc(p.Config)
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
// Check authentication options
|
||||
if len(p.settings.Token) == 0 {
|
||||
if len(p.settings.Username) == 0 {
|
||||
return fmt.Errorf("no username provided")
|
||||
}
|
||||
if len(p.settings.Email) == 0 {
|
||||
return fmt.Errorf("no email address provided")
|
||||
}
|
||||
if len(p.settings.Password) == 0 {
|
||||
return fmt.Errorf("no password provided")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"username": p.settings.Username,
|
||||
"email": p.settings.Email,
|
||||
}).Info("Specified credentials")
|
||||
} else {
|
||||
logrus.Info("Token credentials being used")
|
||||
}
|
||||
|
||||
// attempt to authenticate
|
||||
err = authenticate(p.Config)
|
||||
|
||||
// Verify package.json file
|
||||
npm, err := readPackageFile(p.settings.Folder)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("invalid package.json: %w", err)
|
||||
}
|
||||
|
||||
// read the package
|
||||
npmPackage, err := readPackageFile(p.Config)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
// Verify the same registry is being used
|
||||
if len(p.settings.Registry) == 0 {
|
||||
p.settings.Registry = globalRegistry
|
||||
}
|
||||
|
||||
// determine whether to publish
|
||||
publish, err := shouldPublishPackage(p.Config, npmPackage)
|
||||
if strings.Compare(p.settings.Registry, npm.Config.Registry) != 0 {
|
||||
return fmt.Errorf("registry values do not match .drone.yml: %s package.json: %s", p.settings.Registry, npm.Config.Registry)
|
||||
}
|
||||
|
||||
p.settings.npm = npm
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
// Write the npmrc file
|
||||
if err := p.writeNpmrc(); err != nil {
|
||||
return fmt.Errorf("could not create npmrc: %w", err)
|
||||
}
|
||||
|
||||
// Attempt authentication
|
||||
if err := p.authenticate(); err != nil {
|
||||
return fmt.Errorf("could not authenticate: %w", err)
|
||||
}
|
||||
|
||||
// Determine whether to publish
|
||||
publish, err := p.shouldPublishPackage()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("could not determine if package should be published: %w", err)
|
||||
}
|
||||
|
||||
if publish {
|
||||
log.Info("Publishing package")
|
||||
|
||||
// run the publish command
|
||||
return runCommand(publishCommand(p.Config), p.Config.Folder)
|
||||
logrus.Info("Publishing package")
|
||||
if err = runCommand(publishCommand(p.settings), p.settings.Folder); err != nil {
|
||||
return fmt.Errorf("could not publish package: %w", err)
|
||||
}
|
||||
} else {
|
||||
log.Info("Not publishing package")
|
||||
logrus.Info("Not publishing package")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/// writeNpmrc creates a .npmrc in the folder for authentication
|
||||
func writeNpmrc(config Config) error {
|
||||
var npmrcContents string
|
||||
|
||||
// check for an auth token
|
||||
if len(config.Token) == 0 {
|
||||
// check for a username
|
||||
if len(config.Username) == 0 {
|
||||
return errors.New("No username provided")
|
||||
}
|
||||
|
||||
// check for an email
|
||||
if len(config.Email) == 0 {
|
||||
return errors.New("No email address provided")
|
||||
}
|
||||
|
||||
// check for a password
|
||||
if len(config.Password) == 0 {
|
||||
log.Warning("No password provided")
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"username": config.Username,
|
||||
"email": config.Email,
|
||||
func (p *Plugin) writeNpmrc() error {
|
||||
var f func(settings Settings) string
|
||||
if len(p.settings.Token) == 0 {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"username": p.settings.Username,
|
||||
"email": p.settings.Email,
|
||||
}).Info("Specified credentials")
|
||||
|
||||
npmrcContents = npmrcContentsUsernamePassword(config)
|
||||
f = npmrcContentsUsernamePassword
|
||||
} else {
|
||||
log.Info("Token credentials being used")
|
||||
|
||||
npmrcContents = npmrcContentsToken(config)
|
||||
logrus.Info("Token credentials being used")
|
||||
f = npmrcContentsToken
|
||||
}
|
||||
|
||||
// write npmrc file
|
||||
@@ -133,95 +145,15 @@ func writeNpmrc(config Config) error {
|
||||
}
|
||||
npmrcPath := path.Join(home, ".npmrc")
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"path": npmrcPath,
|
||||
}).Info("Writing npmrc")
|
||||
logrus.WithField("path", npmrcPath).Info("Writing npmrc")
|
||||
|
||||
return ioutil.WriteFile(npmrcPath, []byte(npmrcContents), 0644)
|
||||
}
|
||||
|
||||
/// authenticate atempts to authenticate with the NPM registry.
|
||||
func authenticate(config Config) error {
|
||||
var cmds []*exec.Cmd
|
||||
|
||||
// write the version command
|
||||
cmds = append(cmds, versionCommand())
|
||||
|
||||
// write registry command
|
||||
if config.Registry != GlobalRegistry {
|
||||
cmds = append(cmds, registryCommand(config.Registry))
|
||||
}
|
||||
|
||||
// write auth command
|
||||
cmds = append(cmds, alwaysAuthCommand())
|
||||
|
||||
// write skip verify command
|
||||
if config.SkipVerify {
|
||||
cmds = append(cmds, skipVerifyCommand())
|
||||
}
|
||||
|
||||
// write whoami command to verify credentials
|
||||
cmds = append(cmds, whoamiCommand())
|
||||
|
||||
// run commands
|
||||
err := runCommands(cmds, config.Folder)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("Could not authenticate")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/// readPackageFile reads the package file at the given path.
|
||||
func readPackageFile(config Config) (*npmPackage, error) {
|
||||
// read the file
|
||||
packagePath := path.Join(config.Folder, "package.json")
|
||||
file, err := ioutil.ReadFile(packagePath)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// unmarshal the json data
|
||||
npm := npmPackage{}
|
||||
err = json.Unmarshal(file, &npm)
|
||||
|
||||
if len(npm.Config.Registry) == 0 {
|
||||
log.Info("No registry specified in the package.json")
|
||||
npm.Config.Registry = GlobalRegistry
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// make sure values are present
|
||||
if len(npm.Name) == 0 {
|
||||
return nil, errors.New("No package name present")
|
||||
}
|
||||
|
||||
if len(npm.Version) == 0 {
|
||||
return nil, errors.New("No package version present")
|
||||
}
|
||||
|
||||
// check package registry
|
||||
if strings.Compare(config.Registry, npm.Config.Registry) != 0 {
|
||||
return nil, fmt.Errorf("Registry values do not match .drone.yml: %s package.json: %s", config.Registry, npm.Config.Registry)
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"name": npm.Name,
|
||||
"version": npm.Version,
|
||||
}).Info("Found package.json")
|
||||
|
||||
return &npm, nil
|
||||
return ioutil.WriteFile(npmrcPath, []byte(f(p.settings)), 0644)
|
||||
}
|
||||
|
||||
/// shouldPublishPackage determines if the package should be published
|
||||
func shouldPublishPackage(config Config, npm *npmPackage) (bool, error) {
|
||||
cmd := packageVersionsCommand(npm.Name)
|
||||
cmd.Dir = config.Folder
|
||||
func (p *Plugin) shouldPublishPackage() (bool, error) {
|
||||
cmd := packageVersionsCommand(p.settings.npm.Name)
|
||||
cmd.Dir = p.settings.Folder
|
||||
|
||||
trace(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
@@ -234,7 +166,7 @@ func shouldPublishPackage(config Config, npm *npmPackage) (bool, error) {
|
||||
err = json.Unmarshal(out, &versions)
|
||||
|
||||
if err != nil {
|
||||
log.Debug("Could not parse into array of string. Likely single value")
|
||||
logrus.Debug("Could not parse into array of string. Likely single value")
|
||||
|
||||
var version string
|
||||
err := json.Unmarshal(out, &version)
|
||||
@@ -247,30 +179,109 @@ func shouldPublishPackage(config Config, npm *npmPackage) (bool, error) {
|
||||
}
|
||||
|
||||
for _, value := range versions {
|
||||
log.WithFields(log.Fields{
|
||||
"version": value,
|
||||
}).Debug("Found version of package")
|
||||
logrus.WithField("version", value).Debug("Found version of package")
|
||||
|
||||
if strings.Compare(npm.Version, value) == 0 {
|
||||
log.Info("Version found in the registry")
|
||||
if config.FailOnVersionConflict {
|
||||
return false, errors.New("Cannot publish package due to version conflict")
|
||||
if strings.Compare(p.settings.npm.Version, value) == 0 {
|
||||
logrus.Info("Version found in the registry")
|
||||
if p.settings.FailOnVersionConflict {
|
||||
return false, fmt.Errorf("cannot publish package due to version conflict")
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("Version not found in the registry")
|
||||
logrus.Info("Version not found in the registry")
|
||||
} else {
|
||||
log.Info("Name was not found in the registry")
|
||||
logrus.Info("Name was not found in the registry")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
/// authenticate atempts to authenticate with the NPM registry.
|
||||
func (p *Plugin) authenticate() error {
|
||||
var cmds []*exec.Cmd
|
||||
|
||||
// Write the version command
|
||||
cmds = append(cmds, versionCommand())
|
||||
|
||||
// write registry command
|
||||
if p.settings.Registry != globalRegistry {
|
||||
cmds = append(cmds, registryCommand(p.settings.Registry))
|
||||
}
|
||||
|
||||
// Write auth command
|
||||
cmds = append(cmds, alwaysAuthCommand())
|
||||
|
||||
// Write skip verify command
|
||||
if p.network.SkipVerify {
|
||||
cmds = append(cmds, skipVerifyCommand())
|
||||
}
|
||||
|
||||
// Write whoami command to verify credentials
|
||||
cmds = append(cmds, whoamiCommand())
|
||||
|
||||
// Run commands
|
||||
err := runCommands(cmds, p.settings.Folder)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/// readPackageFile reads the package file at the given path.
|
||||
func readPackageFile(folder string) (*npmPackage, error) {
|
||||
// Verify package.json file exists
|
||||
packagePath := path.Join(folder, "package.json")
|
||||
info, err := os.Stat(packagePath)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("no package.json at %s: %w", packagePath, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil, fmt.Errorf("the package.json at %s is a directory", packagePath)
|
||||
}
|
||||
|
||||
// Read the file
|
||||
file, err := ioutil.ReadFile(packagePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read package.json at %s: %w", packagePath, err)
|
||||
}
|
||||
|
||||
// Unmarshal the json data
|
||||
npm := npmPackage{}
|
||||
err = json.Unmarshal(file, &npm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make sure values are present
|
||||
if len(npm.Name) == 0 {
|
||||
return nil, fmt.Errorf("no package name present")
|
||||
}
|
||||
if len(npm.Version) == 0 {
|
||||
return nil, fmt.Errorf("no package version present")
|
||||
}
|
||||
|
||||
// Set the default registry
|
||||
if len(npm.Config.Registry) == 0 {
|
||||
npm.Config.Registry = globalRegistry
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"name": npm.Name,
|
||||
"version": npm.Version,
|
||||
"path": packagePath,
|
||||
}).Info("Found package.json")
|
||||
|
||||
return &npm, nil
|
||||
}
|
||||
|
||||
// npmrcContentsUsernamePassword creates the contents from a username and
|
||||
// password
|
||||
func npmrcContentsUsernamePassword(config Config) string {
|
||||
func npmrcContentsUsernamePassword(config Settings) string {
|
||||
// get the base64 encoded string
|
||||
authString := fmt.Sprintf("%s:%s", config.Username, config.Password)
|
||||
encoded := base64.StdEncoding.EncodeToString([]byte(authString))
|
||||
@@ -280,7 +291,7 @@ func npmrcContentsUsernamePassword(config Config) string {
|
||||
}
|
||||
|
||||
/// Writes npmrc contents when using a token
|
||||
func npmrcContentsToken(config Config) string {
|
||||
func npmrcContentsToken(config Settings) string {
|
||||
registry, _ := url.Parse(config.Registry)
|
||||
registry.Scheme = "" // Reset the scheme to empty. This makes it so we will get a protocol relative URL.
|
||||
registryString := registry.String()
|
||||
@@ -322,15 +333,15 @@ func packageVersionsCommand(name string) *exec.Cmd {
|
||||
}
|
||||
|
||||
// publishCommand runs the publish command
|
||||
func publishCommand(config Config) *exec.Cmd {
|
||||
func publishCommand(settings Settings) *exec.Cmd {
|
||||
commandArgs := []string{"publish"}
|
||||
|
||||
if len(config.Tag) != 0 {
|
||||
commandArgs = append(commandArgs, "--tag", config.Tag)
|
||||
if len(settings.Tag) != 0 {
|
||||
commandArgs = append(commandArgs, "--tag", settings.Tag)
|
||||
}
|
||||
|
||||
if len(config.Access) != 0 {
|
||||
commandArgs = append(commandArgs, "--access", config.Access)
|
||||
if len(settings.Access) != 0 {
|
||||
commandArgs = append(commandArgs, "--access", settings.Access)
|
||||
}
|
||||
|
||||
return exec.Command("npm", commandArgs...)
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||
)
|
||||
|
||||
// Plugin implements drone.Plugin to provide the plugin implementation.
|
||||
type Plugin struct {
|
||||
settings Settings
|
||||
pipeline drone.Pipeline
|
||||
network drone.Network
|
||||
}
|
||||
|
||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
||||
return &Plugin{
|
||||
settings: settings,
|
||||
pipeline: pipeline,
|
||||
network: network,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
||||
// Please see the AUTHORS file for details. All rights reserved.
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTokenRCContents(t *testing.T) {
|
||||
settings := Settings{
|
||||
Registry: "https://npm.someorg.com/",
|
||||
Token: "token",
|
||||
}
|
||||
actual := npmrcContentsToken(settings)
|
||||
expected := "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com/with/path/"
|
||||
actual = npmrcContentsToken(settings)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = globalRegistry
|
||||
actual = npmrcContentsToken(settings)
|
||||
expected = "//registry.npmjs.org/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com"
|
||||
actual = npmrcContentsToken(settings)
|
||||
expected = "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
settings.Registry = "https://npm.someorg.com/with/path"
|
||||
actual = npmrcContentsToken(settings)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTokenRCContents(t *testing.T) {
|
||||
conf := Config{
|
||||
Registry: "https://npm.someorg.com/",
|
||||
Token: "token",
|
||||
}
|
||||
actual := npmrcContentsToken(conf)
|
||||
expected := "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token config (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
conf.Registry = "https://npm.someorg.com/with/path/"
|
||||
actual = npmrcContentsToken(conf)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token config (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
conf.Registry = GlobalRegistry
|
||||
actual = npmrcContentsToken(conf)
|
||||
expected = "//registry.npmjs.org/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token config (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
conf.Registry = "https://npm.someorg.com"
|
||||
actual = npmrcContentsToken(conf)
|
||||
expected = "//npm.someorg.com/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token config (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
|
||||
conf.Registry = "https://npm.someorg.com/with/path"
|
||||
actual = npmrcContentsToken(conf)
|
||||
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
||||
if actual != expected {
|
||||
t.Errorf("Unexpected token config (Got: %s, Expected: %s)", actual, expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user