mirror of
https://codeberg.org/woodpecker-plugins/go-plugin.git
synced 2024-12-28 05:17:42 +01:00
67b6cdf4a6
Reviewed-on: https://codeberg.org/woodpecker-plugins/go-plugin/pulls/29 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
74 lines
2.1 KiB
Markdown
74 lines
2.1 KiB
Markdown
# 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
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"codeberg.org/woodpecker-plugins/go-plugin"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
type Settings struct {
|
|
// TODO: Plugin settings
|
|
SampleFlag string
|
|
}
|
|
|
|
type Plugin struct {
|
|
*plugin.Plugin
|
|
Settings *Settings
|
|
}
|
|
|
|
func (p *Plugin) Flags() []cli.Flag {
|
|
return []cli.Flag{
|
|
// TODO: Add flags
|
|
&cli.StringFlag{
|
|
Name: "sample.flag",
|
|
Usage: "sample flag",
|
|
Sources: cli.EnvVars("PLUGIN_SAMPLE_FLAG"),
|
|
Destination: &p.Settings.SampleFlag,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (p *Plugin) Execute(ctx context.Context) error {
|
|
// TODO: Implement execution
|
|
log.Debug().Msg("executed")
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
p := &Plugin{
|
|
Settings: &Settings{},
|
|
}
|
|
|
|
p.Plugin = plugin.New(plugin.Options{
|
|
Name: "sample-plugin",
|
|
Description: "Sample plugin",
|
|
Flags: p.Flags(),
|
|
Execute: p.Execute,
|
|
})
|
|
|
|
p.Run()
|
|
}
|
|
```
|