(maint) move to harness.drone.io

This commit is contained in:
TP Honey
2022-12-15 12:01:27 +00:00
parent 8f610a8a9f
commit 0a3ecfe895
11 changed files with 241 additions and 294 deletions
-195
View File
@@ -1,195 +0,0 @@
def main(ctx):
before = testing(ctx)
stages = [
linux(ctx, 'amd64'),
linux(ctx, 'arm64'),
linux(ctx, 'arm'),
]
after = manifest(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': 'lint',
'image': 'golang:1.18',
'pull': 'always',
'commands': [
"go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest",
"golangci-lint version",
"golangci-lint run",
],
'volumes': [
{
'name': 'gopath',
'path': '/go',
},
],
},
{
'name': 'test',
'image': 'golang:1.18',
'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.18',
'pull': 'always',
'environment': {
'CGO_ENABLED': '0',
},
'commands': [
'go version',
'go env',
],
},
{
'name': 'build',
'image': 'golang:1.18',
'pull': 'always',
'environment': {
'CGO_ENABLED': '0',
},
'commands': build,
},
{
'name': 'executable',
'image': 'golang:1.18',
'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',
},
},
],
'depends_on': [],
'trigger': {
'ref': [
'refs/heads/master',
'refs/tags/**',
],
},
}]
+153
View File
@@ -0,0 +1,153 @@
kind: pipeline
type: vm
name: testing
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: lint
image: golang:1.19
pull: always
commands:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- golangci-lint version
- golangci-lint run
volumes:
- name: gopath
path: "/go"
- name: test
image: golang:1.19
commands:
- go test -cover ./...
volumes:
- name: gopath
path: "/go"
volumes:
- name: gopath
temp: {}
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
type: vm
name: linux-amd64
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: environment
image: golang:1.19
pull: always
environment:
CGO_ENABLED: "0"
commands:
- go version
- go env
- name: build
image: golang:1.19
environment:
CGO_ENABLED: "0"
commands:
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-npm .
- name: docker
image: plugins/docker
settings:
dockerfile: docker/Dockerfile.linux.amd64
repo: plugins/npm
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true
auto_tag_suffix: linux-amd64
depends_on:
- testing
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
type: vm
name: linux-arm64
platform:
os: linux
arch: arm64
pool:
use: ubuntu_arm64
steps:
- name: environment
image: golang:1.19
pull: always
environment:
CGO_ENABLED: "0"
commands:
- go version
- go env
- name: build
image: golang:1.19
environment:
CGO_ENABLED: "0"
commands:
- go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-npm .
- name: docker
image: plugins/docker
settings:
dockerfile: docker/Dockerfile.linux.arm64
repo: plugins/npm
username:
from_secret: docker_username
password:
from_secret: docker_password
auto_tag: true
auto_tag_suffix: linux-arm64
depends_on:
- testing
trigger:
ref:
- refs/heads/master
- refs/tags/**
- refs/pull/**
---
kind: pipeline
type: vm
name: manifest
platform:
os: linux
arch: amd64
pool:
use: ubuntu
steps:
- name: manifest
image: plugins/manifest
settings:
auto_tag: "true"
username:
from_secret: docker_username
password:
from_secret: docker_password
spec: docker/manifest.tmpl
ignore_missing: true
depends_on:
- linux-amd64
- linux-arm64
trigger:
ref:
- refs/heads/master
- refs/tags/**
-1
View File
@@ -2,4 +2,3 @@
/drone-npm*
coverage.out
.drone.yml
-70
View File
@@ -1,70 +0,0 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
// DO NOT MODIFY THIS FILE DIRECTLY
package main
import (
"os"
"github.com/drone-plugins/drone-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") //nolint:errcheck
}
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)
p := plugin.New(
*settings,
urfave.PipelineFromContext(ctx),
urfave.NetworkFromContext(ctx),
)
if err := p.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("validation failed: %w", err)
}
if err := p.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
}
return nil
}
}
-11
View File
@@ -1,11 +0,0 @@
FROM plugins/base:linux-arm
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"
RUN apk add --no-cache git nodejs npm
ADD release/linux/arm/drone-npm /bin/
ENTRYPOINT [ "/bin/drone-npm" ]
-5
View File
@@ -17,8 +17,3 @@ manifests:
architecture: arm64
os: linux
variant: v8
- image: plugins/npm:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7
+10 -3
View File
@@ -1,10 +1,17 @@
module github.com/drone-plugins/drone-npm
go 1.16
go 1.19
require (
github.com/drone-plugins/drone-plugin-lib v0.4.0
github.com/joho/godotenv v1.4.0
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli/v2 v2.8.1
github.com/sirupsen/logrus v1.9.0
github.com/urfave/cli/v2 v2.23.7
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.3.0 // indirect
)
+13 -4
View File
@@ -1,8 +1,10 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
@@ -21,12 +23,18 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY=
github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -36,11 +44,12 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
+59
View File
@@ -3,13 +3,72 @@
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
// DO NOT MODIFY THIS FILE DIRECTLY
package main
import (
"os"
"github.com/drone-plugins/drone-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") //nolint:errcheck
}
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)
p := plugin.New(
*settings,
urfave.PipelineFromContext(ctx),
urfave.NetworkFromContext(ctx),
)
if err := p.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("validation failed: %w", err)
}
if err := p.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
}
return nil
}
}
// settingsFlags has the cli.Flags for the plugin.Settings.
func settingsFlags(settings *plugin.Settings) []cli.Flag {
return []cli.Flag{
+5 -5
View File
@@ -124,7 +124,7 @@ func (p *Plugin) Execute() error {
return nil
}
/// writeNpmrc creates a .npmrc in the folder for authentication
// / writeNpmrc creates a .npmrc in the folder for authentication
func (p *Plugin) writeNpmrc() error {
var f func(settings *Settings) string
if p.settings.Token == "" {
@@ -151,7 +151,7 @@ func (p *Plugin) writeNpmrc() error {
return os.WriteFile(npmrcPath, []byte(f(&p.settings)), 0644) //nolint:gomnd
}
/// shouldPublishPackage determines if the package should be published
// / shouldPublishPackage determines if the package should be published
func (p *Plugin) shouldPublishPackage() (bool, error) {
cmd := packageVersionsCommand(p.settings.npm.Name)
cmd.Dir = p.settings.Folder
@@ -199,7 +199,7 @@ func (p *Plugin) shouldPublishPackage() (bool, error) {
return true, nil
}
/// authenticate atempts to authenticate with the NPM registry.
// / authenticate atempts to authenticate with the NPM registry.
func (p *Plugin) authenticate() error {
var cmds []*exec.Cmd
@@ -234,7 +234,7 @@ func (p *Plugin) authenticate() error {
return nil
}
/// readPackageFile reads the package file at the given path.
// / 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")
@@ -293,7 +293,7 @@ func npmrcContentsUsernamePassword(config *Settings) string {
return fmt.Sprintf("_auth = %s\nemail = %s", encoded, config.Email)
}
/// Writes npmrc contents when using a token
// / Writes npmrc contents when using a token
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.
+1
View File
@@ -17,6 +17,7 @@ type Plugin struct {
}
// New initializes a plugin from the given Settings, Pipeline, and Network.
//
//nolint:gocritic
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
return &Plugin{