2023-01-08 03:53:03 +01:00
|
|
|
# Library for creating Woodpecker CI plugins
|
|
|
|
|
|
|
|
Provides basic structure and helpers to load Woodpecker CI environment variables while also
|
|
|
|
supporting reading Drone CI environment variables where available.
|
|
|
|
|
|
|
|
Adds logging support based on [zerolog](https://github.com/rs/zerolog) library and allows configurable
|
|
|
|
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 |
|
|
|
|
|
|
|
|
## Creating plugin
|
|
|
|
|
|
|
|
```go
|
2023-11-15 18:33:12 +01:00
|
|
|
package main
|
|
|
|
|
2023-01-08 03:53:03 +01:00
|
|
|
import (
|
2023-11-15 18:33:12 +01:00
|
|
|
"context"
|
2023-01-08 03:53:03 +01:00
|
|
|
|
2023-11-15 18:33:12 +01:00
|
|
|
"codeberg.org/woodpecker-plugins/go-plugin"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/urfave/cli/v2"
|
2023-01-08 03:53:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Settings struct {
|
2023-11-15 18:33:12 +01:00
|
|
|
// TODO: Plugin settings
|
|
|
|
SampleFlag string
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Plugin struct {
|
2023-11-15 18:33:12 +01:00
|
|
|
*plugin.Plugin
|
|
|
|
Settings *Settings
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Plugin) Flags() []cli.Flag {
|
2023-11-15 18:33:12 +01:00
|
|
|
return []cli.Flag{
|
|
|
|
// TODO: Add flags
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "sample.flag",
|
|
|
|
Usage: "sample flag",
|
|
|
|
EnvVars: []string{"PLUGIN_SAMPLE_FLAG"},
|
|
|
|
Destination: &p.Settings.SampleFlag,
|
|
|
|
},
|
|
|
|
}
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Plugin) Execute(ctx context.Context) error {
|
2023-11-15 18:33:12 +01:00
|
|
|
// TODO: Implement execution
|
|
|
|
log.Debug().Msg("executed")
|
|
|
|
return nil
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-11-15 18:33:12 +01:00
|
|
|
p := &Plugin{
|
|
|
|
Settings: &Settings{},
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Plugin = plugin.New(plugin.Options{
|
|
|
|
Name: "sample-plugin",
|
|
|
|
Description: "Sample plugin",
|
|
|
|
Flags: p.Flags(),
|
|
|
|
Execute: p.Execute,
|
|
|
|
})
|
2023-01-08 03:53:03 +01:00
|
|
|
|
2023-11-15 18:33:12 +01:00
|
|
|
p.Run()
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
```
|