drone

package module
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 23 Imported by: 20

README

drone

Drone插件基础框架,提供如下功能

  • 基础配置
    • 重试
    • 背压
    • 配置解析
    • 命名
  • 接口抽象
    • 步骤
    • 配置
    • 插件

编写插件

使用drone库编写插件非常简单,只需要两步

插件主文件plugin.go

用于描述插件的主文件,主要是实现drone.Plugin接口,大致代码如下

package main

import (
    `github.com/dronestock/drone`
)

type plugin struct {
    drone.PluginBase

    // 远程仓库地址
    Remote string `default:"${PLUGIN_REMOTE=${REMOTE=${DRONE_GIT_HTTP_URL}}}" validate:"required"`
    // 模式
    Mode string `default:"${PLUGIN_MODE=${MODE=push}}"`
    // SSH密钥
    SSHKey string `default:"${PLUGIN_SSH_KEY=${SSH_KEY}}"`
    // 目录
    Folder string `default:"${PLUGIN_FOLDER=${FOLDER=.}}" validate:"required"`
    // 目录列表
    Folders []string `default:"${PLUGIN_FOLDERS=${FOLDERS}}"`
    // 分支
    Branch string `default:"${PLUGIN_BRANCH=${BRANCH=master}}" validate:"required_without=Commit"`
    // 标签
    Tag string `default:"${PLUGIN_TAG=${TAG}}"`
    // 作者
    Author string `default:"${PLUGIN_AUTHOR=${AUTHOR=${DRONE_COMMIT_AUTHOR}}}"`
    // 邮箱
    Email string `default:"${PLUGIN_EMAIL=${EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL}}}"`
    // 提交消息
    Message string `default:"${PLUGIN_MESSAGE=${MESSAGE=${PLUGIN_COMMIT_MESSAGE=drone}}}"`
    // 是否强制提交
    Force bool `default:"${PLUGIN_FORCE=${FORCE=true}}"`

    // 子模块
    Submodules bool `default:"${PLUGIN_SUBMODULES=${SUBMODULES=true}}"`
    // 深度
    Depth int `default:"${PLUGIN_DEPTH=${DEPTH=50}}"`
    // 提交
    Commit string `default:"${PLUGIN_COMMIT=${COMMIT=${DRONE_COMMIT}}}" validate:"required_without=Branch"`

    // 是否清理
    Clear bool `default:"${PLUGIN_CLEAR=${CLEAR=true}}"`
}

func newPlugin() drone.Plugin {
    return new(plugin)
}

func (p *plugin) Config() drone.Config {
    return p
}

func (p *plugin) Steps() []*drone.Step {
    return []*drone.Step{
        drone.NewStep(p.github, drone.Name(`Github加速`)),
        drone.NewStep(p.clear, drone.Name(`清理Git目录`)),
        drone.NewStep(p.ssh, drone.Name(`写入SSH配置`)),
        drone.NewStep(p.pull, drone.Name(`拉代码`)),
        drone.NewStep(p.push, drone.Name(`推代码`)),
    }
}

// 业务逻辑代码
func (p *plugin) github() (undo bool, err error) {
    return
}

// 业务逻辑代码
func (p *plugin) clear() (undo bool, err error) {
    return
}

// 业务逻辑代码
func (p *plugin) ssh() (undo bool, err error) {
    return
}

// 业务逻辑代码
func (p *plugin) pull() (undo bool, err error) {
    return
}

// 业务逻辑代码
func (p *plugin) push() (undo bool, err error) {
    return
}

其中,需要实现的方法步骤有

  • github
  • clear
  • ssh
  • pull
  • push
启动文件main.go

启动文件负责启动整个程序,是一个非常轻量的壳

package main

import (
	`github.com/dronestock/drone`
)

func main() {
	panic(drone.Bootstrap(newPlugin, drone.Configs(`FOLDERS`)))
}

捐助

支持宝 微信

感谢Jetbrains

本项目通过Jetbrains开源许可IDE编写源代码,特此感谢 Jetbrains图标

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v0.6.4

func New(constructor constructor) *bootstrap

func NewStep added in v0.0.2

func NewStep(stepper stepper) *stepBuilder

NewStep 创建一个步骤

Types

type Base added in v0.1.0

type Base struct {
	simaqian.Logger

	// 是否启用默认配置
	Defaults bool `default:"${DEFAULTS=true}"`
	// 是否显示详细信息
	Verbose bool `default:"${VERBOSE=false}"`
	// 日志配置
	Log log `default:"${LOG}"`
	// 是否在出错时打印输出
	Pwe bool `default:"${PWE=true}"`

	// 是否重试
	Retry bool `default:"${RETRY=true}"`
	// 重试次数
	Counts int `default:"${COUNTS=5}"`
	// 重试间隔
	Backoff time.Duration `default:"${BACKOFF=5s}"`

	// 代理
	Proxy *proxy `default:"${PROXY}"`
	// 卡片
	Card card `default:"${CARD}"`
	// contains filtered or unexported fields
}

Base 插件基础

func (*Base) BaseConfig added in v0.3.7

func (b *Base) BaseConfig() *Base

func (*Base) Carding added in v0.6.4

func (b *Base) Carding() (card any, err error)

func (*Base) Command added in v0.6.4

func (b *Base) Command(command string) *commandBuilder

func (*Base) Fields added in v0.1.0

func (b *Base) Fields() gox.Fields[any]

func (*Base) Http added in v0.6.1

func (b *Base) Http() *resty.Request

func (*Base) Parse added in v0.1.0

func (b *Base) Parse(to map[string]string, configs ...string)

func (*Base) Parses added in v0.1.0

func (b *Base) Parses(to map[string][]string, configs ...string)

func (*Base) Scheme added in v0.4.8

func (b *Base) Scheme() (scheme string)

func (*Base) Setup added in v0.1.0

func (b *Base) Setup() (unset bool, err error)

type Config

type Config interface {
	// Setup 设置配置信息
	Setup() (unset bool, err error)

	// Fields 导出所有字段
	Fields() gox.Fields[any]

	// BaseConfig 基础配置
	BaseConfig() *Base
}

Config 配置

type Plugin added in v0.0.2

type Plugin interface {
	// Scheme 卡片模板
	Scheme() (scheme string)

	// Carding 卡片数据
	Carding() (card any, err error)

	// Config 加载配置
	Config() (config Config)

	// Steps 插件运行步骤
	Steps() Steps
}

Plugin 插件接口,任何插件都需要实现这个接口

type Step added in v0.0.2

type Step struct {
	gox.CannotCopy
	// contains filtered or unexported fields
}

Step 步骤

func NewDebugStep added in v0.5.1

func NewDebugStep() *Step

NewDebugStep 创建延迟步骤,调试使用

func NewDelayStep added in v0.2.5

func NewDelayStep(delay time.Duration) *Step

NewDelayStep 创建延迟步骤,调试使用

type Steps added in v0.5.4

type Steps []*Step

Steps 步骤集

func (*Steps) Add added in v0.5.6

func (s *Steps) Add(steps ...*Step)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL