0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-11-21 04:00:40 +00:00

refactor: initial commit after rewrite to woodpecker

This commit is contained in:
Robert Kaussow 2023-08-11 12:27:16 +02:00
parent 00a13d659b
commit 8816f37595
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
48 changed files with 1032 additions and 1750 deletions

View File

@ -2,7 +2,7 @@ style: github
template: CHANGELOG.tpl.md template: CHANGELOG.tpl.md
info: info:
title: CHANGELOG title: CHANGELOG
repository_url: https://github.com/thegeeklab/drone-plugin-lib repository_url: https://github.com/thegeeklab/wp-plugin-go
options: options:
commit_groups: commit_groups:
title_maps: title_maps:

View File

@ -1,161 +0,0 @@
---
kind: pipeline
name: test
platform:
os: linux
arch: amd64
steps:
- name: deps
image: golang:1.20
commands:
- make deps
volumes:
- name: godeps
path: /go
- name: lint
image: golang:1.20
commands:
- make lint
volumes:
- name: godeps
path: /go
- name: test
image: golang:1.20
commands:
- make test
volumes:
- name: godeps
path: /go
volumes:
- name: godeps
temp: {}
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
---
kind: pipeline
name: release
platform:
os: linux
arch: amd64
steps:
- name: changelog-generate
image: thegeeklab/git-chglog
commands:
- git fetch -tq
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}
- name: changelog-format
image: thegeeklab/alpine-tools
commands:
- prettier CHANGELOG.md
- prettier -w CHANGELOG.md
- name: publish
image: plugins/github-release
settings:
api_key:
from_secret: github_token
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
image_pull_secrets:
- docker_config
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- test
---
kind: pipeline
name: docs
platform:
os: linux
arch: amd64
steps:
- name: markdownlint
image: thegeeklab/markdownlint-cli
commands:
- markdownlint 'README.md' 'CONTRIBUTING.md'
- name: spellcheck
image: thegeeklab/alpine-tools
commands:
- spellchecker --files 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions
environment:
FORCE_COLOR: true
NPM_CONFIG_LOGLEVEL: error
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- release
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: matrix
image: thegeeklab/drone-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}"
username:
from_secret: matrix_username
when:
status:
- success
- failure
trigger:
ref:
- refs/heads/main
- refs/tags/**
status:
- success
- failure
depends_on:
- docs
---
kind: signature
hmac: 1821966cd39f3db56d3ac90e1c75f488b9eb09644791399a2a259a008d8a2985
...

10
.github/settings.yml vendored
View File

@ -1,7 +1,7 @@
repository: repository:
name: drone-plugin-lib name: wp-plugin-go
description: Helper library for writing Drone CI plugins description: Helper library for writing Woodpecker CI plugins
topics: drone, drone-plugin topics: woodpecker, wp-plugin
private: false private: false
has_issues: true has_issues: true
@ -50,7 +50,9 @@ branches:
required_status_checks: required_status_checks:
strict: false strict: false
contexts: contexts:
- continuous-integration/drone/pr - ci/woodpecker/pr/test
- ci/woodpecker/pr/release
- ci/woodpecker/pr/container
enforce_admins: true enforce_admins: true
required_linear_history: true required_linear_history: true
restrictions: null restrictions: null

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
/dist/ /dist/
/release/ /release/
/drone-plugin-lib* /wp-plugin-go*
coverage.out coverage.out
CHANGELOG.md CHANGELOG.md

View File

@ -95,3 +95,7 @@ linters-settings:
gofumpt: gofumpt:
extra-rules: true extra-rules: true
lang-version: "1.20" lang-version: "1.20"
tagliatelle:
case:
rules:
json: snake

View File

@ -1,3 +1,2 @@
.drone.yml
*.tpl.md *.tpl.md
LICENSE LICENSE

31
.woodpecker/notify.yml Normal file
View File

@ -0,0 +1,31 @@
---
when:
- event: [tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
runs_on: [success, failure]
steps:
matrix:
image: quay.io/thegeeklab/drone-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: >-
Status: **{{ .Build.Status }}**<br/>
Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/>
Message: {{ .Commit.Message.Title }}
username:
from_secret: matrix_username
when:
- status: [success, failure]
depends_on:
- test
- release

41
.woodpecker/release.yml Normal file
View File

@ -0,0 +1,41 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
checksum:
image: docker.io/alpine
commands:
- sha256sum retry > sha256sum.txt
changelog-generate:
image: quay.io/thegeeklab/git-chglog
commands:
- git fetch -tq
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${CI_COMMIT_TAG:---next-tag unreleased unreleased}
changelog-format:
image: quay.io/thegeeklab/alpine-tools
commands:
- prettier CHANGELOG.md
- prettier -w CHANGELOG.md
publish-github:
image: docker.io/plugins/github-release
settings:
api_key:
from_secret: github_token
files:
- retry
- sha256sum.txt
note: CHANGELOG.md
overwrite: true
title: ${CI_COMMIT_TAG}
when:
- event: [tag]
depends_on:
- test

22
.woodpecker/test.yml Normal file
View File

@ -0,0 +1,22 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
deps:
image: docker.io/library/golang:1.20
commands:
- make deps
lint:
image: docker.io/library/golang:1.20
commands:
- make lint
test:
image: docker.io/library/golang:1.20
commands:
- make test

View File

@ -3,7 +3,7 @@ GOFUMPT_PACKAGE_VERSION := v0.5.0
# renovate: datasource=github-releases depName=golangci/golangci-lint # renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.53.3 GOLANGCI_LINT_PACKAGE_VERSION := v1.53.3
EXECUTABLE := drone-plugin-lib EXECUTABLE := wp-plugin-go
DIST := dist DIST := dist
DIST_DIRS := $(DIST) DIST_DIRS := $(DIST)
@ -30,8 +30,8 @@ endif
TAGS ?= netgo TAGS ?= netgo
ifndef VERSION ifndef VERSION
ifneq ($(DRONE_TAG),) ifneq ($(CI_COMMIT_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG)) VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
else else
VERSION ?= $(shell git rev-parse --short HEAD) VERSION ?= $(shell git rev-parse --short HEAD)
endif endif

View File

@ -1,35 +1,31 @@
# drone-plugin-lib # wp-plugin-go
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-plugin-lib?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-plugin-lib) [![Build Status](https://ci.thegeeklab.de/api/badges/thegeeklab/wp-plugin-go/status.svg)](https://ci.thegeeklab.de/repos/thegeeklab/wp-plugin-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/drone-plugin-lib)](https://goreportcard.com/report/github.com/thegeeklab/drone-plugin-lib) [![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/wp-plugin-go)](https://goreportcard.com/report/github.com/thegeeklab/wp-plugin-go)
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-plugin-lib)](https://github.com/thegeeklab/drone-plugin-lib/graphs/contributors) [![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/wp-plugin-go)](https://github.com/thegeeklab/wp-plugin-go/graphs/contributors)
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-plugin-lib) [![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/wp-plugin-go)
[![License: Apache-2.0](https://img.shields.io/github/license/thegeeklab/drone-plugin-lib)](https://github.com/thegeeklab/drone-plugin-lib/blob/main/LICENSE) [![License: Apache-2.0](https://img.shields.io/github/license/thegeeklab/wp-plugin-go)](https://github.com/thegeeklab/wp-plugin-go/blob/main/LICENSE)
Helper library to reduce the boilerplate code for writing Drone CI plugins. Helper library to reduce the boilerplate code for writing Woodpecker CI plugins.
## Usage ## Usage
### Download the package ### Download the package
```Shell ```Shell
go get -d github.com/thegeeklab/drone-plugin-lib/v2/errors go get -d github.com/thegeeklab/wp-plugin-go/woodpecker
go get -d github.com/thegeeklab/drone-plugin-lib/v2/urfave
go get -d github.com/thegeeklab/drone-plugin-lib/v2/drone
``` ```
### Import the package ### Import the package
```Go ```Go
import "github.com/thegeeklab/drone-plugin-lib/v2/errors" import "github.com/thegeeklab/wp-plugin-go/woodpecker"
import "github.com/thegeeklab/drone-plugin-lib/v2/urfave"
import "github.com/thegeeklab/drone-plugin-lib/v2/drone"
``` ```
## Contributors ## Contributors
Special thanks to all [contributors](https://github.com/thegeeklab/drone-plugin-lib/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/drone-plugin-lib/blob/main/CONTRIBUTING.md). Special thanks to all [contributors](https://github.com/thegeeklab/wp-plugin-go/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/wp-plugin-go/blob/main/CONTRIBUTING.md).
## License ## License
This project is licensed under the Apache-2.0 License - see the [LICENSE](https://github.com/thegeeklab/drone-plugin-lib/blob/main/LICENSE) file for details. This project is licensed under the Apache-2.0 License - see the [LICENSE](https://github.com/thegeeklab/wp-plugin-go/blob/main/LICENSE) file for details.

View File

@ -1,69 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
import (
"time"
)
// Build represents a build of a repository.
type Build struct {
// Branch defines the branch name of the build.
Branch string
// PullRequest number of the build.
PullRequest int
// Tag of the build.
Tag string
// SourceBranch for the pull request.
SourceBranch string
// TargetBranch for the pull request.
TargetBranch string
// Number for the build.
Number int
// Parent build number for the build.
Parent int
// Event that triggered the build.
Event string
// Action that triggered the build. This value is used to differentiate
// bettween a pull request being opened vs synchronized.
Action string
// Status of the build.
Status string
// Link to the build.
Link string
// Created time of the build.
Created time.Time
// Started time of the build.
Started time.Time
// Finished time of the build.
Finished time.Time
// DeployTo the environment.
DeployTo string
// DeployID for the environment.
DeployID int
// FailedStages of the build.
FailedStages []string
// FailedSteps of the build.
FailedSteps []string
}

View File

@ -1,33 +0,0 @@
// Copyright (c) 2020, the Drone Plugins project authors.
package drone
// CalVer represents the calendar version of the currently running build.
//
// This value is only applicable for tags. If the tag cannot be parsed into
// a calendar version then the value will be empty.
type CalVer struct {
// Version is the full calendar version.
Version string
// Major is the major version.
Major string
// Minor is the minor version.
Minor string
// Micro is the micro version.
Micro string
// Modifier is a modifier for the version.
Modifier string
// Short is the short version.
//
// This does not include the modifier.
Short string
}
func (c CalVer) String() string {
return c.Version
}

View File

@ -1,85 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
import "strings"
type (
// Commit represents the current commit being built.
Commit struct {
// SHA for the current commit.
SHA string
// Before contains the commit sha before the patch is applied.
Before string
// After contains the commit sha after the patch is applied.
After string
// Ref for the current commit.
Ref string
// Branch target for the push or pull request. This may be empty for
// tag events.
Branch string
// Link to the commit or object in the source control management system.
Link string
// Message for the current commit.
Message Message
// Author of the commit.
Author Author
}
// Author of a Commit.
Author struct {
// Username of the Commit author.
Username string
// Name of the Commit author.
Name string
// Email for the Commit author.
Email string
// Avatar for the Commit author.
Avatar string
}
// Message for a Commit.
Message struct {
// Title for the Commit.
Title string
// Body of the Commit message.
Body string
}
)
func (c Commit) String() string {
return c.SHA
}
func (a Author) String() string {
return a.Username
}
func (m Message) String() string {
if m.Body == "" {
return m.Title
}
return m.Title + "\n\n" + m.Body
}
// ParseMessage takes a full commit message and translates it into a Message.
func ParseMessage(msg string) Message {
splitMsg := strings.Split(msg, "\n")
return Message{
Title: strings.TrimSpace(splitMsg[0]),
Body: strings.TrimSpace(strings.Join(splitMsg[1:], "\n")),
}
}

View File

@ -1,28 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
import (
"context"
"net/http"
)
// Network contains options for connecting to the network.
type Network struct {
// Context for making network requests.
//
// If `trace` logging is requested the context will use `httptrace` to
// capture all network requests.
//nolint:containedctx
Context context.Context
/// Whether SSL verification is skipped
SkipVerify bool
// Client for making network requests.
Client *http.Client
}

View File

@ -1,21 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// Pipeline being executed.
//
// Represents the full Drone environment that the plugin is executing in.
type Pipeline struct {
Build Build
Repo Repo
Commit Commit
Stage Stage
Step Step
SemVer SemVer
CalVer CalVer
System System
}

View File

@ -1,33 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// Plugin is an interface for a Drone plugin written in Go.
//
// This is a higly opinionated interface for what a Plugin should do. Its
// not required that a plugin author follow it.
type Plugin interface {
// Validate checks the inputs to the Plugin and verifies that the
// configuration is correct before executing.
//
// An error is returned if there are any issues with the current
// configuration, such as missing information or files not being
// present. A Plugin may choose to populate additional information to
// ensure a successful execution, for example if a URL is parsed
// successfully it can be stored off for later use.
//
// Validate needs to be called before Execute.
Validate() error
// Execute runs the plugin in the current configuration.
//
// An error is returned if the Plugin did not run successfully that
// describes the runtime error.
//
// Execute needs to be called after Validate.
Execute() error
}

View File

@ -1,44 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// Repo represents the repository for the build.
type Repo struct {
// Slug for the full name of a repo.
Slug string
// SCM for the used SCM.
SCM string
// Owner for the repo owner.
Owner string
// Name for the repo name.
Name string
// Link for the link to the repo.
Link string
// Branch for the default branch of the repo.
Branch string
// HTTPURL for the clone URL via HTTP.
HTTPURL string
// SSHURL for the clone URL via SSH
SSHURL string
// Visbility for the visbility of the repo.
Visibility string
// Private to show if the repo is private.
Private bool
}
func (r Repo) String() string {
return r.Slug
}

View File

@ -1,44 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// SemVer represents the semantic version of the currently running build.
//
// This value is only applicable for tags. If the tag cannot be parsed into
// a semantic version then SemVer.Error will have the reason.
type SemVer struct {
// Version is the full semantic version.
Version string
// Major version number.
Major string
// Minor version number.
Minor string
// Patch version number.
Patch string
// Prerelease version.
Prerelease string
// Build version number.
//
// This is signified by a + at the end of the tag.
Build string
// Short version of the semantic version string where labels and
// metadata are truncated.
Short string
// Error is the semantic version parsing error if the tag was invalid.
Error string
}
func (s SemVer) String() string {
return s.Version
}

View File

@ -1,67 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
import "time"
// Stage represents a build stage.
type Stage struct {
// Kind is the kind of resource being executed.
//
// This value is sourced from the `kind` attribute in the yaml
// configuration file
Kind string
// Type is the type of resource being executed.
Type string
// Name is the name for the current running build stage.
Name string
// Number is the stage number for the current running build stage.
Number int
// Machine provides the name of the host machine on which the build
// stage is currently running.
Machine string
// OS is the target operating system for the current build stage.
OS string
// Arch is the platform architecture of the current build stage.
Arch string
// Variant is the target architecture variant for the current build
// stage.
Variant string
// Version is OS version for the current build stage.
Version string
// Status is the status for the current running build stage.
//
// If all of the stage's steps are passing, the status defaults to
// success.
Status string
// Started is the unix timestamp for when a build stage was started by
// the runner.
Started time.Time
// Finished is the unix timestamp for when the pipeline is finished.
//
// A running pipleine cannot have a finish timestamp, therefore, the
// system aways sets this value to the current timestamp.
Finished time.Time
// DependsOn is a list of dependencies for the current build stage.
DependsOn []string
}
func (s Stage) String() string {
return s.Name
}

View File

@ -1,20 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// Step represents the currently running step within the stage.
type Step struct {
// Name for the name of the current step.
Name string
// Number is the numeric value of the step.
Number int
}
func (s Step) String() string {
return s.Name
}

View File

@ -1,23 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package drone
// System represents the available system variables.
type System struct {
// Proto for the system protocol.
Proto string
// Host for the system host name.
Host string
// Version for the system version.
Version string
}
func (s System) String() string {
return s.Host
}

9
go.mod
View File

@ -1,11 +1,13 @@
module github.com/thegeeklab/drone-plugin-lib/v2 module github.com/thegeeklab/wp-plugin-go/woodpecker
go 1.20 go 1.20
require ( require (
github.com/Masterminds/sprig/v3 v3.2.3 github.com/Masterminds/sprig/v3 v3.2.3
github.com/sirupsen/logrus v1.9.3 github.com/joho/godotenv v1.5.1
github.com/rs/zerolog v1.30.0
github.com/urfave/cli/v2 v2.25.5 github.com/urfave/cli/v2 v2.25.5
golang.org/x/net v0.2.0
) )
require ( require (
@ -15,11 +17,14 @@ require (
github.com/google/uuid v1.1.1 // indirect github.com/google/uuid v1.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect github.com/imdario/mergo v0.3.11 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cast v1.3.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.3.0 // indirect golang.org/x/crypto v0.3.0 // indirect
golang.org/x/sys v0.2.0 // indirect golang.org/x/sys v0.2.0 // indirect

18
go.sum
View File

@ -4,29 +4,39 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= 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/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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -47,14 +57,16 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View File

@ -1,118 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package trace
import (
"context"
"crypto/tls"
"net/http/httptrace"
"net/textproto"
"github.com/sirupsen/logrus"
)
// HTTP uses httptrace to log all network activity for HTTP requests.
func HTTP(ctx context.Context) context.Context {
return httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
GetConn: func(hostPort string) {
logrus.WithField("host-port", hostPort).Trace("ClientTrace.GetConn")
},
GotConn: func(connInfo httptrace.GotConnInfo) {
logrus.WithFields(logrus.Fields{
"local-address": connInfo.Conn.LocalAddr(),
"remote-address": connInfo.Conn.RemoteAddr(),
"reused": connInfo.Reused,
"was-idle": connInfo.WasIdle,
"idle-time": connInfo.IdleTime,
}).Trace("ClientTrace.GoConn")
},
PutIdleConn: func(err error) {
logrus.WithField("error", err).Trace("ClientTrace.GoConn")
},
GotFirstResponseByte: func() {
logrus.Trace("ClientTrace.GotFirstResponseByte")
},
Got100Continue: func() {
logrus.Trace("ClientTrace.Got100Continue")
},
Got1xxResponse: func(code int, header textproto.MIMEHeader) error {
logrus.WithFields(logrus.Fields{
"code": code,
"header": header,
}).Trace("ClientTrace.Got1xxxResponse")
return nil
},
DNSStart: func(dnsInfo httptrace.DNSStartInfo) {
logrus.WithField("host", dnsInfo.Host).Trace("ClientTrace.DNSStart")
},
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
logrus.WithFields(logrus.Fields{
"addresses": dnsInfo.Addrs,
"error": dnsInfo.Err,
"coalesced": dnsInfo.Coalesced,
}).Trace("ClientTrace.DNSDone")
},
ConnectStart: func(network, addr string) {
logrus.WithFields(logrus.Fields{
"network": network,
"address": addr,
}).Trace("ClientTrace.ConnectStart")
},
ConnectDone: func(network, addr string, err error) {
logrus.WithFields(logrus.Fields{
"network": network,
"address": addr,
"error": err,
}).Trace("ClientTrace.ConnectDone")
},
TLSHandshakeStart: func() {
logrus.Trace("ClientTrace.TLSHandshakeStart")
},
TLSHandshakeDone: func(connState tls.ConnectionState, err error) {
logrus.WithFields(logrus.Fields{
"version": connState.Version,
"handshake-complete": connState.HandshakeComplete,
"did-resume": connState.DidResume,
"cipher-suite": connState.CipherSuite,
"negotiated-protocol": connState.NegotiatedProtocol,
"server-name": connState.ServerName,
"error": err,
}).Trace("ClientTrace.TLSHandshakeDone")
},
WroteHeaderField: func(key string, value []string) {
logrus.WithFields(logrus.Fields{
"key": key,
"values": value,
}).Trace("ClientTrace.WroteHeaderField")
},
WroteHeaders: func() {
logrus.Trace("ClientTrace.WroteHeaders")
},
Wait100Continue: func() {
logrus.Trace("ClientTrace.Wait100Continue")
},
WroteRequest: func(reqInfo httptrace.WroteRequestInfo) {
logrus.WithField("error", reqInfo.Err).Trace("ClientTrace.WroteRequest")
},
})
}

View File

@ -1,152 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"time"
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// buildFlags has the cli.Flags for the drone.Build.
func buildFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "build.branch",
Usage: "build branch",
EnvVars: []string{"DRONE_BRANCH"},
Category: category,
},
&cli.IntFlag{
Name: "build.pull-request",
Usage: "build pull request",
EnvVars: []string{"DRONE_PULL_REQUEST"},
Category: category,
},
&cli.StringFlag{
Name: "build.tag",
Usage: "build tag",
EnvVars: []string{"DRONE_TAG"},
Category: category,
},
&cli.StringFlag{
Name: "build.source-branch",
Usage: "build source branch",
EnvVars: []string{"DRONE_SOURCE_BRANCH"},
Category: category,
},
&cli.StringFlag{
Name: "build.target-branch",
Usage: "build target branch",
EnvVars: []string{"DRONE_TARGET_BRANCH"},
Category: category,
},
&cli.IntFlag{
Name: "build.number",
Usage: "build number",
EnvVars: []string{"DRONE_BUILD_NUMBER"},
Category: category,
},
&cli.IntFlag{
Name: "build.parent",
Usage: "build parent",
EnvVars: []string{"DRONE_BUILD_PARENT"},
Category: category,
},
&cli.StringFlag{
Name: "build.event",
Usage: "build event",
EnvVars: []string{"DRONE_BUILD_EVENT"},
Category: category,
},
&cli.StringFlag{
Name: "build.action",
Usage: "build action",
EnvVars: []string{"DRONE_BUILD_ACTION"},
Category: category,
},
&cli.StringFlag{
Name: "build.status",
Usage: "build status",
EnvVars: []string{"DRONE_BUILD_STATUS"},
Category: category,
},
&cli.StringFlag{
Name: "build.link",
Usage: "build link",
EnvVars: []string{"DRONE_BUILD_LINK"},
Category: category,
},
&cli.StringFlag{
Name: "build.created",
Usage: "build created",
EnvVars: []string{"DRONE_BUILD_CREATED"},
Category: category,
},
&cli.StringFlag{
Name: "build.started",
Usage: "build started",
EnvVars: []string{"DRONE_BUILD_STARTED"},
Category: category,
},
&cli.StringFlag{
Name: "build.finished",
Usage: "build finished",
EnvVars: []string{"DRONE_BUILD_FINISHED"},
Category: category,
},
&cli.StringFlag{
Name: "build.deploy-to",
Usage: "build deploy to",
EnvVars: []string{"DRONE_DEPLOY_TO"},
Category: category,
},
&cli.IntFlag{
Name: "build.deploy-id",
Usage: "build deploy id",
EnvVars: []string{"DRONE_DEPLOY_ID"},
Category: category,
},
&cli.StringSliceFlag{
Name: "build.failed-stages",
Usage: "build failed stages",
EnvVars: []string{"DRONE_FAILED_STAGES"},
Category: category,
},
&cli.StringSliceFlag{
Name: "build.failed-steps",
Usage: "build failed steps",
EnvVars: []string{"DRONE_FAILED_STEPS"},
Category: category,
},
}
}
// buildFromContext creates a drone.Build from the cli.Context.
func buildFromContext(ctx *cli.Context) drone.Build {
return drone.Build{
Branch: ctx.String("build.branch"),
PullRequest: ctx.Int("build.pull-request"),
Tag: ctx.String("build.tag"),
SourceBranch: ctx.String("build.source-branch"),
TargetBranch: ctx.String("build.target-branch"),
Number: ctx.Int("build.number"),
Parent: ctx.Int("build.parent"),
Event: ctx.String("build.event"),
Action: ctx.String("build.action"),
Status: ctx.String("build.status"),
Link: ctx.String("build.link"),
Created: time.Unix(ctx.Int64("build.created"), 0),
Started: time.Unix(ctx.Int64("build.started"), 0),
Finished: time.Unix(ctx.Int64("build.finished"), 0),
DeployTo: ctx.String("build.deploy-to"),
DeployID: ctx.Int("build.deploy-id"),
FailedStages: ctx.StringSlice("build.failed-stages"),
FailedSteps: ctx.StringSlice("build.failed-steps"),
}
}

View File

@ -1,74 +0,0 @@
// Copyright (c) 2020, the Drone Plugins project authors.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// calVerFlags has the cli.Flags for the drone.CalVer.
func calVerFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "calver.version",
Usage: "calver version",
EnvVars: []string{
"DRONE_CALVER",
},
Category: category,
},
&cli.StringFlag{
Name: "calver.major",
Usage: "calver major",
EnvVars: []string{
"DRONE_CALVER_MAJOR",
},
Category: category,
},
&cli.StringFlag{
Name: "calver.minor",
Usage: "calver minor",
EnvVars: []string{
"DRONE_CALVER_MINOR",
},
Category: category,
},
&cli.StringFlag{
Name: "calver.micro",
Usage: "calver micro",
EnvVars: []string{
"DRONE_CALVER_MICRO",
},
Category: category,
},
&cli.StringFlag{
Name: "calver.modifier",
Usage: "calver modifier",
EnvVars: []string{
"DRONE_CALVER_MODIFIER",
},
Category: category,
},
&cli.StringFlag{
Name: "calver.short",
Usage: "calver short",
EnvVars: []string{
"DRONE_CALVER_SHORT",
},
Category: category,
},
}
}
// calVerFromContext creates a drone.CalVer from the cli.Context.
func calVerFromContext(ctx *cli.Context) drone.CalVer {
return drone.CalVer{
Version: ctx.String("calver.version"),
Major: ctx.String("calver.major"),
Minor: ctx.String("calver.minor"),
Micro: ctx.String("calver.micro"),
Modifier: ctx.String("calver.modifier"),
Short: ctx.String("calver.short"),
}
}

View File

@ -1,125 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// commitFlags has the cli.Flags for the drone.Commit.
func commitFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "commit.sha",
Usage: "commit sha",
EnvVars: []string{
"DRONE_COMMIT",
"DRONE_COMMIT_SHA",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.before",
Usage: "commit before",
EnvVars: []string{
"DRONE_COMMIT_BEFORE",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.after",
Usage: "commit after",
EnvVars: []string{
"DRONE_COMMIT_AFTER",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.ref",
Usage: "commit ref",
EnvVars: []string{
"DRONE_COMMIT_REF",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.branch",
Usage: "commit branch",
EnvVars: []string{
"DRONE_COMMIT_BRANCH",
},
Category: category,
}, &cli.StringFlag{
Name: "commit.link",
Usage: "commit link",
EnvVars: []string{
"DRONE_COMMIT_LINK",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.message",
Usage: "commit message",
EnvVars: []string{
"DRONE_COMMIT_MESSAGE",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.author",
Usage: "commit author",
EnvVars: []string{
"DRONE_COMMIT_AUTHOR",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.author-name",
Usage: "commit author name",
EnvVars: []string{
"DRONE_COMMIT_AUTHOR_NAME",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.author-email",
Usage: "commit author email",
EnvVars: []string{
"DRONE_COMMIT_AUTHOR_EMAIL",
},
Category: category,
},
&cli.StringFlag{
Name: "commit.author-avatar",
Usage: "commit author avatar",
EnvVars: []string{
"DRONE_COMMIT_AUTHOR_AVATAR",
},
Category: category,
},
}
}
// commitFromContext creates a drone.Commit from the cli.Context.
func commitFromContext(ctx *cli.Context) drone.Commit {
return drone.Commit{
SHA: ctx.String("commit.sha"),
Before: ctx.String("commit.before"),
After: ctx.String("commit.after"),
Ref: ctx.String("commit.ref"),
Branch: ctx.String("commit.branch"),
Link: ctx.String("commit.link"),
Message: drone.ParseMessage(ctx.String("commit.message")),
Author: drone.Author{
Username: ctx.String("commit.author"),
Name: ctx.String("commit.author-name"),
Email: ctx.String("commit.author-email"),
Avatar: ctx.String("commit.author-avatar"),
},
}
}

View File

@ -1,34 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
// loggingFlags has the cli.Flags for logging config.
func loggingFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Usage: "log level",
EnvVars: []string{"PLUGIN_LOG_LEVEL"},
Category: category,
},
}
}
// LoggingFromContext sets the logrus logging level.
func LoggingFromContext(ctx *cli.Context) {
lvl, err := logrus.ParseLevel(ctx.String("log-level"))
if err != nil {
lvl = logrus.InfoLevel
}
logrus.SetLevel(lvl)
}

View File

@ -1,83 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"context"
"crypto/tls"
"net"
"net/http"
"time"
"github.com/sirupsen/logrus"
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/thegeeklab/drone-plugin-lib/v2/trace"
"github.com/urfave/cli/v2"
)
const (
NetDailerTimeout = 30 * time.Second
HTTPTransportIdleTimeout = 90 * time.Second
HTTPTransportTLSHandshakeTimeout = 10 * time.Second
HTTPTransportMaxIdleConns = 100
)
// networkFlags has the cli.Flags for the drone.Network.
func networkFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "transport.skip-verify",
Usage: "skip ssl verify",
EnvVars: []string{"PLUGIN_SKIP_VERIFY"},
Category: category,
},
}
}
// NetworkFromContext creates a drone.Network from the cli.Context.
func NetworkFromContext(ctx *cli.Context) drone.Network {
dialer := &net.Dialer{
Timeout: NetDailerTimeout,
KeepAlive: NetDailerTimeout,
DualStack: true,
}
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
MaxIdleConns: HTTPTransportMaxIdleConns,
IdleConnTimeout: HTTPTransportIdleTimeout,
TLSHandshakeTimeout: HTTPTransportTLSHandshakeTimeout,
ExpectContinueTimeout: 1 * time.Second,
}
context := context.Background()
skipVerify := ctx.Bool("transport.skip-verify")
if skipVerify {
logrus.Warning("ssl verification is turned off")
transport.TLSClientConfig = &tls.Config{
//nolint:gosec
InsecureSkipVerify: true,
}
}
if ctx.String("log-level") == logrus.TraceLevel.String() {
context = trace.HTTP(context)
}
client := &http.Client{
Transport: transport,
}
return drone.Network{
Context: context,
SkipVerify: skipVerify,
Client: client,
}
}

View File

@ -1,116 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// repoFlags has the cli.Flags for the drone.Repo.
func repoFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "repo.slug",
Usage: "repo slug",
EnvVars: []string{
"DRONE_REPO",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.scm",
Usage: "repo scm",
EnvVars: []string{
"DRONE_REPO_SCM",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.owner",
Usage: "repo owner",
EnvVars: []string{
"DRONE_REPO_OWNER",
"DRONE_REPO_NAMESPACE",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.name",
Usage: "repo name",
EnvVars: []string{
"DRONE_REPO_NAME",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.link",
Usage: "repo link",
EnvVars: []string{
"DRONE_REPO_LINK",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.branch",
Usage: "repo branch",
EnvVars: []string{
"DRONE_REPO_BRANCH",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.http-url",
Usage: "repo http url",
EnvVars: []string{
"DRONE_REMOTE_URL",
"DRONE_GIT_HTTP_URL",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.ssh-url",
Usage: "repo ssh url",
EnvVars: []string{
"DRONE_GIT_SSH_URL",
},
Category: category,
},
&cli.StringFlag{
Name: "repo.visibility",
Usage: "repo visibility",
EnvVars: []string{
"DRONE_REPO_VISIBILITY",
},
Category: category,
},
&cli.BoolFlag{
Name: "repo.private",
Usage: "repo private",
EnvVars: []string{
"DRONE_REPO_PRIVATE",
},
Category: category,
},
}
}
// repoFromContext creates a drone.Repo from the cli.Context.
func repoFromContext(ctx *cli.Context) drone.Repo {
return drone.Repo{
Slug: ctx.String("repo.slug"),
SCM: ctx.String("repo.scm"),
Owner: ctx.String("repo.owner"),
Name: ctx.String("repo.name"),
Link: ctx.String("repo.link"),
Branch: ctx.String("repo.branch"),
HTTPURL: ctx.String("repo.http-url"),
SSHURL: ctx.String("repo.ssh-url"),
Visibility: ctx.String("repo.visibility"),
Private: ctx.Bool("repo.private"),
}
}

View File

@ -1,96 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// semVerFlags has the cli.Flags for the drone.SemVer.
func semVerFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "semver.version",
Usage: "semver version",
EnvVars: []string{
"DRONE_SEMVER",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.major",
Usage: "semver major",
EnvVars: []string{
"DRONE_SEMVER_MAJOR",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.minor",
Usage: "semver minor",
EnvVars: []string{
"DRONE_SEMVER_MINOR",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.patch",
Usage: "semver patch",
EnvVars: []string{
"DRONE_SEMVER_PATCH",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.prerelease",
Usage: "semver prerelease",
EnvVars: []string{
"DRONE_SEMVER_PRERELEASE",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.build",
Usage: "semver build",
EnvVars: []string{
"DRONE_SEMVER_BUILD",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.short",
Usage: "semver short",
EnvVars: []string{
"DRONE_SEMVER_SHORT",
},
Category: category,
},
&cli.StringFlag{
Name: "semver.error",
Usage: "semver error",
EnvVars: []string{
"DRONE_SEMVER_ERROR",
},
Category: category,
},
}
}
// semVerFromContext creates a drone.SemVer from the cli.Context.
func semVerFromContext(ctx *cli.Context) drone.SemVer {
return drone.SemVer{
Version: ctx.String("semver.version"),
Major: ctx.String("semver.major"),
Minor: ctx.String("semver.minor"),
Patch: ctx.String("semver.patch"),
Prerelease: ctx.String("semver.prerelease"),
Build: ctx.String("semver.build"),
Short: ctx.String("semver.short"),
Error: ctx.String("semver.error"),
}
}

View File

@ -1,143 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"time"
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// stageFlags has the cli.Flags for the drone.Stage.
func stageFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "stage.kind",
Usage: "stage kind",
EnvVars: []string{
"DRONE_STAGE_KIND",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.type",
Usage: "stage type",
EnvVars: []string{
"DRONE_STAGE_TYPE",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.name",
Usage: "stage name",
EnvVars: []string{
"DRONE_STAGE_NAME",
},
Category: category,
},
&cli.IntFlag{
Name: "stage.number",
Usage: "stage number",
EnvVars: []string{
"DRONE_STAGE_NUMBER",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.machine",
Usage: "stage machine",
EnvVars: []string{
"DRONE_STAGE_MACHINE",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.os",
Usage: "stage os",
EnvVars: []string{
"DRONE_STAGE_OS",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.arch",
Usage: "stage arch",
EnvVars: []string{
"DRONE_STAGE_ARCH",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.variant",
Usage: "stage variant",
EnvVars: []string{
"DRONE_STAGE_VARIANT",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.version",
Usage: "stage version",
EnvVars: []string{
"DRONE_STAGE_VERSION",
},
Category: category,
},
&cli.StringFlag{
Name: "stage.status",
Usage: "stage status",
EnvVars: []string{
"DRONE_STAGE_STATUS",
},
Category: category,
},
&cli.Int64Flag{
Name: "stage.started",
Usage: "stage started",
EnvVars: []string{
"DRONE_STAGE_STARTED",
},
Category: category,
},
&cli.Int64Flag{
Name: "stage.finished",
Usage: "stage finished",
EnvVars: []string{
"DRONE_STAGE_FINISHED",
},
Category: category,
},
&cli.StringSliceFlag{
Name: "stage.depends-on",
Usage: "stage depends on",
EnvVars: []string{
"DRONE_STAGE_DEPENDS_ON",
},
Category: category,
},
}
}
// stageFromContext creates a drone.Stage from the cli.Context.
func stageFromContext(ctx *cli.Context) drone.Stage {
return drone.Stage{
Kind: ctx.String("stage.kind"),
Type: ctx.String("stage.type"),
Name: ctx.String("stage.name"),
Number: ctx.Int("stage.number"),
Machine: ctx.String("stage.machine"),
OS: ctx.String("stage.os"),
Arch: ctx.String("stage.arch"),
Variant: ctx.String("stage.variant"),
Version: ctx.String("stage.version"),
Status: ctx.String("stage.status"),
Started: time.Unix(ctx.Int64("stage.started"), 0),
Finished: time.Unix(ctx.Int64("stage.finished"), 0),
DependsOn: ctx.StringSlice("stage.depends-on"),
}
}

View File

@ -1,42 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// stepFlags has the cli.Flags for the drone.Step.
func stepFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "step.name",
Usage: "step name",
EnvVars: []string{
"DRONE_STEP_NAME",
},
Category: category,
},
&cli.IntFlag{
Name: "step.number",
Usage: "step number",
EnvVars: []string{
"DRONE_STEP_NUMBER",
},
Category: category,
},
}
}
// stepFromContext creates a drone.Step from the cli.Context.
func stepFromContext(ctx *cli.Context) drone.Step {
return drone.Step{
Name: ctx.String("step.name"),
Number: ctx.Int("step.number"),
}
}

View File

@ -1,52 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
// systemFlags has the cli.Flags for the drone.System.
func systemFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "system.proto",
Usage: "system proto",
EnvVars: []string{
"DRONE_SYSTEM_PROTO",
},
Category: category,
},
&cli.StringFlag{
Name: "system.host",
Usage: "system host",
EnvVars: []string{
"DRONE_SYSTEM_HOST",
"DRONE_SYSTEM_HOSTNAME",
},
Category: category,
},
&cli.StringFlag{
Name: "system.version",
Usage: "system version",
EnvVars: []string{
"DRONE_SYSTEM_VERSION",
},
Category: category,
},
}
}
// systemFromContext creates a drone.System from the cli.Context.
func systemFromContext(ctx *cli.Context) drone.System {
return drone.System{
Proto: ctx.String("system.proto"),
Host: ctx.String("system.host"),
Version: ctx.String("system.version"),
}
}

View File

@ -1,55 +0,0 @@
// Copyright (c) 2019, Drone Plugins project authors
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package urfave
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"github.com/urfave/cli/v2"
)
const (
FlagsBuildCategory = "Drone Build Flags"
FlagsRepoCategory = "Drone Repo Flags"
FlagsCommitCategory = "Drone Commit Flags"
FlagsStageCategory = "Drone Stage Flags"
FlagsStepCategory = "Drone Step Flags"
FlagsVersioningCategory = "Drone Versioning Flags"
FlagsSystemCategory = "Drone System Flags"
FlagsPluginCategory = "Plugin Flags"
)
// Flags has the cli.Flags for the Drone plugin.
func Flags() []cli.Flag {
flags := []cli.Flag{}
flags = append(flags, buildFlags(FlagsBuildCategory)...)
flags = append(flags, repoFlags(FlagsRepoCategory)...)
flags = append(flags, commitFlags(FlagsCommitCategory)...)
flags = append(flags, stageFlags(FlagsStageCategory)...)
flags = append(flags, stepFlags(FlagsStepCategory)...)
flags = append(flags, semVerFlags(FlagsVersioningCategory)...)
flags = append(flags, calVerFlags(FlagsVersioningCategory)...)
flags = append(flags, systemFlags(FlagsSystemCategory)...)
flags = append(flags, networkFlags(FlagsPluginCategory)...)
flags = append(flags, loggingFlags(FlagsPluginCategory)...)
return flags
}
// PipelineFromContext creates a drone.Pipeline from the cli.Context.
func PipelineFromContext(ctx *cli.Context) drone.Pipeline {
return drone.Pipeline{
Build: buildFromContext(ctx),
Repo: repoFromContext(ctx),
Commit: commitFromContext(ctx),
Stage: stageFromContext(ctx),
Step: stepFromContext(ctx),
SemVer: semVerFromContext(ctx),
CalVer: calVerFromContext(ctx),
System: systemFromContext(ctx),
}
}

206
woodpecker/commit.go Normal file
View File

@ -0,0 +1,206 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"github.com/urfave/cli/v2"
)
type (
// Commit defines runtime metadata for a commit.
Commit struct {
Sha string `json:"sha,omitempty"`
Ref string `json:"ref,omitempty"`
Refspec string `json:"refspec,omitempty"`
PullRequest string `json:"pull_request,omitempty"`
SourceBranch string `json:"source_branch,omitempty"`
TargetBranch string `json:"target_branch,omitempty"`
Branch string `json:"branch,omitempty"`
Tag string `json:"tag,omitempty"`
Message string `json:"message,omitempty"`
Author Author `json:"author,omitempty"`
}
// Author defines runtime metadata for a commit author.
Author struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Avatar string `json:"avatar,omitempty"`
}
)
func currFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "commit.sha",
Usage: "commit SHA",
EnvVars: []string{"CI_COMMIT_SHA"},
Category: category,
},
&cli.StringFlag{
Name: "commit.ref",
Usage: "commit ref",
EnvVars: []string{"CI_COMMIT_REF"},
Category: category,
},
&cli.StringFlag{
Name: "commit.refspec",
Usage: "commit refspec",
EnvVars: []string{"CI_COMMIT_REFSPEC"},
Category: category,
},
&cli.StringFlag{
Name: "commit.pull-request",
Usage: "commit pull request",
EnvVars: []string{"CI_COMMIT_PULL_REQUEST"},
Category: category,
},
&cli.StringFlag{
Name: "commit.source-branch",
Usage: "commit source branch",
EnvVars: []string{"CI_COMMIT_SOURCE_BRANCH"},
Category: category,
},
&cli.StringFlag{
Name: "commit.target-branch",
Usage: "commit target branch",
EnvVars: []string{"CI_COMMIT_TARGET_BRANCH"},
Category: category,
},
&cli.StringFlag{
Name: "commit.branch",
Usage: "commit branch",
EnvVars: []string{"CI_COMMIT_BRANCH"},
Category: category,
},
&cli.StringFlag{
Name: "commit.tag",
Usage: "commit tag",
EnvVars: []string{"CI_COMMIT_TAG"},
Category: category,
},
&cli.StringFlag{
Name: "commit.message",
Usage: "commit message",
EnvVars: []string{"CI_COMMIT_MESSAGE"},
Category: category,
},
&cli.StringFlag{
Name: "commit.author.name",
Usage: "commit author name",
EnvVars: []string{"CI_COMMIT_AUTHOR"},
Category: category,
},
&cli.StringFlag{
Name: "commit.author.email",
Usage: "commit author email",
EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL"},
Category: category,
},
&cli.StringFlag{
Name: "commit.author.avatar",
Usage: "commit author avatar",
EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR"},
Category: category,
},
}
}
func currFromContext(c *cli.Context) Commit {
return Commit{
Sha: c.String("commit.sha"),
Ref: c.String("commit.ref"),
Refspec: c.String("commit.refspec"),
PullRequest: c.String("commit.pull-request"),
SourceBranch: c.String("commit.source-branch"),
TargetBranch: c.String("commit.target-branch"),
Branch: c.String("commit.branch"),
Tag: c.String("commit.tag"),
Message: c.String("commit.message"),
Author: Author{
Name: c.String("commit.author.name"),
Email: c.String("commit.author.email"),
Avatar: c.String("commit.author.avatar"),
},
}
}
func prevFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "prev.commit.sha",
Usage: "previous commit SHA",
EnvVars: []string{"CI_PREV_COMMIT_SHA"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.ref",
Usage: "previous commit ref",
EnvVars: []string{"CI_PREV_COMMIT_REF"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.refspec",
Usage: "previous commit refspec",
EnvVars: []string{"CI_PREV_COMMIT_REFSPEC"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.branch",
Usage: "previous commit branch",
EnvVars: []string{"CI_PREV_COMMIT_BRANCH"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.message",
Usage: "previous commit message",
EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.author.name",
Usage: "previous commit author name",
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.author.email",
Usage: "previous commit author email",
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_EMAIL"},
Category: category,
},
&cli.StringFlag{
Name: "prev.commit.author.avatar",
Usage: "previous commit author avatar",
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_AVATAR"},
Category: category,
},
}
}
func prevFromContext(c *cli.Context) Commit {
return Commit{
Sha: c.String("prev.commit.sha"),
Ref: c.String("prev.commit.ref"),
Refspec: c.String("prev.commit.refspec"),
Branch: c.String("prev.commit.branch"),
Message: c.String("prev.commit.message"),
Author: Author{
Name: c.String("prev.commit.author.name"),
Email: c.String("prev.commit.author.email"),
Avatar: c.String("prev.commit.author.avatar"),
},
}
}

47
woodpecker/flags.go Normal file
View File

@ -0,0 +1,47 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"github.com/urfave/cli/v2"
)
const (
FlagsRepositoryCategory = "Woodpecker Repository Flags"
FlagsPipelineCategory = "Woodpecker Pipeline Flags"
FlagsCommitCategory = "Woodpecker Commit Flags"
FlagsStepCategory = "Woodpecker Step Flags"
FlagsSystemCategory = "Woodpecker System Flags"
FlagsPluginCategory = "Plugin Flags"
)
// Flags has the cli.Flags for the Woodpecker plugin.
func Flags() []cli.Flag {
flags := make([]cli.Flag, 0)
// Pipeline flags
flags = append(flags, repositoryFlags(FlagsRepositoryCategory)...)
flags = append(flags, pipelineFlags(FlagsPipelineCategory)...)
flags = append(flags, currFlags(FlagsCommitCategory)...)
flags = append(flags, prevFlags(FlagsCommitCategory)...)
flags = append(flags, stepFlags(FlagsStepCategory)...)
flags = append(flags, systemFlags(FlagsSystemCategory)...)
// Plugin flags
flags = append(flags, loggingFlags(FlagsPluginCategory)...)
flags = append(flags, httpClientFlags(FlagsPluginCategory)...)
return flags
}

112
woodpecker/http.go Normal file
View File

@ -0,0 +1,112 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"context"
"crypto/tls"
"crypto/x509"
"net"
"net/http"
"time"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"golang.org/x/net/proxy"
)
const (
NetDailerTimeout = 30 * time.Second
HTTPTransportIdleTimeout = 90 * time.Second
HTTPTransportTLSHandshakeTimeout = 10 * time.Second
HTTPTransportMaxIdleConns = 100
)
func httpClientFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "transport.skip-verify",
Usage: "skip ssl verify",
EnvVars: []string{"CI_SKIP_VERIFY"},
Category: category,
},
&cli.StringFlag{
Name: "transport.socks-proxy",
Usage: "socks proxy address",
EnvVars: []string{"SOCKS_PROXY"},
Hidden: true,
},
&cli.BoolFlag{
Name: "transport.socks-proxy-off",
Usage: "socks proxy ignored",
EnvVars: []string{"SOCKS_PROXY_OFF"},
Hidden: true,
},
}
}
func HTTPClientFromContext(ctx *cli.Context) *http.Client {
var (
skip = ctx.Bool("transport.skip-verify")
socks = ctx.String("transport.socks-proxy")
socksoff = ctx.Bool("transport.socks-proxy-off")
)
certs, err := x509.SystemCertPool()
if err != nil {
log.Error().Err(err).Msg("failed to find system CA certs")
}
tlsConfig := &tls.Config{
RootCAs: certs,
InsecureSkipVerify: skip, //nolint:gosec
}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
MaxIdleConns: HTTPTransportMaxIdleConns,
IdleConnTimeout: HTTPTransportIdleTimeout,
TLSHandshakeTimeout: HTTPTransportTLSHandshakeTimeout,
ExpectContinueTimeout: 1 * time.Second,
}
dialer := &net.Dialer{
Timeout: NetDailerTimeout,
KeepAlive: NetDailerTimeout,
DualStack: true,
}
if len(socks) != 0 && !socksoff {
proxyDialer, err := proxy.SOCKS5("tcp", socks, nil, dialer)
if err != nil {
log.Error().Err(err).Msg("failed to create socks proxy")
}
if contextDialer, ok := proxyDialer.(proxy.ContextDialer); ok {
transport.DialContext = contextDialer.DialContext
} else {
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return proxyDialer.Dial(network, addr)
}
}
} else {
transport.DialContext = dialer.DialContext
}
return &http.Client{
Transport: transport,
}
}

58
woodpecker/logger.go Normal file
View File

@ -0,0 +1,58 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
func loggingFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Usage: "log level",
EnvVars: []string{"CI_LOG_LEVEL"},
Value: "info",
Category: category,
},
}
}
// SetupConsoleLogger sets up the console logger.
func SetupConsoleLogger(c *cli.Context) error {
level := c.String("log-level")
lvl, err := zerolog.ParseLevel(level)
if err != nil {
log.Fatal().Msgf("unknown logging level: %s", level)
}
zerolog.SetGlobalLevel(lvl)
log.Logger = zerolog.New(zerolog.ConsoleWriter{
Out: os.Stdout,
PartsExclude: []string{zerolog.TimestampFieldName},
}).With().Timestamp().Logger()
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
log.Logger = log.With().Caller().Logger()
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
}
return nil
}

41
woodpecker/metadata.go Normal file
View File

@ -0,0 +1,41 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"github.com/urfave/cli/v2"
)
// Metadata defines runtime metadata.
type Metadata struct {
Repository Repository `json:"repo,omitempty"`
Pipeline Pipeline `json:"curr,omitempty"`
Curr Commit `json:"commit,omitempty"`
Prev Commit `json:"prev,omitempty"`
Step Step `json:"step,omitempty"`
System System `json:"sys,omitempty"`
}
// MetadataFromContext creates a Metadata from the cli.Context.
func MetadataFromContext(ctx *cli.Context) Metadata {
return Metadata{
Repository: repositoryFromContext(ctx),
Pipeline: pipelineFromContext(ctx),
Curr: currFromContext(ctx),
Prev: prevFromContext(ctx),
Step: stepFromContext(ctx),
System: systemFromContext(ctx),
}
}

107
woodpecker/pipeline.go Normal file
View File

@ -0,0 +1,107 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"time"
"github.com/urfave/cli/v2"
)
// Pipeline defines runtime metadata for a pipeline.
type Pipeline struct {
Number int64 `json:"number,omitempty"`
Status string `json:"status,omitempty"`
Event string `json:"event,omitempty"`
Link string `json:"link,omitempty"`
DeployTarget string `json:"target,omitempty"`
Created time.Time `json:"created,omitempty"`
Started time.Time `json:"started,omitempty"`
Finished time.Time `json:"finished,omitempty"`
Parent int64 `json:"parent,omitempty"`
}
func pipelineFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.Int64Flag{
Name: "pipeline.number",
Usage: "pipeline number",
EnvVars: []string{"CI_PIPELINE_NUMBER"},
Category: category,
},
&cli.StringFlag{
Name: "pipeline.status",
Usage: "pipeline status",
EnvVars: []string{"CI_PIPELINE_STATUS"},
Category: category,
},
&cli.StringFlag{
Name: "pipeline.event",
Usage: "pipeline event",
EnvVars: []string{"CI_PIPELINE_EVENT"},
Category: category,
},
&cli.StringFlag{
Name: "pipeline.link",
Usage: "pipeline link",
EnvVars: []string{"CI_PIPELINE_LINK"},
Category: category,
},
&cli.StringFlag{
Name: "pipeline.deploy-target",
Usage: "pipeline deployment target",
EnvVars: []string{"CI_PIPELINE_DEPLOY_TARGET"},
Category: category,
},
&cli.Int64Flag{
Name: "pipeline.created",
Usage: "pipeline creation time",
EnvVars: []string{"CI_PIPELINE_CREATED"},
Category: category,
},
&cli.Int64Flag{
Name: "pipeline.started",
Usage: "pipeline start time",
EnvVars: []string{"CI_PIPELINE_STARTED"},
Category: category,
},
&cli.Int64Flag{
Name: "pipeline.finished",
Usage: "pipeline finish time",
EnvVars: []string{"CI_PIPELINE_FINISHED"},
Category: category,
},
&cli.Int64Flag{
Name: "pipeline.parent",
Usage: "pipeline parent",
EnvVars: []string{"CI_PIPELINE_PARENT"},
Category: category,
},
}
}
func pipelineFromContext(c *cli.Context) Pipeline {
return Pipeline{
Number: c.Int64("pipeline.number"),
Status: c.String("pipeline.status"),
Event: c.String("pipeline.event"),
Link: c.String("pipeline.link"),
DeployTarget: c.String("pipeline.deploy-target"),
Created: time.Unix(c.Int64("pipeline.created"), 0),
Started: time.Unix(c.Int64("pipeline.started"), 0),
Finished: time.Unix(c.Int64("pipeline.finished"), 0),
Parent: c.Int64("pipeline.parent"),
}
}

101
woodpecker/plugin.go Normal file
View File

@ -0,0 +1,101 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"context"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
// Options defines the options for the plugin.
type Options struct {
// Name of the plugin.
Name string
// Description of the plugin.
Description string
// Version of the plugin.
Version string
// Flags of the plugin.
Flags []cli.Flag
// Execute function of the plugin.
Execute ExecuteFunc
}
// Plugin defines the plugin instance.
type Plugin struct {
app *cli.App
execute ExecuteFunc
client *http.Client
// Metadata of the current pipeline.
Metadata Metadata
}
// ExecuteFunc defines the function that is executed by the plugin.
type ExecuteFunc func(ctx context.Context) error
// New plugin instance.
func New(opt Options) *Plugin {
if _, err := os.Stat("/run/woodpecker/env"); err == nil {
_ = godotenv.Overload("/run/woodpecker/env")
}
app := &cli.App{
Name: opt.Name,
Description: opt.Description,
Version: opt.Version,
Flags: append(opt.Flags, Flags()...),
}
plugin := &Plugin{
app: app,
execute: opt.Execute,
}
plugin.app.Action = plugin.action
return plugin
}
func (p *Plugin) action(ctx *cli.Context) error {
if err := SetupConsoleLogger(ctx); err != nil {
return err
}
p.Metadata = MetadataFromContext(ctx)
p.client = HTTPClientFromContext(ctx)
if p.execute == nil {
panic("plugin execute function is not set")
}
return p.execute(ctx.Context)
}
// HTTPClient returns the http.Client instance.
func (p *Plugin) HTTPClient() *http.Client {
return p.client
}
// Run the plugin.
func (p *Plugin) Run() {
if err := p.app.Run(os.Args); err != nil {
log.Error().Err(err).Msg("execution failed")
os.Exit(1)
}
}

81
woodpecker/repo.go Normal file
View File

@ -0,0 +1,81 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"github.com/urfave/cli/v2"
)
// Repository defines runtime metadata for a repository.
type Repository struct {
Name string `json:"name,omitempty"`
Owner string `json:"owner,omitempty"`
Link string `json:"link,omitempty"`
CloneURL string `json:"clone_url,omitempty"`
Private bool `json:"private,omitempty"`
Branch string `json:"default_branch,omitempty"`
}
func repositoryFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "repo.name",
Usage: "repo name",
EnvVars: []string{"CI_REPO_NAME"},
Category: category,
},
&cli.StringFlag{
Name: "repo.owner",
Usage: "repo owner",
EnvVars: []string{"CI_REPO_OWNER"},
Category: category,
},
&cli.StringFlag{
Name: "repo.link",
Usage: "repo link",
EnvVars: []string{"CI_REPO_LINK"},
Category: category,
},
&cli.StringFlag{
Name: "repo.clone-url",
Usage: "repo clone url",
EnvVars: []string{"CI_REPO_CLONE_URL"},
Category: category,
},
&cli.BoolFlag{
Name: "repo.private",
Usage: "repo private",
EnvVars: []string{"CI_REPO_PRIVATE"},
Category: category,
},
&cli.StringFlag{
Name: "repo.default-branch",
Usage: "repo default branch",
EnvVars: []string{"CI_REPO_DEFAULT_BRANCH"},
Category: category,
},
}
}
func repositoryFromContext(c *cli.Context) Repository {
return Repository{
Name: c.String("repo.name"),
Owner: c.String("repo.owner"),
Link: c.String("repo.link"),
CloneURL: c.String("repo.clone-url"),
Private: c.Bool("repo.private"),
Branch: c.String("repo.default-branch"),
}
}

59
woodpecker/step.go Normal file
View File

@ -0,0 +1,59 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"time"
"github.com/urfave/cli/v2"
)
// Step defines runtime metadata for a step.
type Step struct {
Number int `json:"number,omitempty"`
Started time.Time `json:"started,omitempty"`
Finished time.Time `json:"finished,omitempty"`
}
func stepFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.IntFlag{
Name: "step.number",
Usage: "step number",
EnvVars: []string{"CI_STEP_NUMBER"},
Category: category,
},
&cli.Int64Flag{
Name: "step.started",
Usage: "step start time",
EnvVars: []string{"CI_STEP_STARTED"},
Category: category,
},
&cli.Int64Flag{
Name: "step.finished",
Usage: "step finish time",
EnvVars: []string{"CI_STEP_FINISHED"},
Category: category,
},
}
}
func stepFromContext(c *cli.Context) Step {
return Step{
Number: c.Int("step.number"),
Started: time.Unix(c.Int64("step.started"), 0),
Finished: time.Unix(c.Int64("step.finished"), 0),
}
}

76
woodpecker/system.go Normal file
View File

@ -0,0 +1,76 @@
// Copyright 2023 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
package plugin
import (
"github.com/urfave/cli/v2"
)
// System defines runtime metadata for a ci/cd system.
type System struct {
Name string `json:"name,omitempty"`
Host string `json:"host,omitempty"`
Link string `json:"link,omitempty"`
Platform string `json:"arch,omitempty"`
Version string `json:"version,omitempty"`
}
func systemFlags(category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "system.name",
Usage: "system name",
EnvVars: []string{"CI_SYSTEM_NAME"},
Category: category,
},
&cli.StringFlag{
Name: "system.host",
Usage: "system host",
EnvVars: []string{"CI_SYSTEM_HOST"},
Category: category,
},
&cli.StringFlag{
Name: "system.link",
Usage: "system link",
EnvVars: []string{"CI_SYSTEM_LINK"},
Category: category,
},
&cli.StringFlag{
Name: "system.arch",
Usage: "system arch",
EnvVars: []string{"CI_SYSTEM_PLATFORM"},
Category: category,
},
&cli.StringFlag{
Name: "system.version",
Usage: "system version",
EnvVars: []string{"CI_SYSTEM_VERSION"},
Category: category,
},
}
}
func systemFromContext(ctx *cli.Context) System {
link := ctx.String("system.link")
host := ctx.String("system.host")
return System{
Name: ctx.String("system.name"),
Host: host,
Link: link,
Platform: ctx.String("system.arch"),
Version: ctx.String("system.version"),
}
}

View File

@ -1,4 +1,4 @@
package drone package plugin
import ( import (
"strings" "strings"

View File

@ -1,4 +1,4 @@
package drone package plugin
import ( import (
"reflect" "reflect"