chore: cleanup docs and use cmd trace from plugin lib (#3)

This commit is contained in:
Robert Kaussow 2024-01-02 22:58:05 +01:00 committed by GitHub
parent 40636a12c5
commit 6b506e6a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 48 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/thegeeklab/wp-git-clone/plugin"
"github.com/thegeeklab/wp-plugin-go/docs"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
wp_template "github.com/thegeeklab/wp-plugin-go/template"
"github.com/urfave/cli/v2"
)
@ -43,7 +44,7 @@ func main() {
func toYAML(app *cli.App) (string, error) {
var w bytes.Buffer
yamlTmpl, err := template.New("docs").ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
yamlTmpl, err := template.New("docs").Funcs(wp_template.LoadFuncMap()).ParseFS(yamlTemplate, "templates/docs-data.yaml.tmpl")
if err != nil {
fmt.Println(yamlTmpl)
return "", err

View File

@ -1,9 +1,3 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package main
import (
@ -19,16 +13,18 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "remote",
Usage: "git remote url",
Usage: "git remote HTTP clone url",
EnvVars: []string{"PLUGIN_REMOTE", "CI_REPO_CLONE_URL"},
Destination: &settings.Repo.RemoteURL,
DefaultText: "$CI_REPO_CLONE_URL",
Category: category,
},
&cli.StringFlag{
Name: "remote-ssh",
Usage: "git clone ssh url",
Usage: "git remote SSH clone url",
EnvVars: []string{"PLUGIN_REMOTE_SSH", "CI_REPO_CLONE_SSH_URL"},
Destination: &settings.Repo.RemoteSSH,
DefaultText: "$CI_REPO_CLONE_SSH_URL",
Category: category,
},
&cli.StringFlag{
@ -36,6 +32,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Usage: "path to clone git repository",
EnvVars: []string{"PLUGIN_WORKDIR", "CI_WORKSPACE"},
Destination: &settings.WorkDir,
DefaultText: "$CI_WORKSPACE",
Category: category,
},
&cli.StringFlag{
@ -43,13 +40,14 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Usage: "git commit sha",
EnvVars: []string{"PLUGIN_COMMIT_SHA", "CI_COMMIT_SHA"},
Destination: &settings.Repo.CommitSha,
DefaultText: "$CI_COMMIT_SHA",
Category: category,
},
&cli.StringFlag{
Name: "ref",
Value: "refs/heads/main",
Usage: "git commit ref",
EnvVars: []string{"PLUGIN_COMMIT_REF", "CI_COMMIT_REF"},
Value: "refs/heads/main",
Destination: &settings.Repo.CommitRef,
Category: category,
},
@ -99,7 +97,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
},
&cli.BoolFlag{
Name: "insecure-skip-ssl-verify",
Usage: "skip ssl verification of the remote machine",
Usage: "skip SSL verification of the remote machine",
EnvVars: []string{"PLUGIN_INSECURE_SKIP_SSL_VERIFY"},
Destination: &settings.Repo.InsecureSkipSSLVerify,
Category: category,
@ -113,14 +111,14 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
},
&cli.GenericFlag{
Name: "submodule-override",
Usage: "json map of submodule overrides",
Usage: "JSON map of submodule overrides",
EnvVars: []string{"PLUGIN_SUBMODULE_OVERRIDE"},
Value: &types.MapFlag{},
Category: category,
},
&cli.BoolFlag{
Name: "submodule-partial",
Usage: "update submodules via partial clone",
Usage: "update submodules via partial clone (`depth=1`)",
EnvVars: []string{"PLUGIN_SUBMODULES_PARTIAL", "PLUGIN_SUBMODULE_PARTIAL"},
Value: true,
Destination: &settings.Repo.SubmodulePartial,
@ -138,8 +136,8 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Name: "branch",
Usage: "change branch name",
EnvVars: []string{"PLUGIN_BRANCH", "CI_COMMIT_BRANCH", "CI_REPO_DEFAULT_BRANCH"},
Destination: &settings.Repo.Branch,
Value: "main",
Destination: &settings.Repo.Branch,
Category: category,
},
&cli.BoolFlag{
@ -154,18 +152,19 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Usage: "define/replace safe directories",
EnvVars: []string{"PLUGIN_SAFE_DIRECTORY", "CI_WORKSPACE"},
Destination: &settings.Repo.SafeDirectory,
DefaultText: "$CI_WORKSPACE",
Category: category,
},
&cli.BoolFlag{
Name: "use-ssh",
Usage: "using ssh for git clone",
Usage: "using SSH for git clone",
EnvVars: []string{"PLUGIN_USE_SSH"},
Destination: &settings.UseSSH,
Category: category,
},
&cli.StringFlag{
Name: "ssh-key",
Usage: "ssh key for ssh clone",
Usage: "private key for SSH clone",
EnvVars: []string{"PLUGIN_SSH_KEY"},
Destination: &settings.SSHKey,
Category: category,

View File

@ -1,9 +1,3 @@
// Copyright (c) 2020, the Drone Plugins project authors.
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package main
import (

View File

@ -5,10 +5,16 @@ properties:
- name: {{ $v.Name }}
{{- with $v.Description }}
description: |
{{ . }}
{{ . | ToSentence }}
{{- end }}
{{- with $v.Type }}
type: {{ . }}
{{- end }}
{{- with $v.Default }}
defaultvalue: {{ . }}
{{- end }}
{{- with $v.Required }}
required: {{ . }}
{{- end }}
{{ end -}}
{{ end -}}

View File

@ -3,84 +3,107 @@ properties:
- name: branch
description: |
Change branch name.
type: string
defaultvalue: "main"
- name: commit_ref
description: |
Git commit ref.
type: string
defaultvalue: "refs/heads/main"
- name: commit_sha
description: |
Git commit sha.
type: string
defaultvalue: $CI_COMMIT_SHA
- name: depth
description: |
Clone depth.
type: integer
defaultvalue: 0
- name: insecure_skip_ssl_verify
description: |
Skip SSL verification of the remote machine. Activating this option is insecure
and should be avoided in most cases.
defaultvalue: true
Skip SSL verification of the remote machine.
Activating this option is insecure and should be avoided in most cases.
type: bool
defaultvalue: false
- name: lfs
description: |
Whether to retrieve LFS content if available.
type: bool
defaultvalue: true
- name: partial
description: |
Enable/disable partial clone.
type: bool
defaultvalue: false
- name: recursive
description: |
Clone submodules.
type: bool
defaultvalue: true
- name: remote
description: |
Git remote HTTP clone url.
type: string
defaultvalue: $CI_REPO_CLONE_URL
- name: remote_ssh
description: |
Git remote SSH clone url.
type: string
defaultvalue: $CI_REPO_CLONE_SSH_URL
- name: safe_directory
description: |
Define/replace safe directories.
type: string
defaultvalue: $CI_WORKSPACE
- name: ssh_key
description: |
SSH key for ssh clone.
Private key for SSH clone.
type: string
- name: submodule_override
description: |
JSON map of submodule overrides.
type: generic
- name: submodules_partial
description: |
Update submodules via partial clone (`depth=1`).
type: bool
defaultvalue: true
- name: submodules_update_remote
description: |
Update remote submodules.
type: bool
defaultvalue: false
- name: tags
description: |
Fetch git tags during clone.
type: bool
defaultvalue: true
- name: use_ssh
description: |
Using ssh for git clone.
Using SSH for git clone.
type: bool
defaultvalue: false
- name: workdir
description: |
Path to clone git repository.
type: string
defaultvalue: $CI_WORKSPACE

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.21
require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/rs/zerolog v1.31.0
github.com/thegeeklab/wp-plugin-go v1.4.0
github.com/thegeeklab/wp-plugin-go v1.5.0
github.com/urfave/cli/v2 v2.27.1
golang.org/x/sys v0.15.0
)

4
go.sum
View File

@ -50,8 +50,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thegeeklab/wp-plugin-go v1.4.0 h1:gYctYST3wfNrx/G+JgevWqhCdSPDukL63e49+ZMVBzI=
github.com/thegeeklab/wp-plugin-go v1.4.0/go.mod h1:ULBD5SNC7bkIB/UbLMQpcPWj7iZObCTWg8bqXf1zqsA=
github.com/thegeeklab/wp-plugin-go v1.5.0 h1:fA/kQwQrntjxdxePKKGecMRnPbj1xwpy6D2JrrPD2qA=
github.com/thegeeklab/wp-plugin-go v1.5.0/go.mod h1:ULBD5SNC7bkIB/UbLMQpcPWj7iZObCTWg8bqXf1zqsA=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=

View File

@ -1,8 +1,3 @@
// Copyright (c) 2023, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
@ -18,6 +13,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/thegeeklab/wp-git-clone/git"
"github.com/thegeeklab/wp-plugin-go/trace"
"github.com/thegeeklab/wp-plugin-go/types"
"golang.org/x/sys/execabs"
)
@ -179,7 +175,7 @@ func (p *Plugin) execCmd(cmd *execabs.Cmd, buf *bytes.Buffer) error {
cmd.Stderr = io.MultiWriter(os.Stderr, buf)
cmd.Dir = p.Settings.WorkDir
trace(cmd)
trace.Cmd(cmd)
return cmd.Run()
}

View File

@ -1,8 +1,3 @@
// Copyright (c) 2023, Robert Kaussow <mail@thegeeklab.de>
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (

View File

@ -1,13 +1,13 @@
package plugin
import (
"fmt"
"os"
"strings"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/rs/zerolog/log"
"github.com/thegeeklab/wp-plugin-go/trace"
"golang.org/x/sys/execabs"
)
@ -25,10 +25,6 @@ func newBackoff(maxRetries uint64) backoff.BackOff {
return backoff.WithMaxRetries(b, maxRetries)
}
func trace(cmd *execabs.Cmd) {
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
}
func retryCmd(cmd *execabs.Cmd) error {
backoffOps := func() error {
// copy the original command
@ -39,7 +35,7 @@ func retryCmd(cmd *execabs.Cmd) error {
retry.Stdout = os.Stdout
retry.Stderr = os.Stderr
trace(cmd)
trace.Cmd(cmd)
return cmd.Run()
}