mirror of
https://codeberg.org/woodpecker-plugins/go-plugin.git
synced 2024-09-27 01:41:21 +02:00
Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
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 | ||
|
30c031631d | ||
|
f02d9dcbb4 | ||
|
39a7259ed0 | ||
|
275eb26ca7 | ||
|
f1c4c040ce | ||
|
174f822f73 | ||
|
ab2091b8bc | ||
|
7a77b4deb6 | ||
|
1396daf59f | ||
|
4595cecac4 | ||
|
629a1a9258 | ||
|
875983b71f | ||
|
1baf72dd81 | ||
|
92ff2797fa | ||
|
18a1562886 | ||
|
afbbefb22e |
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -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/
|
@ -1,15 +1,34 @@
|
|||||||
variables:
|
when:
|
||||||
- &golang 'golang:1.18'
|
- event: [pull_request, tag, cron]
|
||||||
|
- event: push
|
||||||
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
- 'renovate/*'
|
||||||
|
|
||||||
pipeline:
|
variables:
|
||||||
- name: vendor
|
- &golang "golang:1.23"
|
||||||
|
- &golangci-lint "golangci/golangci-lint:v1.61-alpine"
|
||||||
|
- &reviewdog-golangci-lint "woodpeckerci/plugin-reviewdog-golangci-lint:1.59"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
vendor:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands: go mod vendor
|
commands: go mod vendor
|
||||||
|
|
||||||
- name: lint
|
review-go:
|
||||||
image: golangci/golangci-lint:v1.50-alpine
|
image: *reviewdog-golangci-lint
|
||||||
commands: golangci-lint run
|
settings:
|
||||||
|
token:
|
||||||
|
from_secret: reviewdog_token
|
||||||
|
when:
|
||||||
|
event: pull_request
|
||||||
|
|
||||||
- name: test
|
lint:
|
||||||
|
image: *golangci-lint
|
||||||
|
commands: golangci-lint run --timeout 5m
|
||||||
|
when:
|
||||||
|
event: [push, tag, cron]
|
||||||
|
|
||||||
|
test:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands: go test --cover ./...
|
commands: go test --cover ./...
|
||||||
|
76
README.md
76
README.md
@ -8,64 +8,66 @@ HTTP client library.
|
|||||||
|
|
||||||
## Builtin settings
|
## Builtin settings
|
||||||
|
|
||||||
| Settings Name | Environment variable | Default | Description |
|
| Settings Name | Environment variable | Default | Description |
|
||||||
|---|---|----|---|
|
| ------------- | -------------------- | ------- | ---------------------------------------------------------------------------- | ------------------------------------ |
|
||||||
| `log_level` | - | `info` | Sets log level (`panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`) |
|
| `log_level` | - | `info` | Sets log level (`panic`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`) |
|
||||||
| `skip_verify` | - | `false` | - | Skip verification of TLS certificate |
|
| `skip_verify` | - | `false` | - | Skip verification of TLS certificate |
|
||||||
| | `SOCKS_PROXY` | *none* | SOCKS5 proxy to use for connections |
|
| | `SOCKS_PROXY` | _none_ | SOCKS5 proxy to use for connections |
|
||||||
| | `SOCKS_PROXY_OFF` | *none* | Do not use SOCKS5 proxy |
|
| | `SOCKS_PROXY_OFF` | _none_ | Do not use SOCKS5 proxy |
|
||||||
|
|
||||||
## Creating plugin
|
## Creating plugin
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
package main
|
||||||
"context"
|
|
||||||
|
|
||||||
"codeberg.org/woodpecker-plugins/go-plugin"
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"context"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
"codeberg.org/woodpecker-plugins/go-plugin"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
// TODO: Plugin settings
|
// TODO: Plugin settings
|
||||||
SampleFlag string
|
SampleFlag string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
*plugin.Plugin
|
*plugin.Plugin
|
||||||
Settings *Settings
|
Settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) Flags() []cli.Flag {
|
func (p *Plugin) Flags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
// TODO: Add flags
|
// TODO: Add flags
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "sample.flag",
|
Name: "sample.flag",
|
||||||
Usage: "sample flag",
|
Usage: "sample flag",
|
||||||
EnvVars: []string{"PLUGIN_SAMPLE_FLAG"},
|
Sources: cli.EnvVars("PLUGIN_SAMPLE_FLAG"),
|
||||||
Destination: &p.Settings.SampleFlag,
|
Destination: &p.Settings.SampleFlag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) Execute(ctx context.Context) error {
|
func (p *Plugin) Execute(ctx context.Context) error {
|
||||||
// TODO: Implement execution
|
// TODO: Implement execution
|
||||||
log.Debug().Msg("executed")
|
log.Debug().Msg("executed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := &Plugin{
|
p := &Plugin{
|
||||||
&Settings{}
|
Settings: &Settings{},
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Plugin = plugin.New(Options{
|
p.Plugin = plugin.New(plugin.Options{
|
||||||
Name: "sample-plugin",
|
Name: "sample-plugin",
|
||||||
Description: "Sample plugin",
|
Description: "Sample plugin",
|
||||||
Flags: p.Flags(),
|
Flags: p.Flags(),
|
||||||
Execute: p.Execute,
|
Execute: p.Execute,
|
||||||
})
|
})
|
||||||
|
|
||||||
p.Run()
|
p.Run()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
184
commit.go
184
commit.go
@ -15,7 +15,7 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -41,72 +41,109 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func currFlags() []cli.Flag {
|
func commitFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.sha",
|
Name: "commit.sha",
|
||||||
Usage: "commit SHA",
|
Usage: "commit SHA",
|
||||||
EnvVars: []string{"CI_COMMIT_SHA", "DRONE_COMMIT", "DRONE_COMMIT_SHA"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_SHA",
|
||||||
|
"DRONE_COMMIT",
|
||||||
|
"DRONE_COMMIT_SHA",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.ref",
|
Name: "commit.ref",
|
||||||
Usage: "commit ref",
|
Usage: "commit ref",
|
||||||
EnvVars: []string{"CI_COMMIT_REF", "DRONE_COMMIT_REF"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_REF",
|
||||||
|
"DRONE_COMMIT_REF",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.refspec",
|
Name: "commit.refspec",
|
||||||
Usage: "commit refspec",
|
Usage: "commit refspec",
|
||||||
EnvVars: []string{"CI_COMMIT_REFSPEC"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_REFSPEC",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.pull-request",
|
Name: "commit.pull-request",
|
||||||
Usage: "commit pull request",
|
Usage: "commit pull request",
|
||||||
EnvVars: []string{"CI_COMMIT_PULL_REQUEST", "DRONE_PULL_REQUEST"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_PULL_REQUEST",
|
||||||
|
"DRONE_PULL_REQUEST",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.source-branch",
|
Name: "commit.source-branch",
|
||||||
Usage: "commit source branch",
|
Usage: "commit source branch",
|
||||||
EnvVars: []string{"CI_COMMIT_SOURCE_BRANCH", "DRONE_SOURCE_BRANCH"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_SOURCE_BRANCH",
|
||||||
|
"DRONE_SOURCE_BRANCH",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.target-branch",
|
Name: "commit.target-branch",
|
||||||
Usage: "commit target branch",
|
Usage: "commit target branch",
|
||||||
EnvVars: []string{"CI_COMMIT_TARGET_BRANCH", "DRONE_TARGET_BRANCH"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_TARGET_BRANCH",
|
||||||
|
"DRONE_TARGET_BRANCH",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.branch",
|
Name: "commit.branch",
|
||||||
Usage: "commit branch",
|
Usage: "commit branch",
|
||||||
EnvVars: []string{"CI_COMMIT_BRANCH", "DRONE_BRANCH"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_BRANCH",
|
||||||
|
"DRONE_BRANCH",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.tag",
|
Name: "commit.tag",
|
||||||
Usage: "commit tag",
|
Usage: "commit tag",
|
||||||
EnvVars: []string{"CI_COMMIT_TAG", "DRONE_TAG"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_TAG",
|
||||||
|
"DRONE_TAG",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.message",
|
Name: "commit.message",
|
||||||
Usage: "commit message",
|
Usage: "commit message",
|
||||||
EnvVars: []string{"CI_COMMIT_MESSAGE", "DRONE_COMMIT_MESSAGE"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_MESSAGE",
|
||||||
|
"DRONE_COMMIT_MESSAGE",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.author.name",
|
Name: "commit.author.name",
|
||||||
Usage: "commit author name",
|
Usage: "commit author name",
|
||||||
EnvVars: []string{"CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR_NAME"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_AUTHOR",
|
||||||
|
"DRONE_COMMIT_AUTHOR",
|
||||||
|
"DRONE_COMMIT_AUTHOR_NAME",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.author.email",
|
Name: "commit.author.email",
|
||||||
Usage: "commit author email",
|
Usage: "commit author email",
|
||||||
EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_COMMIT_AUTHOR_EMAIL",
|
||||||
|
"DRONE_COMMIT_AUTHOR_EMAIL",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "commit.author.avatar",
|
Name: "commit.author.avatar",
|
||||||
Usage: "commit author avatar",
|
Usage: "commit author avatar",
|
||||||
EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR", "DRONE_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{
|
return Commit{
|
||||||
Sha: c.String("commit.sha"),
|
Sha: c.String("commit.sha"),
|
||||||
Ref: c.String("commit.ref"),
|
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{
|
return []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.sha",
|
Name: "prev.commit.sha",
|
||||||
Usage: "previous commit SHA",
|
Usage: "previous commit SHA",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_SHA", "DRONE_COMMIT_BEFORE"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_SHA",
|
||||||
|
"DRONE_COMMIT_BEFORE",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.ref",
|
Name: "prev.commit.ref",
|
||||||
Usage: "previous commit ref",
|
Usage: "previous commit ref",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_REF"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_REF",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.refspec",
|
Name: "prev.commit.refspec",
|
||||||
Usage: "previous commit refspec",
|
Usage: "previous commit refspec",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_REFSPEC"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_REFSPEC",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.branch",
|
Name: "prev.commit.branch",
|
||||||
Usage: "previous commit branch",
|
Usage: "previous commit branch",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_BRANCH"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_BRANCH",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.message",
|
Name: "prev.commit.message",
|
||||||
Usage: "previous commit message",
|
Usage: "previous commit message",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_MESSAGE",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.author.name",
|
Name: "prev.commit.author.name",
|
||||||
Usage: "previous commit author name",
|
Usage: "previous commit author name",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_AUTHOR",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.author.email",
|
Name: "prev.commit.author.email",
|
||||||
Usage: "previous commit author email",
|
Usage: "previous commit author email",
|
||||||
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_EMAIL"},
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PREV_COMMIT_AUTHOR_EMAIL",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "prev.commit.author.avatar",
|
Name: "prev.commit.author.avatar",
|
||||||
Usage: "previous commit author avatar",
|
Usage: "previous commit author avatar",
|
||||||
EnvVars: []string{"CI_PREV_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{
|
return Commit{
|
||||||
Sha: c.String("prev.commit.sha"),
|
Sha: c.String("prev.commit.sha"),
|
||||||
Ref: c.String("prev.commit.ref"),
|
Ref: c.String("prev.commit.ref"),
|
||||||
|
7
flags.go
7
flags.go
@ -15,7 +15,7 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags has the cli.Flags for the Woodpecker plugin.
|
// Flags has the cli.Flags for the Woodpecker plugin.
|
||||||
@ -25,10 +25,11 @@ func Flags() []cli.Flag {
|
|||||||
// Pipeline flags
|
// Pipeline flags
|
||||||
flags = append(flags, repositoryFlags()...)
|
flags = append(flags, repositoryFlags()...)
|
||||||
flags = append(flags, pipelineFlags()...)
|
flags = append(flags, pipelineFlags()...)
|
||||||
flags = append(flags, currFlags()...)
|
flags = append(flags, commitFlags()...)
|
||||||
flags = append(flags, prevFlags()...)
|
flags = append(flags, previousCommitFlags()...)
|
||||||
flags = append(flags, stepFlags()...)
|
flags = append(flags, stepFlags()...)
|
||||||
flags = append(flags, systemFlags()...)
|
flags = append(flags, systemFlags()...)
|
||||||
|
flags = append(flags, forgeFlags()...)
|
||||||
|
|
||||||
// Plugin flags
|
// Plugin flags
|
||||||
flags = append(flags, loggingFlags()...)
|
flags = append(flags, loggingFlags()...)
|
||||||
|
61
flake.lock
Normal file
61
flake.lock
Normal file
@ -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
|
||||||
|
}
|
24
flake.nix
Normal file
24
flake.nix
Normal file
@ -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
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
65
forge.go
Normal file
65
forge.go
Normal file
@ -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"),
|
||||||
|
}
|
||||||
|
}
|
19
go.mod
19
go.mod
@ -3,21 +3,18 @@ module codeberg.org/woodpecker-plugins/go-plugin
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/joho/godotenv v1.4.0
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/rs/zerolog v1.28.0
|
github.com/rs/zerolog v1.33.0
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/urfave/cli/v2 v2.23.7
|
github.com/urfave/cli/v3 v3.0.0-alpha9.0.20240901123629-31c5c841e98f
|
||||||
golang.org/x/net v0.5.0
|
golang.org/x/net v0.29.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
golang.org/x/sys v0.25.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
|
||||||
golang.org/x/sys v0.4.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
55
go.sum
55
go.sum
@ -1,43 +1,32 @@
|
|||||||
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/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.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
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.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
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.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
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/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rs/xid v1.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.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||||
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/urfave/cli/v3 v3.0.0-alpha9.0.20240901123629-31c5c841e98f h1:NLtJkwEq8wijGw/t5340pm/SRM2loRQ6m+2IRaM+8eM=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/urfave/cli/v3 v3.0.0-alpha9.0.20240901123629-31c5c841e98f/go.mod h1:Z1ItyMma7t6I7zHG9OpbExhHQOSkFf/96n+mAZ9MtVI=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY=
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
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/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.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
|
||||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
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/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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
42
http.go
42
http.go
@ -23,37 +23,43 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func httpClientFlags() []cli.Flag {
|
func httpClientFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "transport.skip-verify",
|
Name: "transport.skip-verify",
|
||||||
Usage: "skip ssl verify",
|
Usage: "skip ssl verify",
|
||||||
EnvVars: []string{"PLUGIN_SKIP_VERIFY"},
|
Sources: cli.EnvVars(
|
||||||
|
"PLUGIN_SKIP_VERIFY",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "transport.socks-proxy",
|
Name: "transport.socks-proxy",
|
||||||
Usage: "socks proxy address",
|
Usage: "socks proxy address",
|
||||||
EnvVars: []string{"SOCKS_PROXY"},
|
Sources: cli.EnvVars(
|
||||||
Hidden: true,
|
"SOCKS_PROXY",
|
||||||
|
),
|
||||||
|
Hidden: true,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "transport.socks-proxy-off",
|
Name: "transport.socks-proxy-off",
|
||||||
Usage: "socks proxy ignored",
|
Usage: "socks proxy ignored",
|
||||||
EnvVars: []string{"SOCKS_PROXY_OFF"},
|
Sources: cli.EnvVars(
|
||||||
Hidden: true,
|
"SOCKS_PROXY_OFF",
|
||||||
|
),
|
||||||
|
Hidden: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
func HTTPClientFromContext(c *cli.Command) *http.Client {
|
||||||
var (
|
var (
|
||||||
skip = ctx.Bool("transport.skip-verify")
|
skip = c.Bool("transport.skip-verify")
|
||||||
socks = ctx.String("transport.socks-proxy")
|
socks = c.String("transport.socks-proxy")
|
||||||
socksoff = ctx.Bool("transport.socks-proxy-off")
|
socksOff = c.Bool("transport.socks-proxy-off")
|
||||||
)
|
)
|
||||||
|
|
||||||
certs, err := x509.SystemCertPool()
|
certs, err := x509.SystemCertPool()
|
||||||
@ -80,7 +86,7 @@ func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
|||||||
DualStack: true,
|
DualStack: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(socks) != 0 && !socksoff {
|
if len(socks) != 0 && !socksOff {
|
||||||
proxyDialer, err := proxy.SOCKS5("tcp", socks, nil, dialer)
|
proxyDialer, err := proxy.SOCKS5("tcp", socks, nil, dialer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to create socks proxy")
|
log.Error().Err(err).Msg("failed to create socks proxy")
|
||||||
@ -88,7 +94,7 @@ func HTTPClientFromContext(ctx *cli.Context) *http.Client {
|
|||||||
if contextDialer, ok := proxyDialer.(proxy.ContextDialer); ok {
|
if contextDialer, ok := proxyDialer.(proxy.ContextDialer); ok {
|
||||||
transport.DialContext = contextDialer.DialContext
|
transport.DialContext = contextDialer.DialContext
|
||||||
} else {
|
} 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)
|
return proxyDialer.Dial(network, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
logger.go
14
logger.go
@ -19,22 +19,24 @@ import (
|
|||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loggingFlags() []cli.Flag {
|
func loggingFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "log-level",
|
Name: "log-level",
|
||||||
Usage: "log level",
|
Usage: "log level",
|
||||||
EnvVars: []string{"PLUGIN_LOG_LEVEL"},
|
Sources: cli.EnvVars(
|
||||||
Value: "info",
|
"PLUGIN_LOG_LEVEL",
|
||||||
|
),
|
||||||
|
Value: "info",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupConsoleLogger sets up the console logger.
|
// SetupConsoleLogger sets up the console logger.
|
||||||
func SetupConsoleLogger(c *cli.Context) error {
|
func SetupConsoleLogger(c *cli.Command) error {
|
||||||
level := c.String("log-level")
|
level := c.String("log-level")
|
||||||
lvl, err := zerolog.ParseLevel(level)
|
lvl, err := zerolog.ParseLevel(level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
42
metadata.go
42
metadata.go
@ -15,27 +15,41 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metadata defines runtime metadata.
|
// Metadata defines runtime metadata.
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
Repository Repository `json:"repo,omitempty"`
|
Repository Repository `json:"repo,omitempty"`
|
||||||
Pipeline Pipeline `json:"curr,omitempty"`
|
Pipeline Pipeline `json:"curr,omitempty"`
|
||||||
Curr Commit `json:"commit,omitempty"`
|
Commit Commit `json:"commit,omitempty"`
|
||||||
Prev Commit `json:"prev,omitempty"`
|
PreviousCommit Commit `json:"previous_commit,omitempty"`
|
||||||
Step Step `json:"step,omitempty"`
|
Step Step `json:"step,omitempty"`
|
||||||
System System `json:"sys,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.
|
// 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{
|
return Metadata{
|
||||||
Repository: repositoryFromContext(ctx),
|
Repository: repositoryFromContext(c),
|
||||||
Pipeline: pipelineFromContext(ctx),
|
Pipeline: pipelineFromContext(c),
|
||||||
Curr: currFromContext(ctx),
|
Commit: commit,
|
||||||
Prev: prevFromContext(ctx),
|
PreviousCommit: previousCommit,
|
||||||
Step: stepFromContext(ctx),
|
Step: stepFromContext(c),
|
||||||
System: systemFromContext(ctx),
|
System: systemFromContext(c),
|
||||||
|
Forge: forgeFromContext(c),
|
||||||
|
|
||||||
|
Curr: commit,
|
||||||
|
Prev: previousCommit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ func testMetadata() map[string]string {
|
|||||||
"CI_REPO_NAME": "woodpecker",
|
"CI_REPO_NAME": "woodpecker",
|
||||||
"CI_REPO_OWNER": "woodpecker-ci",
|
"CI_REPO_OWNER": "woodpecker-ci",
|
||||||
"CI_REPO_SCM": "git",
|
"CI_REPO_SCM": "git",
|
||||||
"CI_REPO_LINK": "https://github.com/woodpecker-ci/woodpecker",
|
"CI_REPO_URL": "https://codeberg.org/woodpecker-plugins/go-plugin",
|
||||||
"CI_REPO_CLONE_URL": "https://github.com/woodpecker-ci/woodpecker.git",
|
"CI_REPO_CLONE_URL": "https://codeberg.org/woodpecker-plugins/go-plugin.git",
|
||||||
"CI_REPO_DEFAULT_BRANCH": "main",
|
"CI_REPO_DEFAULT_BRANCH": "main",
|
||||||
"CI_REPO_PRIVATE": "false",
|
"CI_REPO_PRIVATE": "false",
|
||||||
// Commit
|
// Commit
|
||||||
@ -45,11 +45,11 @@ func testMetadata() map[string]string {
|
|||||||
"CI_COMMIT_AUTHOR": "John Doe",
|
"CI_COMMIT_AUTHOR": "John Doe",
|
||||||
"CI_COMMIT_AUTHOR_EMAIL": "john@example.com",
|
"CI_COMMIT_AUTHOR_EMAIL": "john@example.com",
|
||||||
"CI_COMMIT_AUTHOR_AVATAR": "https://avatars.githubusercontent.com/u/1234567?v=4",
|
"CI_COMMIT_AUTHOR_AVATAR": "https://avatars.githubusercontent.com/u/1234567?v=4",
|
||||||
"CI_COMMIT_LINK": "https://github.com/woodpecker-ci/woodpecker/commit/a1b2c3d4",
|
"CI_COMMIT_URL": "https://codeberg.org/woodpecker-plugins/go-plugin/commit/a1b2c3d4",
|
||||||
// Build
|
// Build
|
||||||
"CI_PIPELINE_NUMBER": "1",
|
"CI_PIPELINE_NUMBER": "1",
|
||||||
"CI_PIPELINE_EVENT": "push",
|
"CI_PIPELINE_EVENT": EventTypePush,
|
||||||
"CI_PIPELINE_LINK": "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1",
|
"CI_PIPELINE_URL": "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1",
|
||||||
"CI_PIPELINE_STATUS": "running",
|
"CI_PIPELINE_STATUS": "running",
|
||||||
"CI_PIPELINE_CREATED": "1611234567",
|
"CI_PIPELINE_CREATED": "1611234567",
|
||||||
"CI_PIPELINE_STARTED": "1611234567",
|
"CI_PIPELINE_STARTED": "1611234567",
|
||||||
@ -60,9 +60,12 @@ func testMetadata() map[string]string {
|
|||||||
"CI_STEP_STARTED": "1611234567",
|
"CI_STEP_STARTED": "1611234567",
|
||||||
// System
|
// System
|
||||||
"CI_SYSTEM_NAME": "woodpecker",
|
"CI_SYSTEM_NAME": "woodpecker",
|
||||||
"CI_SYSTEM_LINK": "https://ci.woodpecker-ci.org",
|
"CI_SYSTEM_URL": "https://ci.woodpecker-ci.org",
|
||||||
"CI_SYSTEM_VERSION": "1.0.0",
|
"CI_SYSTEM_VERSION": "1.0.0",
|
||||||
"CI_SYSTEM_HOST": "woodpecker-ci.org",
|
"CI_SYSTEM_HOST": "woodpecker-ci.org",
|
||||||
|
// Forge
|
||||||
|
"CI_FORGE_TYPE": ForgeTypeGitea,
|
||||||
|
"CI_FORGE_URL": "https://codeberg.org",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,14 +79,14 @@ func TestMetadata(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
err := plugin.app.Run([]string{"test"})
|
err := plugin.app.Run(plugin.ctx, []string{"test"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
assert.Equal(t, "woodpecker", plugin.Metadata.Repository.Name)
|
assert.Equal(t, "woodpecker", plugin.Metadata.Repository.Name)
|
||||||
assert.Equal(t, "woodpecker-ci", plugin.Metadata.Repository.Owner)
|
assert.Equal(t, "woodpecker-ci", plugin.Metadata.Repository.Owner)
|
||||||
assert.Equal(t, "https://github.com/woodpecker-ci/woodpecker", plugin.Metadata.Repository.Link)
|
assert.Equal(t, "https://codeberg.org/woodpecker-plugins/go-plugin", plugin.Metadata.Repository.URL)
|
||||||
assert.Equal(t, "https://github.com/woodpecker-ci/woodpecker.git", plugin.Metadata.Repository.CloneURL)
|
assert.Equal(t, "https://codeberg.org/woodpecker-plugins/go-plugin.git", plugin.Metadata.Repository.CloneURL)
|
||||||
assert.Equal(t, "main", plugin.Metadata.Repository.Branch)
|
assert.Equal(t, "main", plugin.Metadata.Repository.Branch)
|
||||||
assert.False(t, plugin.Metadata.Repository.Private)
|
assert.False(t, plugin.Metadata.Repository.Private)
|
||||||
|
|
||||||
@ -99,8 +102,8 @@ func TestMetadata(t *testing.T) {
|
|||||||
|
|
||||||
// Pipeline
|
// Pipeline
|
||||||
assert.Equal(t, int64(1), plugin.Metadata.Pipeline.Number)
|
assert.Equal(t, int64(1), plugin.Metadata.Pipeline.Number)
|
||||||
assert.Equal(t, "push", plugin.Metadata.Pipeline.Event)
|
assert.Equal(t, EventTypePush, plugin.Metadata.Pipeline.Event)
|
||||||
assert.Equal(t, "https://ci.woodpecker-ci.org/woodpecker-ci/woodpecker/1", plugin.Metadata.Pipeline.Link)
|
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, "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.Created)
|
||||||
assert.Equal(t, time.Unix(1611234567, 0), plugin.Metadata.Pipeline.Started)
|
assert.Equal(t, time.Unix(1611234567, 0), plugin.Metadata.Pipeline.Started)
|
||||||
@ -111,7 +114,11 @@ func TestMetadata(t *testing.T) {
|
|||||||
|
|
||||||
// System
|
// System
|
||||||
assert.Equal(t, "woodpecker", plugin.Metadata.System.Name)
|
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, "1.0.0", plugin.Metadata.System.Version)
|
||||||
assert.Equal(t, "woodpecker-ci.org", plugin.Metadata.System.Host)
|
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)
|
||||||
}
|
}
|
||||||
|
83
pipeline.go
83
pipeline.go
@ -17,7 +17,16 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"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.
|
// Pipeline defines runtime metadata for a pipeline.
|
||||||
@ -25,101 +34,107 @@ type Pipeline struct {
|
|||||||
Number int64 `json:"number,omitempty"`
|
Number int64 `json:"number,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
DeployTarget string `json:"target,omitempty"`
|
DeployTarget string `json:"target,omitempty"`
|
||||||
Created time.Time `json:"created,omitempty"`
|
Created time.Time `json:"created,omitempty"`
|
||||||
Started time.Time `json:"started,omitempty"`
|
Started time.Time `json:"started,omitempty"`
|
||||||
Finished time.Time `json:"finished,omitempty"`
|
Finished time.Time `json:"finished,omitempty"`
|
||||||
Parent int64 `json:"parent,omitempty"`
|
Parent int64 `json:"parent,omitempty"`
|
||||||
|
|
||||||
|
// Deprecated: Please use URL instead.
|
||||||
|
Link string `json:"link,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func pipelineFlags() []cli.Flag {
|
func pipelineFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "pipeline.number",
|
Name: "pipeline.number",
|
||||||
Usage: "pipeline number",
|
Usage: "pipeline number",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_NUMBER",
|
"CI_PIPELINE_NUMBER",
|
||||||
"DRONE_BUILD_NUMBER",
|
"DRONE_BUILD_NUMBER",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "pipeline.status",
|
Name: "pipeline.status",
|
||||||
Usage: "pipeline status",
|
Usage: "pipeline status",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_STATUS",
|
"CI_PIPELINE_STATUS",
|
||||||
"DRONE_BUILD_STATUS",
|
"DRONE_BUILD_STATUS",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "pipeline.event",
|
Name: "pipeline.event",
|
||||||
Usage: "pipeline event",
|
Usage: "pipeline event",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_EVENT",
|
"CI_PIPELINE_EVENT",
|
||||||
"DRONE_BUILD_EVENT",
|
"DRONE_BUILD_EVENT",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "pipeline.link",
|
Name: "pipeline.url",
|
||||||
Usage: "pipeline link",
|
Aliases: []string{"pipeline.link"},
|
||||||
EnvVars: []string{
|
Usage: "pipeline url",
|
||||||
|
Sources: cli.EnvVars(
|
||||||
|
"CI_PIPELINE_URL",
|
||||||
"CI_PIPELINE_LINK",
|
"CI_PIPELINE_LINK",
|
||||||
"DRONE_BUILD_LINK",
|
"DRONE_BUILD_LINK",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "pipeline.deploy-target",
|
Name: "pipeline.deploy-target",
|
||||||
Usage: "pipeline deployment target",
|
Usage: "pipeline deployment target",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_DEPLOY_TARGET",
|
"CI_PIPELINE_DEPLOY_TARGET",
|
||||||
"DRONE_DEPLOY_TO",
|
"DRONE_DEPLOY_TO",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "pipeline.created",
|
Name: "pipeline.created",
|
||||||
Usage: "pipeline creation time",
|
Usage: "pipeline creation time",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_CREATED",
|
"CI_PIPELINE_CREATED",
|
||||||
"DRONE_BUILD_CREATED",
|
"DRONE_BUILD_CREATED",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "pipeline.started",
|
Name: "pipeline.started",
|
||||||
Usage: "pipeline start time",
|
Usage: "pipeline start time",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_STARTED",
|
"CI_PIPELINE_STARTED",
|
||||||
"DRONE_BUILD_STARTED",
|
"DRONE_BUILD_STARTED",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "pipeline.finished",
|
Name: "pipeline.finished",
|
||||||
Usage: "pipeline finish time",
|
Usage: "pipeline finish time",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_FINISHED",
|
"CI_PIPELINE_FINISHED",
|
||||||
"DRONE_BUILD_FINISHED",
|
"DRONE_BUILD_FINISHED",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "pipeline.parent",
|
Name: "pipeline.parent",
|
||||||
Usage: "pipeline parent",
|
Usage: "pipeline parent",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_PIPELINE_PARENT",
|
"CI_PIPELINE_PARENT",
|
||||||
"DRONE_BUILD_PARENT",
|
"DRONE_BUILD_PARENT",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pipelineFromContext(c *cli.Context) Pipeline {
|
func pipelineFromContext(c *cli.Command) Pipeline {
|
||||||
return Pipeline{
|
return Pipeline{
|
||||||
Number: c.Int64("pipeline.number"),
|
Number: c.Int("pipeline.number"),
|
||||||
Status: c.String("pipeline.status"),
|
Status: c.String("pipeline.status"),
|
||||||
Event: c.String("pipeline.event"),
|
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"),
|
DeployTarget: c.String("pipeline.deploy-target"),
|
||||||
Created: time.Unix(c.Int64("pipeline.created"), 0),
|
Created: time.Unix(c.Int("pipeline.created"), 0),
|
||||||
Started: time.Unix(c.Int64("pipeline.started"), 0),
|
Started: time.Unix(c.Int("pipeline.started"), 0),
|
||||||
Finished: time.Unix(c.Int64("pipeline.finished"), 0),
|
Finished: time.Unix(c.Int("pipeline.finished"), 0),
|
||||||
Parent: c.Int64("pipeline.parent"),
|
Parent: c.Int("pipeline.parent"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
plugin.go
27
plugin.go
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options defines the options for the plugin.
|
// Options defines the options for the plugin.
|
||||||
@ -36,13 +36,16 @@ type Options struct {
|
|||||||
Flags []cli.Flag
|
Flags []cli.Flag
|
||||||
// Execute function of the plugin.
|
// Execute function of the plugin.
|
||||||
Execute ExecuteFunc
|
Execute ExecuteFunc
|
||||||
|
// Context the plugin will use while executing.
|
||||||
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin defines the plugin instance.
|
// Plugin defines the plugin instance.
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
app *cli.App
|
app *cli.Command
|
||||||
execute ExecuteFunc
|
execute ExecuteFunc
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
ctx context.Context
|
||||||
// Metadata of the current pipeline.
|
// Metadata of the current pipeline.
|
||||||
Metadata Metadata
|
Metadata Metadata
|
||||||
}
|
}
|
||||||
@ -56,8 +59,9 @@ func New(opt Options) *Plugin {
|
|||||||
_ = godotenv.Overload("/run/woodpecker/env")
|
_ = godotenv.Overload("/run/woodpecker/env")
|
||||||
}
|
}
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.Command{
|
||||||
Name: opt.Name,
|
Name: opt.Name,
|
||||||
|
Usage: "Run the Woodpecker CI plugin",
|
||||||
Description: opt.Description,
|
Description: opt.Description,
|
||||||
Version: opt.Version,
|
Version: opt.Version,
|
||||||
Flags: append(opt.Flags, Flags()...),
|
Flags: append(opt.Flags, Flags()...),
|
||||||
@ -66,25 +70,30 @@ func New(opt Options) *Plugin {
|
|||||||
plugin := &Plugin{
|
plugin := &Plugin{
|
||||||
app: app,
|
app: app,
|
||||||
execute: opt.Execute,
|
execute: opt.Execute,
|
||||||
|
ctx: opt.Context,
|
||||||
}
|
}
|
||||||
plugin.app.Action = plugin.action
|
plugin.app.Action = plugin.action
|
||||||
|
|
||||||
|
if plugin.ctx == nil {
|
||||||
|
plugin.ctx = context.Background()
|
||||||
|
}
|
||||||
|
|
||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) action(ctx *cli.Context) error {
|
func (p *Plugin) action(ctx context.Context, c *cli.Command) error {
|
||||||
if err := SetupConsoleLogger(ctx); err != nil {
|
if err := SetupConsoleLogger(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Metadata = MetadataFromContext(ctx)
|
p.Metadata = MetadataFromContext(c)
|
||||||
p.client = HTTPClientFromContext(ctx)
|
p.client = HTTPClientFromContext(c)
|
||||||
|
|
||||||
if p.execute == nil {
|
if p.execute == nil {
|
||||||
panic("plugin execute function is not set")
|
panic("plugin execute function is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.execute(ctx.Context)
|
return p.execute(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPClient returns the http.Client instance.
|
// HTTPClient returns the http.Client instance.
|
||||||
@ -94,7 +103,7 @@ func (p *Plugin) HTTPClient() *http.Client {
|
|||||||
|
|
||||||
// Run the plugin.
|
// Run the plugin.
|
||||||
func (p *Plugin) Run() {
|
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")
|
log.Error().Err(err).Msg("execution failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func TestPlugin(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
err := p.app.Run([]string{"test"})
|
err := p.app.Run(p.ctx, []string{"test"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, executed)
|
assert.True(t, executed)
|
||||||
}
|
}
|
||||||
|
6
renovate.json
Normal file
6
renovate.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"local>woodpecker-plugins/renovate-config"
|
||||||
|
]
|
||||||
|
}
|
73
repo.go
73
repo.go
@ -15,79 +15,96 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Repository defines runtime metadata for a repository.
|
// Repository defines runtime metadata for a repository.
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
Name string `json:"name,omitempty"`
|
RemoteID string `json:"remote_id,omitempty"`
|
||||||
Owner string `json:"owner,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
Owner string `json:"owner,omitempty"`
|
||||||
CloneURL string `json:"clone_url,omitempty"`
|
Link string `json:"link,omitempty"`
|
||||||
Private bool `json:"private,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Branch string `json:"default_branch,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 {
|
func repositoryFlags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "repo.remote-id",
|
||||||
|
Usage: "repo remote id",
|
||||||
|
Sources: cli.EnvVars(
|
||||||
|
"CI_REPO_REMOTE_ID",
|
||||||
|
),
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo.name",
|
Name: "repo.name",
|
||||||
Usage: "repo name",
|
Usage: "repo name",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_REPO_NAME",
|
"CI_REPO_NAME",
|
||||||
"DRONE_REPO_NAME",
|
"DRONE_REPO_NAME",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo.owner",
|
Name: "repo.owner",
|
||||||
Usage: "repo owner",
|
Usage: "repo owner",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_REPO_OWNER",
|
"CI_REPO_OWNER",
|
||||||
"DRONE_REPO_OWNER",
|
"DRONE_REPO_OWNER",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo.link",
|
Name: "repo.url",
|
||||||
Usage: "repo link",
|
Aliases: []string{"repo.link"},
|
||||||
EnvVars: []string{
|
Usage: "repo url",
|
||||||
|
Sources: cli.EnvVars(
|
||||||
|
"CI_REPO_URL",
|
||||||
"CI_REPO_LINK",
|
"CI_REPO_LINK",
|
||||||
"DRONE_REPO_LINK",
|
"DRONE_REPO_LINK",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo.clone-url",
|
Name: "repo.clone-url",
|
||||||
Usage: "repo clone url",
|
Usage: "repo clone url",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_REPO_CLONE_URL",
|
"CI_REPO_CLONE_URL",
|
||||||
"DRONE_GIT_HTTP_URL",
|
"DRONE_GIT_HTTP_URL",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "repo.private",
|
Name: "repo.private",
|
||||||
Usage: "repo private",
|
Usage: "repo private",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_REPO_PRIVATE",
|
"CI_REPO_PRIVATE",
|
||||||
"DRONE_REPO_PRIVATE",
|
"DRONE_REPO_PRIVATE",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo.default-branch",
|
Name: "repo.default-branch",
|
||||||
Usage: "repo default branch",
|
Usage: "repo default branch",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_REPO_DEFAULT_BRANCH",
|
"CI_REPO_DEFAULT_BRANCH",
|
||||||
"DRONE_REPO_BRANCH",
|
"DRONE_REPO_BRANCH",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func repositoryFromContext(c *cli.Context) Repository {
|
func repositoryFromContext(c *cli.Command) Repository {
|
||||||
return Repository{
|
return Repository{
|
||||||
Name: c.String("repo.name"),
|
RemoteID: c.String("repo.remote-id"),
|
||||||
Owner: c.String("repo.owner"),
|
Name: c.String("repo.name"),
|
||||||
Link: c.String("repo.link"),
|
Owner: c.String("repo.owner"),
|
||||||
CloneURL: c.String("repo.clone-url"),
|
URL: c.String("repo.url"),
|
||||||
Private: c.Bool("repo.private"),
|
Link: c.String("repo.url"),
|
||||||
Branch: c.String("repo.default-branch"),
|
CloneURL: c.String("repo.clone-url"),
|
||||||
|
Private: c.Bool("repo.private"),
|
||||||
|
Branch: c.String("repo.default-branch"),
|
||||||
|
DefaultBranch: c.String("repo.default-branch"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
step.go
26
step.go
@ -17,7 +17,7 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Step defines runtime metadata for a step.
|
// Step defines runtime metadata for a step.
|
||||||
@ -32,32 +32,32 @@ func stepFlags() []cli.Flag {
|
|||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "step.number",
|
Name: "step.number",
|
||||||
Usage: "step number",
|
Usage: "step number",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_STEP_NUMBER",
|
"CI_STEP_NUMBER",
|
||||||
"DRONE_STEP_NUMBER",
|
"DRONE_STEP_NUMBER",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "step.started",
|
Name: "step.started",
|
||||||
Usage: "step start time",
|
Usage: "step start time",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_STEP_STARTED",
|
"CI_STEP_STARTED",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.Int64Flag{
|
&cli.IntFlag{
|
||||||
Name: "step.finished",
|
Name: "step.finished",
|
||||||
Usage: "step finish time",
|
Usage: "step finish time",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_STEP_FINISHED",
|
"CI_STEP_FINISHED",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stepFromContext(c *cli.Context) Step {
|
func stepFromContext(c *cli.Command) Step {
|
||||||
return Step{
|
return Step{
|
||||||
Number: c.Int("step.number"),
|
Number: int(c.Int("step.number")),
|
||||||
Started: time.Unix(c.Int64("step.started"), 0),
|
Started: time.Unix(c.Int("step.started"), 0),
|
||||||
Finished: time.Unix(c.Int64("step.finished"), 0),
|
Finished: time.Unix(c.Int("step.finished"), 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
system.go
54
system.go
@ -17,16 +17,19 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// System defines runtime metadata for a ci/cd system.
|
// System defines runtime metadata for a ci/cd system.
|
||||||
type System struct {
|
type System struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Link string `json:"link,omitempty"`
|
|
||||||
Platform string `json:"arch,omitempty"`
|
Platform string `json:"arch,omitempty"`
|
||||||
Version string `json:"version,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 {
|
func systemFlags() []cli.Flag {
|
||||||
@ -34,60 +37,63 @@ func systemFlags() []cli.Flag {
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "system.name",
|
Name: "system.name",
|
||||||
Usage: "system name",
|
Usage: "system name",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_SYSTEM_NAME",
|
"CI_SYSTEM_NAME",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "system.host",
|
Name: "system.host",
|
||||||
Usage: "system host",
|
Usage: "system host",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_SYSTEM_HOST",
|
"CI_SYSTEM_HOST",
|
||||||
"DRONE_SYSTEM_HOST",
|
"DRONE_SYSTEM_HOST",
|
||||||
"DRONE_SYSTEM_HOSTNAME",
|
"DRONE_SYSTEM_HOSTNAME",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "system.link",
|
Name: "system.url",
|
||||||
Usage: "system link",
|
Aliases: []string{"system.link"},
|
||||||
EnvVars: []string{
|
Usage: "system url",
|
||||||
|
Sources: cli.EnvVars(
|
||||||
|
"CI_SYSTEM_URL",
|
||||||
"CI_SYSTEM_LINK",
|
"CI_SYSTEM_LINK",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "system.arch",
|
Name: "system.arch",
|
||||||
Usage: "system arch",
|
Usage: "system arch",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_SYSTEM_PLATFORM",
|
"CI_SYSTEM_PLATFORM",
|
||||||
"DRONE_STAGE_ARCH",
|
"DRONE_STAGE_ARCH",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "system.version",
|
Name: "system.version",
|
||||||
Usage: "system version",
|
Usage: "system version",
|
||||||
EnvVars: []string{
|
Sources: cli.EnvVars(
|
||||||
"CI_SYSTEM_VERSION",
|
"CI_SYSTEM_VERSION",
|
||||||
"DRONE_SYSTEM_VERSION",
|
"DRONE_SYSTEM_VERSION",
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func systemFromContext(ctx *cli.Context) System {
|
func systemFromContext(c *cli.Command) System {
|
||||||
link := ctx.String("system.link")
|
url := c.String("system.url")
|
||||||
host := ctx.String("system.host")
|
host := c.String("system.host")
|
||||||
if link == "" && host != "" {
|
if url == "" && host != "" {
|
||||||
// Alternative link format used by Drone.
|
// Alternative url format used by Drone.
|
||||||
proto := os.Getenv("DRONE_SYSTEM_PROTO")
|
proto := os.Getenv("DRONE_SYSTEM_PROTO")
|
||||||
if proto != "" {
|
if proto != "" {
|
||||||
link = proto + "://" + host
|
url = proto + "://" + host
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return System{
|
return System{
|
||||||
Name: ctx.String("system.name"),
|
Name: c.String("system.name"),
|
||||||
Host: host,
|
Host: host,
|
||||||
Link: link,
|
URL: url,
|
||||||
Platform: ctx.String("system.arch"),
|
Link: url,
|
||||||
Version: ctx.String("system.version"),
|
Platform: c.String("system.arch"),
|
||||||
|
Version: c.String("system.version"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user