mirror of
https://codeberg.org/woodpecker-plugins/go-plugin
synced 2026-06-16 14:49:10 +08:00
Compare commits
137 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b54bb824c | |||
| 04d11d71e2 | |||
| 6c31fd4eca | |||
| 6d2dd250f2 | |||
| b9901cb0a4 | |||
| 35e4580f92 | |||
| 7c2ff72c02 | |||
| 8cc8f11ed6 | |||
| c437b69716 | |||
| ff7388263c | |||
| deb8bebb75 | |||
| 715e1e0802 | |||
| c8a8fc1983 | |||
| 320f95afae | |||
| 4fba2ed06e | |||
| 64071307b1 | |||
| 00f2fd05f9 | |||
| 4cfd9035eb | |||
| e8db412499 | |||
| 685ac42fc4 | |||
| f0168dce22 | |||
| a811e40032 | |||
| e5e33d41e5 | |||
| 8eadd31abf | |||
| aded02e977 | |||
| 9e3162422c | |||
| e9e7d50eb6 | |||
| 5959a73881 | |||
| dc3aea27df | |||
| 87698ede13 | |||
| 3393bdb542 | |||
| 2dd0dc173f | |||
| c5308d94ba | |||
| 2f1f602de3 | |||
| 87f30c981b | |||
| 60c0df20cd | |||
| 6027b2d758 | |||
| 00e236ab6d | |||
| 54513ba0ec | |||
| 14342137fa | |||
| abe46c2b5d | |||
| 649294ac47 | |||
| 10b75b259b | |||
| d25844e305 | |||
| ac40cced18 | |||
| aa85fcbce5 | |||
| 8ef4f8f9cc | |||
| a23e4f7e42 | |||
| 5e6aff13a7 | |||
| 6ce864b6d9 | |||
| a72f843148 | |||
| 9cf9134d0e | |||
| 16d1fd423d | |||
| 34d6107edb | |||
| 3908f282af | |||
| 15556b694d | |||
| ce08e0142d | |||
| 32c3c2a6f1 | |||
| 8ddffff10c | |||
| 7668bbb9be | |||
| d73d41e148 | |||
| fb4faa61f2 | |||
| 645238beec | |||
| 612b6a34dd | |||
| dad2b481a2 | |||
| e3f4284781 | |||
| 044f72ed49 | |||
| 94ba1fe374 | |||
| 89c7be805f | |||
| c13a4deeba | |||
| 770c8d6ae2 | |||
| 9993b2b277 | |||
| 545ea71b3c | |||
| 7dffd4a970 | |||
| 4cb087c13c | |||
| 67497c7b50 | |||
| 3afdbec338 | |||
| 16e5ebfe91 | |||
| 8c15dbc919 | |||
| 33995f25c3 | |||
| ba75700cc4 | |||
| 0db17abc92 | |||
| 0c8f2b173b | |||
| edc91fba9e | |||
| dec7e76c4e | |||
| 738d85cc8e | |||
| 0bb8640938 | |||
| 9748a14bd5 | |||
| 42e963e908 | |||
| d899146040 | |||
| a5e5444f6a | |||
| 54eb1bdcdd | |||
| daf65e94bb | |||
| 7f87818bf7 | |||
| 00a58f4a06 | |||
| 1d5ccf599c | |||
| 26cc02d9d9 | |||
| b43eefd089 | |||
| 3cf11a328e | |||
| dc21eb0c71 | |||
| 06e90d56f8 | |||
| 33cbc07540 | |||
| cac90b61b0 | |||
| 2b59a3028d | |||
| 2b17135e0c | |||
| c79c27bb51 | |||
| 5859397549 | |||
| b9a4363bd9 | |||
| 81050b18f0 | |||
| 67b6cdf4a6 | |||
| 2e397e1b02 | |||
| 525775bd26 | |||
| 1b0f1c5754 | |||
| 7ea01d1b3b | |||
| 212153caee | |||
| 1842b6efa6 | |||
| d493cf5c51 | |||
| 19c216c533 | |||
| c182818d82 | |||
| 38dcac787e | |||
| 5c32612e8d | |||
| 567908df09 | |||
| 72d3ea674d | |||
| ca1f8e48fe | |||
| b67c23ab79 | |||
| f6037e6127 | |||
| fa7f39a739 | |||
| 0ab802ca5b | |||
| 090b4571b4 | |||
| 6a59bd9561 | |||
| f3134af984 | |||
| 890edaf1c3 | |||
| a969947601 | |||
| 0ae47cb04a | |||
| 125fb101dc | |||
| 7b81f9a203 | |||
| 93da4f40e1 |
+23
@@ -0,0 +1,23 @@
|
||||
|
||||
### Go ###
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
||||
### IDE ###
|
||||
.vscode/
|
||||
@@ -0,0 +1,69 @@
|
||||
version: "2"
|
||||
linters:
|
||||
default: none
|
||||
enable:
|
||||
- bidichk
|
||||
- errcheck
|
||||
- errorlint
|
||||
- forbidigo
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- revive
|
||||
- staticcheck
|
||||
- unused
|
||||
- whitespace
|
||||
- zerologlint
|
||||
settings:
|
||||
errorlint:
|
||||
errorf-multi: true
|
||||
forbidigo:
|
||||
forbid:
|
||||
- pattern: context\.WithCancel$
|
||||
- pattern: ^print.*$
|
||||
misspell:
|
||||
locale: US
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming
|
||||
arguments:
|
||||
- []
|
||||
- []
|
||||
- - skipPackageNameChecks: true
|
||||
skip-package-name-collision-with-go-std: true
|
||||
formatters:
|
||||
enable:
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
settings:
|
||||
gci:
|
||||
sections:
|
||||
- standard
|
||||
- default
|
||||
- prefix(go.woodpecker-ci.org/woodpecker)
|
||||
custom-order: true
|
||||
gofmt:
|
||||
simplify: true
|
||||
rewrite-rules:
|
||||
- pattern: interface{}
|
||||
replacement: any
|
||||
gofumpt:
|
||||
extra-rules: true
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
@@ -3,10 +3,10 @@ when:
|
||||
- event: push
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
- 'renovate/*'
|
||||
- "renovate/*"
|
||||
|
||||
variables:
|
||||
- &golang "golang:1.21"
|
||||
- &golang "golang:1.26"
|
||||
|
||||
steps:
|
||||
vendor:
|
||||
@@ -14,9 +14,11 @@ steps:
|
||||
commands: go mod vendor
|
||||
|
||||
lint:
|
||||
image: golangci/golangci-lint:v1.55-alpine
|
||||
commands: golangci-lint run
|
||||
image: *golang
|
||||
commands: make lint
|
||||
when:
|
||||
event: [push, tag, cron]
|
||||
|
||||
test:
|
||||
image: *golang
|
||||
commands: go test --cover ./...
|
||||
commands: make test
|
||||
@@ -0,0 +1,14 @@
|
||||
when:
|
||||
- event: push
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
- release/*
|
||||
|
||||
steps:
|
||||
- name: release-helper
|
||||
image: docker.io/woodpeckerci/plugin-ready-release-go:4.1.1
|
||||
settings:
|
||||
release_branch: ${CI_COMMIT_BRANCH}
|
||||
git_email: woodpecker-bot@obermui.de
|
||||
forge_token:
|
||||
from_secret: gitea_token
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
# Changelog
|
||||
|
||||
## [1.2.0](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.2.0) - 2026-05-30
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@6543, @woodpecker-bot
|
||||
|
||||
### ✨ Features
|
||||
|
||||
- Support CI_STEP_NAME and CI_STEP_TYPE [[#88](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/88)]
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update module golang.org/x/net to v0.55.0 [[#86](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/86)]
|
||||
- fix(deps): update module golang.org/x/net to v0.54.0 [[#84](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/84)]
|
||||
|
||||
## [1.1.0](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.1.0) - 2026-03-30
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@OCram85
|
||||
|
||||
### 📈 Enhancement
|
||||
|
||||
- feat(flags): adds support for http proxy config [[#82](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/82)]
|
||||
|
||||
## [1.0.3](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.0.3) - 2026-03-07
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@woodpecker-bot
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.7.0 [[#80](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/80)]
|
||||
- chore(deps): update docker.io/woodpeckerci/plugin-ready-release-go docker tag to v4 [[#78](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/78)]
|
||||
- fix(deps): update module golang.org/x/net to v0.51.0 [[#79](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/79)]
|
||||
- chore(deps): update dependency go to v1.26.0 [[#74](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/74)]
|
||||
- chore(deps): update golang docker tag to v1.26 [[#75](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/75)]
|
||||
- fix(deps): update module golang.org/x/net to v0.50.0 [[#76](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/76)]
|
||||
|
||||
## [1.0.2](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.0.2) - 2026-01-09
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@woodpecker-bot
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.6.0 [[#72](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/72)]
|
||||
- chore(deps): update dependency go to v1.25.4 [[#71](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/71)]
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.5.0 [[#70](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/70)]
|
||||
- chore(deps): update dependency go to v1.25.3 [[#69](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/69)]
|
||||
- fix(deps): update module golang.org/x/net to v0.46.0 [[#67](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/67)]
|
||||
- chore(deps): update dependency go to v1.25.2 [[#66](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/66)]
|
||||
|
||||
## [1.0.1](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.0.1) - 2025-09-13
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@woodpecker-bot
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.4.1 [[#64](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/64)]
|
||||
- chore(deps): update dependency go to v1.25.1 [[#61](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/61)]
|
||||
- fix(deps): update module github.com/stretchr/testify to v1.11.1 [[#63](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/63)]
|
||||
- fix(deps): update module golang.org/x/net to v0.44.0 [[#65](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/65)]
|
||||
- chore(deps): update golang docker tag to v1.25 [[#62](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/62)]
|
||||
- chore(deps): update docker.io/woodpeckerci/plugin-ready-release-go docker tag to v3.4.0 [[#59](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/59)]
|
||||
- fix(deps): update module golang.org/x/net to v0.43.0 [[#60](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/60)]
|
||||
- chore(deps): update dependency go to v1.24.6 [[#58](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/58)]
|
||||
- fix(deps): update module golang.org/x/net to v0.42.0 [[#57](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/57)]
|
||||
- chore(deps): update dependency go to v1.24.5 [[#56](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/56)]
|
||||
- chore(deps): update docker.io/woodpeckerci/plugin-ready-release-go docker tag to v3.3.0 [[#55](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/55)]
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.3.8 [[#54](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/54)]
|
||||
- fix(deps): update module golang.org/x/net to v0.41.0 [[#53](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/53)]
|
||||
- chore(deps): update dependency go to v1.24.4 [[#52](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/52)]
|
||||
- chore(deps): update dependency go to v1.24.3 [[#50](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/50)]
|
||||
|
||||
## [1.0.0](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v1.0.0) - 2025-04-24
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@woodpecker-bot, @xoxys
|
||||
|
||||
### 💥 Breaking changes
|
||||
|
||||
- Bump urfave/cli to v3.2.0 [[#49](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/49)]
|
||||
|
||||
### ✨ Features
|
||||
|
||||
- feat: add custom cli flags [[#48](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/48)]
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update module github.com/urfave/cli/v3 to v3.1.1 [[#47](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/47)]
|
||||
- chore(deps): update dependency go to v1.24.2 [[#46](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/46)]
|
||||
- chore(deps): update golangci/golangci-lint docker tag to v2 [[#44](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/44)]
|
||||
|
||||
## [0.7.1](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v0.7.1) - 2025-02-16
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@6543, @woodpecker-bot
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- chore(deps): update golangci/golangci-lint docker tag to v1.64 [[#42](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/42)]
|
||||
- chore(deps): update golang docker tag to v1.24 [[#41](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/41)]
|
||||
- fix(deps): update module golang.org/x/net to v0.35.0 [[#43](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/43)]
|
||||
- chore(deps): update docker.io/woodpeckerci/plugin-ready-release-go docker tag to v3.1.3 [[#40](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/40)]
|
||||
- chore(deps): update docker.io/woodpeckerci/plugin-ready-release-go docker tag to v3 [[#37](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/37)]
|
||||
|
||||
### Misc
|
||||
|
||||
- Bump min golan version to v1.20 [[#36](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/36)]
|
||||
|
||||
## [0.7.0](https://codeberg.org/woodpecker-plugins/go-plugin/releases/tag/v0.7.0) - 2024-11-13
|
||||
|
||||
### ❤️ Thanks to all contributors! ❤️
|
||||
|
||||
@6543, @woodpecker-bot
|
||||
|
||||
### 📈 Enhancement
|
||||
|
||||
- Add support for CI_PIPELINE_FILES [[#33](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/33)]
|
||||
|
||||
### 📦️ Dependency
|
||||
|
||||
- fix(deps): update github.com/urfave/cli/v3 digest to cd7d34a [[#32](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/32)]
|
||||
|
||||
### Misc
|
||||
|
||||
- Use ready-release-go plugin [[#34](https://codeberg.org/woodpecker-plugins/go-plugin/pulls/34)]
|
||||
@@ -0,0 +1,41 @@
|
||||
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
|
||||
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
||||
|
||||
.PHONY: all
|
||||
all: lint
|
||||
|
||||
vendor:
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
|
||||
format: install-tools ## Format source code
|
||||
@gofumpt -extra -w ${GOFILES_NOVENDOR}
|
||||
|
||||
formatcheck:
|
||||
@([ -z "$(shell gofumpt -d $(GOFILES_NOVENDOR) | head)" ]) || (echo "Source is unformatted"; exit 1)
|
||||
|
||||
install-tools: ## Install development tools
|
||||
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest ; \
|
||||
fi ; \
|
||||
hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||
go install mvdan.cc/gofumpt@latest; \
|
||||
fi ; \
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
go clean -i ./...
|
||||
|
||||
.PHONY: lint
|
||||
lint: install-tools ## Lint code
|
||||
@echo "Running golangci-lint"
|
||||
golangci-lint run
|
||||
|
||||
.PHONY: vet
|
||||
vet:
|
||||
@echo "Running go vet..."
|
||||
@go vet $(GO_PACKAGES)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -race -cover ./...
|
||||
@@ -8,12 +8,40 @@ HTTP client library.
|
||||
|
||||
## Builtin settings
|
||||
|
||||
| Settings Name | Environment variable | Default | Description |
|
||||
|---|---|----|---|
|
||||
| `log_level` | - | `info` | Sets log level (`panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`) |
|
||||
| `skip_verify` | - | `false` | - | Skip verification of TLS certificate |
|
||||
| | `SOCKS_PROXY` | *none* | SOCKS5 proxy to use for connections |
|
||||
| | `SOCKS_PROXY_OFF` | *none* | Do not use SOCKS5 proxy |
|
||||
| Settings Name | Environment variable | Default | Description |
|
||||
| ------------- | -------------------- | ------- | ---------------------------------------------------------------------------- |
|
||||
| `log_level` | - | `info` | Sets log level (`panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`) |
|
||||
| `skip_verify` | - | `false` | Skip verification of TLS certificate |
|
||||
| | `SOCKS_PROXY` | _none_ | SOCKS5 proxy to use for connections |
|
||||
| | `SOCKS_PROXY_OFF` | _none_ | Do not use SOCKS5 proxy |
|
||||
|
||||
### Optional: HTTP proxy support
|
||||
|
||||
HTTP proxy support is **opt-in** and must be explicitly enabled by the plugin author via `EnableHTTPProxy: true` in `plugin.Options`. When enabled, the following settings become available:
|
||||
|
||||
| Settings Name | Environment variable | Default | Description |
|
||||
| ------------- | -------------------- | ------- | ------------------------------------------------------ |
|
||||
| `http_proxy` | `HTTP_PROXY` | _none_ | HTTP proxy URL for outgoing connections |
|
||||
| `https_proxy` | `HTTPS_PROXY` | _none_ | HTTPS proxy URL for outgoing connections |
|
||||
| `no_proxy` | `NO_PROXY` | _none_ | Comma-separated list of hosts to exclude from proxying |
|
||||
|
||||
The settings are resolved in the following order of precedence:
|
||||
|
||||
1. **Plugin settings** — `PLUGIN_HTTP_PROXY`, `PLUGIN_HTTPS_PROXY`, `PLUGIN_NO_PROXY`
|
||||
2. **Lowercase env vars** — `http_proxy`, `https_proxy`, `no_proxy`
|
||||
3. **Uppercase env vars** — `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`
|
||||
|
||||
Example Woodpecker CI pipeline configuration:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: my-plugin
|
||||
image: my-plugin:latest
|
||||
settings:
|
||||
http_proxy: http://proxy.example.com:3128
|
||||
https_proxy: http://proxy.example.com:3128
|
||||
no_proxy: "localhost,internal.example.com"
|
||||
```
|
||||
|
||||
## Creating plugin
|
||||
|
||||
@@ -25,7 +53,7 @@ import (
|
||||
|
||||
"codeberg.org/woodpecker-plugins/go-plugin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
@@ -44,7 +72,7 @@ func (p *Plugin) Flags() []cli.Flag {
|
||||
&cli.StringFlag{
|
||||
Name: "sample.flag",
|
||||
Usage: "sample flag",
|
||||
EnvVars: []string{"PLUGIN_SAMPLE_FLAG"},
|
||||
Sources: cli.EnvVars("PLUGIN_SAMPLE_FLAG"),
|
||||
Destination: &p.Settings.SampleFlag,
|
||||
},
|
||||
}
|
||||
@@ -62,10 +90,11 @@ func main() {
|
||||
}
|
||||
|
||||
p.Plugin = plugin.New(plugin.Options{
|
||||
Name: "sample-plugin",
|
||||
Description: "Sample plugin",
|
||||
Flags: p.Flags(),
|
||||
Execute: p.Execute,
|
||||
Name: "sample-plugin",
|
||||
Description: "Sample plugin",
|
||||
Flags: p.Flags(),
|
||||
Execute: p.Execute,
|
||||
EnableHTTPProxy: true, // opt-in to HTTP proxy support
|
||||
})
|
||||
|
||||
p.Run()
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// StringMapFlag is a flag type which supports JSON string maps.
|
||||
type (
|
||||
StringMapFlag = cli.FlagBase[map[string]string, StringMapConfig, StringMap]
|
||||
)
|
||||
|
||||
// StringMapConfig defines the configuration for string map flags.
|
||||
type StringMapConfig struct {
|
||||
// Any config options can be added here if needed
|
||||
}
|
||||
|
||||
// StringMap implements the Value and ValueCreator interfaces for string maps.
|
||||
type StringMap struct {
|
||||
destination *map[string]string
|
||||
}
|
||||
|
||||
// Create implements the ValueCreator interface.
|
||||
func (s StringMap) Create(v map[string]string, p *map[string]string, _ StringMapConfig) cli.Value {
|
||||
*p = map[string]string{}
|
||||
|
||||
if v != nil {
|
||||
*p = v
|
||||
}
|
||||
|
||||
return &StringMap{
|
||||
destination: p,
|
||||
}
|
||||
}
|
||||
|
||||
// ToString implements the ValueCreator interface.
|
||||
func (s StringMap) ToString(v map[string]string) string {
|
||||
if len(v) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(jsonBytes)
|
||||
}
|
||||
|
||||
// Set implements the flag.Value interface.
|
||||
func (s *StringMap) Set(v string) error {
|
||||
*s.destination = map[string]string{}
|
||||
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := json.Unmarshal([]byte(v), s.destination)
|
||||
if err != nil {
|
||||
(*s.destination)["*"] = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get implements the flag.Value interface.
|
||||
func (s *StringMap) Get() any {
|
||||
return *s.destination
|
||||
}
|
||||
|
||||
// String implements the flag.Value interface.
|
||||
func (s *StringMap) String() string {
|
||||
if s.destination == nil || len(*s.destination) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(*s.destination)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(jsonBytes)
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStringMapSet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want map[string]string
|
||||
}{
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
want: map[string]string{},
|
||||
},
|
||||
{
|
||||
name: "valid JSON",
|
||||
input: `{"key1":"value1","key2":"value2"}`,
|
||||
want: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
},
|
||||
{
|
||||
name: "single key-value",
|
||||
input: `{"key":"value"}`,
|
||||
want: map[string]string{"key": "value"},
|
||||
},
|
||||
{
|
||||
name: "non-JSON string",
|
||||
input: "not-json",
|
||||
want: map[string]string{"*": "not-json"},
|
||||
},
|
||||
{
|
||||
name: "empty JSON object",
|
||||
input: "{}",
|
||||
want: map[string]string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var dest map[string]string
|
||||
s := &StringMap{
|
||||
destination: &dest,
|
||||
}
|
||||
|
||||
err := s.Set(tt.input)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, dest)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input map[string]string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty map",
|
||||
input: map[string]string{},
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "nil map",
|
||||
input: nil,
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "single key-value",
|
||||
input: map[string]string{"key": "value"},
|
||||
want: `{"key":"value"}`,
|
||||
},
|
||||
{
|
||||
name: "multiple key-values",
|
||||
input: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
want: `{"key1":"value1","key2":"value2"}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &StringMap{
|
||||
destination: &tt.input,
|
||||
}
|
||||
|
||||
got := s.String()
|
||||
|
||||
if len(tt.input) > 1 {
|
||||
var expected, actual map[string]string
|
||||
_ = json.Unmarshal([]byte(tt.want), &expected)
|
||||
_ = json.Unmarshal([]byte(got), &actual)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapGet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want map[string]string
|
||||
}{
|
||||
{
|
||||
name: "empty map",
|
||||
want: map[string]string{},
|
||||
},
|
||||
{
|
||||
name: "single key-value",
|
||||
want: map[string]string{"key": "value"},
|
||||
},
|
||||
{
|
||||
name: "multiple key-values",
|
||||
want: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &StringMap{
|
||||
destination: &tt.want,
|
||||
}
|
||||
|
||||
result := s.Get()
|
||||
assert.Equal(t, tt.want, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input map[string]string
|
||||
want map[string]string
|
||||
}{
|
||||
{
|
||||
name: "empty map",
|
||||
input: nil,
|
||||
want: map[string]string{},
|
||||
},
|
||||
{
|
||||
name: "empty map",
|
||||
input: map[string]string{},
|
||||
want: map[string]string{},
|
||||
},
|
||||
{
|
||||
name: "single key-value",
|
||||
input: map[string]string{"key": "value"},
|
||||
want: map[string]string{"key": "value"},
|
||||
},
|
||||
{
|
||||
name: "multiple key-values",
|
||||
input: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
want: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var dest map[string]string
|
||||
|
||||
s := StringMap{}
|
||||
config := StringMapConfig{}
|
||||
|
||||
got := s.Create(tt.input, &dest, config)
|
||||
assert.Equal(t, tt.want, dest)
|
||||
assert.Equal(t, &dest, got.(*StringMap).destination)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapToString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input map[string]string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty map",
|
||||
input: map[string]string{},
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "single key-value",
|
||||
input: map[string]string{"key": "value"},
|
||||
want: `{"key":"value"}`,
|
||||
},
|
||||
{
|
||||
name: "multiple key-values",
|
||||
input: map[string]string{"key1": "value1", "key2": "value2"},
|
||||
want: `{"key1":"value1","key2":"value2"}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := StringMap{}
|
||||
|
||||
got := s.ToString(tt.input)
|
||||
|
||||
if len(tt.input) > 1 {
|
||||
var expected, actual map[string]string
|
||||
_ = json.Unmarshal([]byte(tt.want), &expected)
|
||||
_ = json.Unmarshal([]byte(got), &actual)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// StringSliceFlag is a flag type which support comma separated values and escaping to not split at unwanted lines.
|
||||
type (
|
||||
StringSliceFlag = cli.FlagBase[[]string, StringSliceConfig, StringSlice]
|
||||
)
|
||||
|
||||
// StringConfig defines the configuration for string flags.
|
||||
type StringSliceConfig struct {
|
||||
Delimiter string
|
||||
EscapeString string
|
||||
}
|
||||
|
||||
// StringSlice implements the Value and ValueCreator interfaces for string slices.
|
||||
type StringSlice struct {
|
||||
destination *[]string
|
||||
delimiter string
|
||||
escapeString string
|
||||
}
|
||||
|
||||
// Create implements the ValueCreator interface.
|
||||
func (s StringSlice) Create(v []string, p *[]string, c StringSliceConfig) cli.Value {
|
||||
*p = v
|
||||
|
||||
return &StringSlice{
|
||||
destination: p,
|
||||
delimiter: c.Delimiter,
|
||||
escapeString: c.EscapeString,
|
||||
}
|
||||
}
|
||||
|
||||
// ToString implements the ValueCreator interface.
|
||||
func (s StringSlice) ToString(v []string) string {
|
||||
if len(v) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%q", strings.Join(v, s.delimiter))
|
||||
}
|
||||
|
||||
// Set implements the flag.Value interface.
|
||||
func (s *StringSlice) Set(v string) error {
|
||||
if v == "" {
|
||||
*s.destination = []string{}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
out := strings.Split(v, s.delimiter)
|
||||
|
||||
//nolint:mnd
|
||||
for i := len(out) - 2; i >= 0; i-- {
|
||||
if strings.HasSuffix(out[i], s.escapeString) {
|
||||
out[i] = out[i][:len(out[i])-len(s.escapeString)] + s.delimiter + out[i+1]
|
||||
out = append(out[:i+1], out[i+2:]...)
|
||||
}
|
||||
}
|
||||
|
||||
*s.destination = out
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get implements the flag.Value interface.
|
||||
func (s *StringSlice) Get() any {
|
||||
return *s.destination
|
||||
}
|
||||
|
||||
// String implements the flag.Value interface.
|
||||
func (s *StringSlice) String() string {
|
||||
if s.destination == nil || len(*s.destination) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.Join(*s.destination, s.delimiter)
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStringSliceSet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "empty string",
|
||||
input: "",
|
||||
want: []string{},
|
||||
},
|
||||
{
|
||||
name: "simple comma separated",
|
||||
input: "a,b",
|
||||
want: []string{"a", "b"},
|
||||
},
|
||||
{
|
||||
name: "multiple commas",
|
||||
input: ",,,",
|
||||
want: []string{"", "", "", ""},
|
||||
},
|
||||
{
|
||||
name: "escaped comma",
|
||||
input: ",a\\,",
|
||||
want: []string{"", "a,"},
|
||||
},
|
||||
{
|
||||
name: "escaped backslash",
|
||||
input: "a,b\\,c\\\\d,e",
|
||||
want: []string{"a", "b,c\\\\d", "e"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got []string
|
||||
s := &StringSlice{
|
||||
destination: &got,
|
||||
delimiter: ",",
|
||||
escapeString: "\\",
|
||||
}
|
||||
|
||||
err := s.Set(tt.input)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSliceString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty slice",
|
||||
input: []string{},
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "nil slice",
|
||||
input: nil,
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "single item",
|
||||
input: []string{"a"},
|
||||
want: "a",
|
||||
},
|
||||
{
|
||||
name: "multiple items",
|
||||
input: []string{"a", "b", "c"},
|
||||
want: "a,b,c",
|
||||
},
|
||||
{
|
||||
name: "items with commas",
|
||||
input: []string{"a,b", "c"},
|
||||
want: "a,b,c",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &StringSlice{
|
||||
destination: &tt.input,
|
||||
delimiter: ",",
|
||||
escapeString: "\\",
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, s.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSliceGet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "empty slice",
|
||||
want: []string{},
|
||||
},
|
||||
{
|
||||
name: "single item",
|
||||
want: []string{"a"},
|
||||
},
|
||||
{
|
||||
name: "multiple items",
|
||||
want: []string{"a", "b", "c"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &StringSlice{
|
||||
destination: &tt.want,
|
||||
delimiter: ",",
|
||||
escapeString: "\\",
|
||||
}
|
||||
|
||||
result := s.Get()
|
||||
assert.Equal(t, tt.want, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSliceCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []string
|
||||
want []string
|
||||
config StringSliceConfig
|
||||
}{
|
||||
{
|
||||
name: "empty slice",
|
||||
input: nil,
|
||||
want: []string{},
|
||||
},
|
||||
{
|
||||
name: "default config",
|
||||
input: []string{"a", "b"},
|
||||
want: []string{"a", "b"},
|
||||
config: StringSliceConfig{
|
||||
Delimiter: ",",
|
||||
EscapeString: "\\",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "custom config",
|
||||
input: []string{"a", "b"},
|
||||
want: []string{"a", "b"},
|
||||
config: StringSliceConfig{
|
||||
Delimiter: ";",
|
||||
EscapeString: "#",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var dest []string
|
||||
|
||||
s := StringSlice{}
|
||||
got := s.Create(tt.input, &dest, tt.config)
|
||||
|
||||
assert.Equal(t, tt.input, dest)
|
||||
assert.Equal(t, &dest, got.(*StringSlice).destination)
|
||||
assert.Equal(t, tt.config.Delimiter, got.(*StringSlice).delimiter)
|
||||
assert.Equal(t, tt.config.EscapeString, got.(*StringSlice).escapeString)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSliceToString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []string
|
||||
delimiter string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty slice",
|
||||
input: []string{},
|
||||
delimiter: ",",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "single item",
|
||||
input: []string{"a"},
|
||||
delimiter: ",",
|
||||
want: `"a"`,
|
||||
},
|
||||
{
|
||||
name: "multiple items",
|
||||
input: []string{"a", "b", "c"},
|
||||
delimiter: ",",
|
||||
want: `"a,b,c"`,
|
||||
},
|
||||
{
|
||||
name: "custom delimiter",
|
||||
input: []string{"a", "b", "c"},
|
||||
delimiter: ";",
|
||||
want: `"a;b;c"`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := StringSlice{delimiter: tt.delimiter}
|
||||
|
||||
got := s.ToString(tt.input)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -41,72 +41,109 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func currFlags() []cli.Flag {
|
||||
func commitFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "commit.sha",
|
||||
Usage: "commit SHA",
|
||||
EnvVars: []string{"CI_COMMIT_SHA", "DRONE_COMMIT", "DRONE_COMMIT_SHA"},
|
||||
Name: "commit.sha",
|
||||
Usage: "commit SHA",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_SHA",
|
||||
"DRONE_COMMIT",
|
||||
"DRONE_COMMIT_SHA",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.ref",
|
||||
Usage: "commit ref",
|
||||
EnvVars: []string{"CI_COMMIT_REF", "DRONE_COMMIT_REF"},
|
||||
Name: "commit.ref",
|
||||
Usage: "commit ref",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_REF",
|
||||
"DRONE_COMMIT_REF",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.refspec",
|
||||
Usage: "commit refspec",
|
||||
EnvVars: []string{"CI_COMMIT_REFSPEC"},
|
||||
Name: "commit.refspec",
|
||||
Usage: "commit refspec",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_REFSPEC",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.pull-request",
|
||||
Usage: "commit pull request",
|
||||
EnvVars: []string{"CI_COMMIT_PULL_REQUEST", "DRONE_PULL_REQUEST"},
|
||||
Name: "commit.pull-request",
|
||||
Usage: "commit pull request",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_PULL_REQUEST",
|
||||
"DRONE_PULL_REQUEST",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.source-branch",
|
||||
Usage: "commit source branch",
|
||||
EnvVars: []string{"CI_COMMIT_SOURCE_BRANCH", "DRONE_SOURCE_BRANCH"},
|
||||
Name: "commit.source-branch",
|
||||
Usage: "commit source branch",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_SOURCE_BRANCH",
|
||||
"DRONE_SOURCE_BRANCH",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.target-branch",
|
||||
Usage: "commit target branch",
|
||||
EnvVars: []string{"CI_COMMIT_TARGET_BRANCH", "DRONE_TARGET_BRANCH"},
|
||||
Name: "commit.target-branch",
|
||||
Usage: "commit target branch",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_TARGET_BRANCH",
|
||||
"DRONE_TARGET_BRANCH",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.branch",
|
||||
Usage: "commit branch",
|
||||
EnvVars: []string{"CI_COMMIT_BRANCH", "DRONE_BRANCH"},
|
||||
Name: "commit.branch",
|
||||
Usage: "commit branch",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_BRANCH",
|
||||
"DRONE_BRANCH",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.tag",
|
||||
Usage: "commit tag",
|
||||
EnvVars: []string{"CI_COMMIT_TAG", "DRONE_TAG"},
|
||||
Name: "commit.tag",
|
||||
Usage: "commit tag",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_TAG",
|
||||
"DRONE_TAG",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
EnvVars: []string{"CI_COMMIT_MESSAGE", "DRONE_COMMIT_MESSAGE"},
|
||||
Name: "commit.message",
|
||||
Usage: "commit message",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_MESSAGE",
|
||||
"DRONE_COMMIT_MESSAGE",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author.name",
|
||||
Usage: "commit author name",
|
||||
EnvVars: []string{"CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR_NAME"},
|
||||
Name: "commit.author.name",
|
||||
Usage: "commit author name",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_AUTHOR",
|
||||
"DRONE_COMMIT_AUTHOR",
|
||||
"DRONE_COMMIT_AUTHOR_NAME",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author.email",
|
||||
Usage: "commit author email",
|
||||
EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL"},
|
||||
Name: "commit.author.email",
|
||||
Usage: "commit author email",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_AUTHOR_EMAIL",
|
||||
"DRONE_COMMIT_AUTHOR_EMAIL",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "commit.author.avatar",
|
||||
Usage: "commit author avatar",
|
||||
EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR", "DRONE_COMMIT_AUTHOR_AVATAR"},
|
||||
Name: "commit.author.avatar",
|
||||
Usage: "commit author avatar",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_COMMIT_AUTHOR_AVATAR",
|
||||
"DRONE_COMMIT_AUTHOR_AVATAR",
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func currFromContext(c *cli.Context) Commit {
|
||||
func commitFromContext(c *cli.Command) Commit {
|
||||
return Commit{
|
||||
Sha: c.String("commit.sha"),
|
||||
Ref: c.String("commit.ref"),
|
||||
@@ -125,52 +162,69 @@ func currFromContext(c *cli.Context) Commit {
|
||||
}
|
||||
}
|
||||
|
||||
func prevFlags() []cli.Flag {
|
||||
func previousCommitFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.sha",
|
||||
Usage: "previous commit SHA",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_SHA", "DRONE_COMMIT_BEFORE"},
|
||||
Name: "prev.commit.sha",
|
||||
Usage: "previous commit SHA",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_SHA",
|
||||
"DRONE_COMMIT_BEFORE",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.ref",
|
||||
Usage: "previous commit ref",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_REF"},
|
||||
Name: "prev.commit.ref",
|
||||
Usage: "previous commit ref",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_REF",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.refspec",
|
||||
Usage: "previous commit refspec",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_REFSPEC"},
|
||||
Name: "prev.commit.refspec",
|
||||
Usage: "previous commit refspec",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_REFSPEC",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.branch",
|
||||
Usage: "previous commit branch",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_BRANCH"},
|
||||
Name: "prev.commit.branch",
|
||||
Usage: "previous commit branch",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_BRANCH",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.message",
|
||||
Usage: "previous commit message",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"},
|
||||
Name: "prev.commit.message",
|
||||
Usage: "previous commit message",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_MESSAGE",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.author.name",
|
||||
Usage: "previous commit author name",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR"},
|
||||
Name: "prev.commit.author.name",
|
||||
Usage: "previous commit author name",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_AUTHOR",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.author.email",
|
||||
Usage: "previous commit author email",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_EMAIL"},
|
||||
Name: "prev.commit.author.email",
|
||||
Usage: "previous commit author email",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_AUTHOR_EMAIL",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "prev.commit.author.avatar",
|
||||
Usage: "previous commit author avatar",
|
||||
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_AVATAR"},
|
||||
Name: "prev.commit.author.avatar",
|
||||
Usage: "previous commit author avatar",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PREV_COMMIT_AUTHOR_AVATAR",
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func prevFromContext(c *cli.Context) Commit {
|
||||
func previousCommitFromContext(c *cli.Command) Commit {
|
||||
return Commit{
|
||||
Sha: c.String("prev.commit.sha"),
|
||||
Ref: c.String("prev.commit.ref"),
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// Flags has the cli.Flags for the Woodpecker plugin.
|
||||
@@ -25,10 +25,11 @@ func Flags() []cli.Flag {
|
||||
// Pipeline flags
|
||||
flags = append(flags, repositoryFlags()...)
|
||||
flags = append(flags, pipelineFlags()...)
|
||||
flags = append(flags, currFlags()...)
|
||||
flags = append(flags, prevFlags()...)
|
||||
flags = append(flags, commitFlags()...)
|
||||
flags = append(flags, previousCommitFlags()...)
|
||||
flags = append(flags, stepFlags()...)
|
||||
flags = append(flags, systemFlags()...)
|
||||
flags = append(flags, forgeFlags()...)
|
||||
|
||||
// Plugin flags
|
||||
flags = append(flags, loggingFlags()...)
|
||||
|
||||
Generated
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1720542800,
|
||||
"narHash": "sha256-ZgnNHuKV6h2+fQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "feb2849fdeb70028c70d73b848214b00d324a497",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ nixpkgs, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
go_1_22
|
||||
gofumpt
|
||||
golangci-lint
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
ForgeTypeGitea = "gitea"
|
||||
ForgeTypeForgejo = "forgejo"
|
||||
ForgeTypeGitHub = "github"
|
||||
ForgeTypeGitLab = "gitlab"
|
||||
ForgeTypeBitbucket = "bitbucket"
|
||||
)
|
||||
|
||||
// Forge defines metadata for integration with a forge.
|
||||
type Forge struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// Deprecated: Please use URL instead.
|
||||
Link string `json:"link,omitempty"`
|
||||
}
|
||||
|
||||
func forgeFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "forge.type",
|
||||
Usage: "forge type (gitea, forgejo, github, gitlab, bitbucket)",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_FORGE_TYPE",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "forge.url",
|
||||
Aliases: []string{"forge.link"},
|
||||
Usage: "forge url",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_FORGE_URL",
|
||||
"CI_FORGE_LINK",
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func forgeFromContext(c *cli.Command) Forge {
|
||||
return Forge{
|
||||
Type: c.String("forge.type"),
|
||||
Link: c.String("forge.url"),
|
||||
URL: c.String("forge.url"),
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
module codeberg.org/woodpecker-plugins/go-plugin
|
||||
|
||||
go 1.19
|
||||
go 1.25.0
|
||||
|
||||
toolchain go1.26.3
|
||||
|
||||
require (
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/urfave/cli/v2 v2.26.0
|
||||
golang.org/x/net v0.19.0
|
||||
github.com/rs/zerolog v1.35.1
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/urfave/cli/v3 v3.9.0
|
||||
golang.org/x/net v0.55.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // 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.15.0 // indirect
|
||||
golang.org/x/sys v0.45.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,76 +1,25 @@
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
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/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/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
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-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
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/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
|
||||
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
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/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
|
||||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI=
|
||||
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
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/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
|
||||
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/rs/zerolog v1.35.1 h1:m7xQeoiLIiV0BCEY4Hs+j2NG4Gp2o2KPKmhnnLiazKI=
|
||||
github.com/rs/zerolog v1.35.1/go.mod h1:EjML9kdfa/RMA7h/6z6pYmq1ykOuA8/mjWaEvGI+jcw=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/urfave/cli/v3 v3.9.0 h1:AV9lIiPv3ukYnxunaCUsHnEozptYmDN2F0+yWqLMn/c=
|
||||
github.com/urfave/cli/v3 v3.9.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -20,42 +20,95 @@ import (
|
||||
"crypto/x509"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
func httpClientFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "transport.skip-verify",
|
||||
Usage: "skip ssl verify",
|
||||
EnvVars: []string{"PLUGIN_SKIP_VERIFY"},
|
||||
Name: "transport.skip-verify",
|
||||
Usage: "skip ssl verify",
|
||||
Sources: cli.EnvVars(
|
||||
"PLUGIN_SKIP_VERIFY",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "transport.socks-proxy",
|
||||
Usage: "socks proxy address",
|
||||
EnvVars: []string{"SOCKS_PROXY"},
|
||||
Hidden: true,
|
||||
Name: "transport.socks-proxy",
|
||||
Usage: "socks proxy address",
|
||||
Sources: cli.EnvVars(
|
||||
"SOCKS_PROXY",
|
||||
),
|
||||
Hidden: true,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "transport.socks-proxy-off",
|
||||
Usage: "socks proxy ignored",
|
||||
EnvVars: []string{"SOCKS_PROXY_OFF"},
|
||||
Hidden: true,
|
||||
Name: "transport.socks-proxy-off",
|
||||
Usage: "socks proxy ignored",
|
||||
Sources: cli.EnvVars(
|
||||
"SOCKS_PROXY_OFF",
|
||||
),
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
||||
// httpProxyFlags returns the optional HTTP proxy flags.
|
||||
// Only added to the app when EnableHTTPProxy is set in Options.
|
||||
func httpProxyFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "transport.http-proxy",
|
||||
Usage: "HTTP proxy URL",
|
||||
Sources: cli.EnvVars(
|
||||
"PLUGIN_HTTP_PROXY",
|
||||
),
|
||||
Hidden: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "transport.https-proxy",
|
||||
Usage: "HTTPS proxy URL",
|
||||
Sources: cli.EnvVars(
|
||||
"PLUGIN_HTTPS_PROXY",
|
||||
),
|
||||
Hidden: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "transport.no-proxy",
|
||||
Usage: "Hosts to exclude from proxy (comma-separated)",
|
||||
Sources: cli.EnvVars(
|
||||
"PLUGIN_NO_PROXY",
|
||||
),
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func HTTPClientFromContext(c *cli.Command, httpProxyEnabled bool) *http.Client {
|
||||
var (
|
||||
skip = ctx.Bool("transport.skip-verify")
|
||||
socks = ctx.String("transport.socks-proxy")
|
||||
socksoff = ctx.Bool("transport.socks-proxy-off")
|
||||
skip = c.Bool("transport.skip-verify")
|
||||
socks = c.String("transport.socks-proxy")
|
||||
socksOff = c.Bool("transport.socks-proxy-off")
|
||||
)
|
||||
|
||||
if httpProxyEnabled {
|
||||
if v := c.String("transport.http-proxy"); v != "" {
|
||||
os.Setenv("HTTP_PROXY", v)
|
||||
os.Setenv("http_proxy", v)
|
||||
}
|
||||
if v := c.String("transport.https-proxy"); v != "" {
|
||||
os.Setenv("HTTPS_PROXY", v)
|
||||
os.Setenv("https_proxy", v)
|
||||
}
|
||||
if v := c.String("transport.no-proxy"); v != "" {
|
||||
os.Setenv("NO_PROXY", v)
|
||||
os.Setenv("no_proxy", v)
|
||||
}
|
||||
}
|
||||
|
||||
certs, err := x509.SystemCertPool()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to find system CA certs")
|
||||
@@ -80,7 +133,7 @@ func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
||||
DualStack: true,
|
||||
}
|
||||
|
||||
if len(socks) != 0 && !socksoff {
|
||||
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")
|
||||
@@ -88,7 +141,7 @@ func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
||||
if contextDialer, ok := proxyDialer.(proxy.ContextDialer); ok {
|
||||
transport.DialContext = contextDialer.DialContext
|
||||
} else {
|
||||
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
transport.DialContext = func(_ context.Context, network, addr string) (net.Conn, error) {
|
||||
return proxyDialer.Dial(network, addr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,24 @@ import (
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func loggingFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "log-level",
|
||||
Usage: "log level",
|
||||
EnvVars: []string{"PLUGIN_LOG_LEVEL"},
|
||||
Value: "info",
|
||||
Name: "log-level",
|
||||
Usage: "log level",
|
||||
Sources: cli.EnvVars(
|
||||
"PLUGIN_LOG_LEVEL",
|
||||
),
|
||||
Value: "info",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// SetupConsoleLogger sets up the console logger.
|
||||
func SetupConsoleLogger(c *cli.Context) error {
|
||||
func SetupConsoleLogger(c *cli.Command) error {
|
||||
level := c.String("log-level")
|
||||
lvl, err := zerolog.ParseLevel(level)
|
||||
if err != nil {
|
||||
|
||||
+28
-14
@@ -15,27 +15,41 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
Repository Repository `json:"repo,omitempty"`
|
||||
Pipeline Pipeline `json:"curr,omitempty"`
|
||||
Commit Commit `json:"commit,omitempty"`
|
||||
PreviousCommit Commit `json:"previous_commit,omitempty"`
|
||||
Step Step `json:"step,omitempty"`
|
||||
System System `json:"sys,omitempty"`
|
||||
Forge Forge `json:"forge,omitempty"`
|
||||
|
||||
// Deprecated: Please use Commit instead.
|
||||
Curr Commit
|
||||
|
||||
// Deprecated: Please use PreviousCommit instead.
|
||||
Prev Commit `json:"prev,omitempty"`
|
||||
}
|
||||
|
||||
// MetadataFromContext creates a Metadata from the cli.Context.
|
||||
func MetadataFromContext(ctx *cli.Context) Metadata {
|
||||
func MetadataFromContext(c *cli.Command) Metadata {
|
||||
commit := commitFromContext(c)
|
||||
previousCommit := previousCommitFromContext(c)
|
||||
|
||||
return Metadata{
|
||||
Repository: repositoryFromContext(ctx),
|
||||
Pipeline: pipelineFromContext(ctx),
|
||||
Curr: currFromContext(ctx),
|
||||
Prev: prevFromContext(ctx),
|
||||
Step: stepFromContext(ctx),
|
||||
System: systemFromContext(ctx),
|
||||
Repository: repositoryFromContext(c),
|
||||
Pipeline: pipelineFromContext(c),
|
||||
Commit: commit,
|
||||
PreviousCommit: previousCommit,
|
||||
Step: stepFromContext(c),
|
||||
System: systemFromContext(c),
|
||||
Forge: forgeFromContext(c),
|
||||
|
||||
Curr: commit,
|
||||
Prev: previousCommit,
|
||||
}
|
||||
}
|
||||
|
||||
+17
-10
@@ -16,7 +16,6 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -48,11 +47,12 @@ func testMetadata() map[string]string {
|
||||
"CI_COMMIT_URL": "https://codeberg.org/woodpecker-plugins/go-plugin/commit/a1b2c3d4",
|
||||
// Build
|
||||
"CI_PIPELINE_NUMBER": "1",
|
||||
"CI_PIPELINE_EVENT": "push",
|
||||
"CI_PIPELINE_EVENT": EventTypePush,
|
||||
"CI_PIPELINE_URL": "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1",
|
||||
"CI_PIPELINE_STATUS": "running",
|
||||
"CI_PIPELINE_CREATED": "1611234567",
|
||||
"CI_PIPELINE_STARTED": "1611234567",
|
||||
"CI_PIPELINE_FILES": `["README.md", "main.go"]`,
|
||||
// Step
|
||||
"CI_STEP_NUMBER": "1",
|
||||
"CI_STEP_NAME": "test",
|
||||
@@ -63,26 +63,28 @@ func testMetadata() map[string]string {
|
||||
"CI_SYSTEM_URL": "https://ci.woodpecker-ci.org",
|
||||
"CI_SYSTEM_VERSION": "1.0.0",
|
||||
"CI_SYSTEM_HOST": "woodpecker-ci.org",
|
||||
// Forge
|
||||
"CI_FORGE_TYPE": ForgeTypeGitea,
|
||||
"CI_FORGE_URL": "https://codeberg.org",
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadata(t *testing.T) {
|
||||
for k, v := range testMetadata() {
|
||||
os.Setenv(k, v)
|
||||
defer os.Unsetenv(k)
|
||||
t.Setenv(k, v)
|
||||
}
|
||||
plugin := New(Options{
|
||||
Execute: func(ctx context.Context) error {
|
||||
Execute: func(_ context.Context) error {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
err := plugin.app.Run([]string{"test"})
|
||||
err := plugin.App.Run(plugin.ctx, []string{"test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Repository
|
||||
assert.Equal(t, "woodpecker", plugin.Metadata.Repository.Name)
|
||||
assert.Equal(t, "woodpecker-ci", plugin.Metadata.Repository.Owner)
|
||||
assert.Equal(t, "https://codeberg.org/woodpecker-plugins/go-plugin", plugin.Metadata.Repository.Link)
|
||||
assert.Equal(t, "https://codeberg.org/woodpecker-plugins/go-plugin", plugin.Metadata.Repository.URL)
|
||||
assert.Equal(t, "https://codeberg.org/woodpecker-plugins/go-plugin.git", plugin.Metadata.Repository.CloneURL)
|
||||
assert.Equal(t, "main", plugin.Metadata.Repository.Branch)
|
||||
assert.False(t, plugin.Metadata.Repository.Private)
|
||||
@@ -99,11 +101,12 @@ func TestMetadata(t *testing.T) {
|
||||
|
||||
// Pipeline
|
||||
assert.Equal(t, int64(1), plugin.Metadata.Pipeline.Number)
|
||||
assert.Equal(t, "push", plugin.Metadata.Pipeline.Event)
|
||||
assert.Equal(t, "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1", plugin.Metadata.Pipeline.Link)
|
||||
assert.Equal(t, EventTypePush, plugin.Metadata.Pipeline.Event)
|
||||
assert.Equal(t, "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1", plugin.Metadata.Pipeline.URL)
|
||||
assert.Equal(t, "running", plugin.Metadata.Pipeline.Status)
|
||||
assert.Equal(t, time.Unix(1611234567, 0), plugin.Metadata.Pipeline.Created)
|
||||
assert.Equal(t, time.Unix(1611234567, 0), plugin.Metadata.Pipeline.Started)
|
||||
assert.Equal(t, []string{"README.md", "main.go"}, plugin.Metadata.Pipeline.ChangedFiles)
|
||||
|
||||
// Step
|
||||
assert.Equal(t, 1, plugin.Metadata.Step.Number)
|
||||
@@ -111,7 +114,11 @@ func TestMetadata(t *testing.T) {
|
||||
|
||||
// System
|
||||
assert.Equal(t, "woodpecker", plugin.Metadata.System.Name)
|
||||
assert.Equal(t, "https://ci.woodpecker-ci.org", plugin.Metadata.System.Link)
|
||||
assert.Equal(t, "https://ci.woodpecker-ci.org", plugin.Metadata.System.URL)
|
||||
assert.Equal(t, "1.0.0", plugin.Metadata.System.Version)
|
||||
assert.Equal(t, "woodpecker-ci.org", plugin.Metadata.System.Host)
|
||||
|
||||
// Forge
|
||||
assert.Equal(t, ForgeTypeGitea, plugin.Metadata.Forge.Type)
|
||||
assert.Equal(t, "https://codeberg.org", plugin.Metadata.Forge.URL)
|
||||
}
|
||||
|
||||
+59
-24
@@ -15,9 +15,21 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
EventTypePush = "push"
|
||||
EventTypePullRequest = "pull_request"
|
||||
EventTypeTag = "tag"
|
||||
EventTypeDeployment = "deployment"
|
||||
EventTypeCron = "cron"
|
||||
EventTypeManual = "manual"
|
||||
)
|
||||
|
||||
// Pipeline defines runtime metadata for a pipeline.
|
||||
@@ -25,12 +37,16 @@ type Pipeline struct {
|
||||
Number int64 `json:"number,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Event string `json:"event,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
URL string `json:"url,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"`
|
||||
ChangedFiles []string `json:"files,omitempty"`
|
||||
|
||||
// Deprecated: Please use URL instead.
|
||||
Link string `json:"link,omitempty"`
|
||||
}
|
||||
|
||||
func pipelineFlags() []cli.Flag {
|
||||
@@ -38,89 +54,108 @@ func pipelineFlags() []cli.Flag {
|
||||
&cli.Int64Flag{
|
||||
Name: "pipeline.number",
|
||||
Usage: "pipeline number",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_NUMBER",
|
||||
"DRONE_BUILD_NUMBER",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pipeline.status",
|
||||
Usage: "pipeline status",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_STATUS",
|
||||
"DRONE_BUILD_STATUS",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pipeline.event",
|
||||
Usage: "pipeline event",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_EVENT",
|
||||
"DRONE_BUILD_EVENT",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pipeline.link",
|
||||
Usage: "pipeline link",
|
||||
EnvVars: []string{
|
||||
Name: "pipeline.url",
|
||||
Aliases: []string{"pipeline.link"},
|
||||
Usage: "pipeline url",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_URL",
|
||||
"CI_PIPELINE_LINK",
|
||||
"DRONE_BUILD_LINK",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pipeline.deploy-target",
|
||||
Usage: "pipeline deployment target",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_DEPLOY_TARGET",
|
||||
"DRONE_DEPLOY_TO",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "pipeline.created",
|
||||
Usage: "pipeline creation time",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_CREATED",
|
||||
"DRONE_BUILD_CREATED",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "pipeline.started",
|
||||
Usage: "pipeline start time",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_STARTED",
|
||||
"DRONE_BUILD_STARTED",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "pipeline.finished",
|
||||
Usage: "pipeline finish time",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_FINISHED",
|
||||
"DRONE_BUILD_FINISHED",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "pipeline.parent",
|
||||
Usage: "pipeline parent",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_PARENT",
|
||||
"DRONE_BUILD_PARENT",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "pipeline.files",
|
||||
Usage: "pipeline changed files (string list as json)",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_PIPELINE_FILES",
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func pipelineFromContext(c *cli.Context) Pipeline {
|
||||
func pipelineFromContext(c *cli.Command) Pipeline {
|
||||
var changedFiles []string
|
||||
|
||||
if files := c.String("pipeline.files"); files != "" {
|
||||
if err := json.Unmarshal([]byte(files), &changedFiles); err != nil {
|
||||
log.Error().Err(err).Msg("parse \"CI_PIPELINE_FILES\" failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
return Pipeline{
|
||||
Number: c.Int64("pipeline.number"),
|
||||
Status: c.String("pipeline.status"),
|
||||
Event: c.String("pipeline.event"),
|
||||
Link: c.String("pipeline.link"),
|
||||
URL: c.String("pipeline.url"),
|
||||
Link: c.String("pipeline.url"),
|
||||
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"),
|
||||
ChangedFiles: changedFiles,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// Options defines the options for the plugin.
|
||||
@@ -36,13 +36,22 @@ type Options struct {
|
||||
Flags []cli.Flag
|
||||
// Execute function of the plugin.
|
||||
Execute ExecuteFunc
|
||||
// Context the plugin will use while executing.
|
||||
Context context.Context
|
||||
// EnableHTTPProxy allows plugins to opt-in to HTTP/HTTPS proxy support.
|
||||
// When true, PLUGIN_HTTP_PROXY, PLUGIN_HTTPS_PROXY and PLUGIN_NO_PROXY
|
||||
// are accepted as settings and applied to the HTTP client.
|
||||
EnableHTTPProxy bool
|
||||
}
|
||||
|
||||
// Plugin defines the plugin instance.
|
||||
type Plugin struct {
|
||||
app *cli.App
|
||||
App *cli.Command
|
||||
execute ExecuteFunc
|
||||
client *http.Client
|
||||
ctx context.Context
|
||||
// enableHTTPProxy controls whether HTTP proxy flags are registered and applied.
|
||||
enableHTTPProxy bool
|
||||
// Metadata of the current pipeline.
|
||||
Metadata Metadata
|
||||
}
|
||||
@@ -56,35 +65,47 @@ func New(opt Options) *Plugin {
|
||||
_ = godotenv.Overload("/run/woodpecker/env")
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
app := &cli.Command{
|
||||
Name: opt.Name,
|
||||
Usage: "Run the Woodpecker CI plugin",
|
||||
Description: opt.Description,
|
||||
Version: opt.Version,
|
||||
Flags: append(opt.Flags, Flags()...),
|
||||
}
|
||||
|
||||
plugin := &Plugin{
|
||||
app: app,
|
||||
execute: opt.Execute,
|
||||
App: app,
|
||||
execute: opt.Execute,
|
||||
ctx: opt.Context,
|
||||
enableHTTPProxy: opt.EnableHTTPProxy,
|
||||
}
|
||||
|
||||
if opt.EnableHTTPProxy {
|
||||
app.Flags = append(app.Flags, httpProxyFlags()...)
|
||||
}
|
||||
|
||||
plugin.App.Action = plugin.action
|
||||
|
||||
if plugin.ctx == nil {
|
||||
plugin.ctx = context.Background()
|
||||
}
|
||||
plugin.app.Action = plugin.action
|
||||
|
||||
return plugin
|
||||
}
|
||||
|
||||
func (p *Plugin) action(ctx *cli.Context) error {
|
||||
if err := SetupConsoleLogger(ctx); err != nil {
|
||||
func (p *Plugin) action(ctx context.Context, c *cli.Command) error {
|
||||
if err := SetupConsoleLogger(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.Metadata = MetadataFromContext(ctx)
|
||||
p.client = HTTPClientFromContext(ctx)
|
||||
p.Metadata = MetadataFromContext(c)
|
||||
p.client = HTTPClientFromContext(c, p.enableHTTPProxy)
|
||||
|
||||
if p.execute == nil {
|
||||
panic("plugin execute function is not set")
|
||||
}
|
||||
|
||||
return p.execute(ctx.Context)
|
||||
return p.execute(ctx)
|
||||
}
|
||||
|
||||
// HTTPClient returns the http.Client instance.
|
||||
@@ -94,7 +115,7 @@ func (p *Plugin) HTTPClient() *http.Client {
|
||||
|
||||
// Run the plugin.
|
||||
func (p *Plugin) Run() {
|
||||
if err := p.app.Run(os.Args); err != nil {
|
||||
if err := p.App.Run(p.ctx, os.Args); err != nil {
|
||||
log.Error().Err(err).Msg("execution failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,12 +25,12 @@ func TestPlugin(t *testing.T) {
|
||||
var executed bool
|
||||
p := New(Options{
|
||||
Name: "test",
|
||||
Execute: func(ctx context.Context) error {
|
||||
Execute: func(_ context.Context) error {
|
||||
executed = true
|
||||
return nil
|
||||
},
|
||||
})
|
||||
err := p.app.Run([]string{"test"})
|
||||
err := p.App.Run(p.ctx, []string{"test"})
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, executed)
|
||||
}
|
||||
|
||||
@@ -15,80 +15,96 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
RemoteID string `json:"remote_id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
CloneURL string `json:"clone_url,omitempty"`
|
||||
Private bool `json:"private,omitempty"`
|
||||
DefaultBranch string `json:"default_branch,omitempty"`
|
||||
|
||||
// Deprecated: Please use DefaultBranch instead.
|
||||
Branch string
|
||||
}
|
||||
|
||||
func repositoryFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "repo.remote-id",
|
||||
Usage: "repo remote id",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_REMOTE_ID",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo.name",
|
||||
Usage: "repo name",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_NAME",
|
||||
"DRONE_REPO_NAME",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
Usage: "repo owner",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_OWNER",
|
||||
"DRONE_REPO_OWNER",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo.link",
|
||||
Usage: "repo link",
|
||||
EnvVars: []string{
|
||||
Name: "repo.url",
|
||||
Aliases: []string{"repo.link"},
|
||||
Usage: "repo url",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_URL",
|
||||
"CI_REPO_LINK",
|
||||
"DRONE_REPO_LINK",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo.clone-url",
|
||||
Usage: "repo clone url",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_CLONE_URL",
|
||||
"DRONE_GIT_HTTP_URL",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "repo.private",
|
||||
Usage: "repo private",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_PRIVATE",
|
||||
"DRONE_REPO_PRIVATE",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "repo.default-branch",
|
||||
Usage: "repo default branch",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_REPO_DEFAULT_BRANCH",
|
||||
"DRONE_REPO_BRANCH",
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func repositoryFromContext(c *cli.Context) Repository {
|
||||
func repositoryFromContext(c *cli.Command) 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"),
|
||||
RemoteID: c.String("repo.remote-id"),
|
||||
Name: c.String("repo.name"),
|
||||
Owner: c.String("repo.owner"),
|
||||
URL: c.String("repo.url"),
|
||||
Link: c.String("repo.url"),
|
||||
CloneURL: c.String("repo.clone-url"),
|
||||
Private: c.Bool("repo.private"),
|
||||
Branch: c.String("repo.default-branch"),
|
||||
DefaultBranch: c.String("repo.default-branch"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,45 +17,74 @@ package plugin
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// Step defines runtime metadata for a step.
|
||||
type Step struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Type StepType `json:"type,omitempty"`
|
||||
Number int `json:"number,omitempty"`
|
||||
Started time.Time `json:"started,omitempty"`
|
||||
Finished time.Time `json:"finished,omitempty"`
|
||||
}
|
||||
|
||||
// StepType identifies the type of step.
|
||||
type StepType string
|
||||
|
||||
const (
|
||||
StepTypeClone StepType = "clone"
|
||||
StepTypeService StepType = "service"
|
||||
StepTypePlugin StepType = "plugin"
|
||||
StepTypeCommands StepType = "commands"
|
||||
StepTypeCache StepType = "cache"
|
||||
)
|
||||
|
||||
func stepFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "step.name",
|
||||
Usage: "step name",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_STEP_NAME",
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "step.type",
|
||||
Usage: "step type",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_STEP_TYPE",
|
||||
),
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "step.number",
|
||||
Usage: "step number",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_STEP_NUMBER",
|
||||
"DRONE_STEP_NUMBER",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "step.started",
|
||||
Usage: "step start time",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_STEP_STARTED",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.Int64Flag{
|
||||
Name: "step.finished",
|
||||
Usage: "step finish time",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_STEP_FINISHED",
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func stepFromContext(c *cli.Context) Step {
|
||||
func stepFromContext(c *cli.Command) Step {
|
||||
return Step{
|
||||
Name: c.String("step.name"),
|
||||
Type: StepType(c.String("step.type")),
|
||||
Number: c.Int("step.number"),
|
||||
Started: time.Unix(c.Int64("step.started"), 0),
|
||||
Finished: time.Unix(c.Int64("step.finished"), 0),
|
||||
|
||||
@@ -17,16 +17,19 @@ package plugin
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// Deprecated: Please use URL instead.
|
||||
Link string `json:"link,omitempty"`
|
||||
}
|
||||
|
||||
func systemFlags() []cli.Flag {
|
||||
@@ -34,61 +37,63 @@ func systemFlags() []cli.Flag {
|
||||
&cli.StringFlag{
|
||||
Name: "system.name",
|
||||
Usage: "system name",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_SYSTEM_NAME",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "system.host",
|
||||
Usage: "system host",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_SYSTEM_HOST",
|
||||
"DRONE_SYSTEM_HOST",
|
||||
"DRONE_SYSTEM_HOSTNAME",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "system.link",
|
||||
Usage: "system link",
|
||||
EnvVars: []string{
|
||||
Name: "system.url",
|
||||
Aliases: []string{"system.link"},
|
||||
Usage: "system url",
|
||||
Sources: cli.EnvVars(
|
||||
"CI_SYSTEM_URL",
|
||||
"CI_SYSTEM_LINK",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "system.arch",
|
||||
Usage: "system arch",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_SYSTEM_PLATFORM",
|
||||
"DRONE_STAGE_ARCH",
|
||||
},
|
||||
),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "system.version",
|
||||
Usage: "system version",
|
||||
EnvVars: []string{
|
||||
Sources: cli.EnvVars(
|
||||
"CI_SYSTEM_VERSION",
|
||||
"DRONE_SYSTEM_VERSION",
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func systemFromContext(ctx *cli.Context) System {
|
||||
link := ctx.String("system.link")
|
||||
host := ctx.String("system.host")
|
||||
if link == "" && host != "" {
|
||||
// Alternative link format used by Drone.
|
||||
func systemFromContext(c *cli.Command) System {
|
||||
url := c.String("system.url")
|
||||
host := c.String("system.host")
|
||||
if url == "" && host != "" {
|
||||
// Alternative url format used by Drone.
|
||||
proto := os.Getenv("DRONE_SYSTEM_PROTO")
|
||||
if proto != "" {
|
||||
link = proto + "://" + host
|
||||
url = proto + "://" + host
|
||||
}
|
||||
}
|
||||
return System{
|
||||
Name: ctx.String("system.name"),
|
||||
Name: c.String("system.name"),
|
||||
Host: host,
|
||||
Link: link,
|
||||
Platform: ctx.String("system.arch"),
|
||||
Version: ctx.String("system.version"),
|
||||
URL: url,
|
||||
Link: url,
|
||||
Platform: c.String("system.arch"),
|
||||
Version: c.String("system.version"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user