mirror of
https://github.com/thegeeklab/wp-git-clone.git
synced 2024-11-22 00:10:39 +00:00
fix: enable tags fetching by default and remove event condition
This commit is contained in:
parent
019f983e8f
commit
802772766b
@ -53,14 +53,6 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|||||||
Destination: &settings.Repo.CommitRef,
|
Destination: &settings.Repo.CommitRef,
|
||||||
Category: category,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "event",
|
|
||||||
Value: "push",
|
|
||||||
Usage: "pipeline event",
|
|
||||||
EnvVars: []string{"CI_PIPELINE_EVENT"},
|
|
||||||
Destination: &settings.Pipeline.Event,
|
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "netrc.machine",
|
Name: "netrc.machine",
|
||||||
Usage: "netrc machine",
|
Usage: "netrc machine",
|
||||||
@ -99,7 +91,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "tags",
|
Name: "tags",
|
||||||
Usage: "clone tags, if not explicitly set and event is tag its default is true else false",
|
Usage: "fetch git tags during clone",
|
||||||
EnvVars: []string{"PLUGIN_TAGS"},
|
EnvVars: []string{"PLUGIN_TAGS"},
|
||||||
Destination: &settings.Tags,
|
Destination: &settings.Tags,
|
||||||
Category: category,
|
Category: category,
|
||||||
|
@ -56,7 +56,6 @@ docker build --file Containerfile.multiarch --tag thegeeklab/wp-git-clone .
|
|||||||
```Shell
|
```Shell
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-e CI_REPO_CLONE_URL=https://github.com/octocat/Hello-World.git \
|
-e CI_REPO_CLONE_URL=https://github.com/octocat/Hello-World.git \
|
||||||
-e CI_PIPELINE_EVENT=push \
|
|
||||||
-e CI_COMMIT_SHA=b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf \
|
-e CI_COMMIT_SHA=b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf \
|
||||||
-e CI_COMMIT_REF=refs/heads/test \
|
-e CI_COMMIT_REF=refs/heads/test \
|
||||||
-e CI_WORKSPACE=/tmp/wp_git_testrepo \
|
-e CI_WORKSPACE=/tmp/wp_git_testrepo \
|
||||||
|
@ -5,23 +5,6 @@ properties:
|
|||||||
Change branch name.
|
Change branch name.
|
||||||
defaultvalue: "main"
|
defaultvalue: "main"
|
||||||
|
|
||||||
- name: ci_netrc_machine
|
|
||||||
description: |
|
|
||||||
Netrc machine.
|
|
||||||
|
|
||||||
- name: ci_netrc_password
|
|
||||||
description: |
|
|
||||||
Netrc password.
|
|
||||||
|
|
||||||
- name: ci_netrc_username
|
|
||||||
description: |
|
|
||||||
Metrc username.
|
|
||||||
|
|
||||||
- name: ci_pipeline_event
|
|
||||||
description: |
|
|
||||||
Pipeline event.
|
|
||||||
defaultvalue: "push"
|
|
||||||
|
|
||||||
- name: commit_ref
|
- name: commit_ref
|
||||||
description: |
|
description: |
|
||||||
Git commit ref.
|
Git commit ref.
|
||||||
@ -90,8 +73,8 @@ properties:
|
|||||||
|
|
||||||
- name: tags
|
- name: tags
|
||||||
description: |
|
description: |
|
||||||
Clone tags, if not explicitly set and event is tag its default is `true` else `false`.
|
Fetch git tags during clone.
|
||||||
defaultvalue: false
|
defaultvalue: true
|
||||||
|
|
||||||
- name: use_ssh
|
- name: use_ssh
|
||||||
description: |
|
description: |
|
||||||
|
@ -8,10 +8,10 @@ import (
|
|||||||
|
|
||||||
// FetchSource fetches the source from remote.
|
// FetchSource fetches the source from remote.
|
||||||
func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd {
|
func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd {
|
||||||
tagsOption := "--no-tags"
|
tagsOption := "--tags"
|
||||||
|
|
||||||
if tags {
|
if !tags {
|
||||||
tagsOption = "--tags"
|
tagsOption = "--no-tags"
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
|
@ -59,19 +59,6 @@ func (p *Plugin) Validate() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Settings.Pipeline.Event == "tag" && !p.Settings.Tags {
|
|
||||||
// tags clone not explicit set but pipeline is triggered by a tag
|
|
||||||
// auto set tags cloning to true
|
|
||||||
p.Settings.Tags = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Settings.Tags && p.Settings.Partial {
|
|
||||||
log.Warn().Msg("ignore partial clone as tags are fetched")
|
|
||||||
|
|
||||||
// if tag fetching is enabled per event or setting, disable partial clone
|
|
||||||
p.Settings.Partial = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.Settings.Partial {
|
if p.Settings.Partial {
|
||||||
p.Settings.Depth = 1
|
p.Settings.Depth = 1
|
||||||
p.Settings.Filter = "tree:0"
|
p.Settings.Filter = "tree:0"
|
||||||
|
@ -12,7 +12,6 @@ type testCommit struct {
|
|||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
clone string
|
clone string
|
||||||
event string
|
|
||||||
commit string
|
commit string
|
||||||
ref string
|
ref string
|
||||||
file string
|
file string
|
||||||
@ -37,9 +36,6 @@ func TestClone(t *testing.T) {
|
|||||||
CommitSha: tt.commit,
|
CommitSha: tt.commit,
|
||||||
Branch: "main",
|
Branch: "main",
|
||||||
},
|
},
|
||||||
Pipeline: Pipeline{
|
|
||||||
Event: tt.event,
|
|
||||||
},
|
|
||||||
Home: "/tmp",
|
Home: "/tmp",
|
||||||
WorkDir: filepath.Join(dir, tt.path),
|
WorkDir: filepath.Join(dir, tt.path),
|
||||||
Recursive: tt.recursive,
|
Recursive: tt.recursive,
|
||||||
@ -83,9 +79,6 @@ func TestCloneNonEmpty(t *testing.T) {
|
|||||||
CommitSha: tt.commit,
|
CommitSha: tt.commit,
|
||||||
Branch: "main",
|
Branch: "main",
|
||||||
},
|
},
|
||||||
Pipeline: Pipeline{
|
|
||||||
Event: tt.event,
|
|
||||||
},
|
|
||||||
Home: "/tmp",
|
Home: "/tmp",
|
||||||
WorkDir: filepath.Join(dir, tt.path),
|
WorkDir: filepath.Join(dir, tt.path),
|
||||||
Recursive: tt.recursive,
|
Recursive: tt.recursive,
|
||||||
@ -150,7 +143,6 @@ func getCommits() []testCommit {
|
|||||||
name: "first commit",
|
name: "first commit",
|
||||||
path: "octocat/Hello-World",
|
path: "octocat/Hello-World",
|
||||||
clone: "https://github.com/octocat/Hello-World.git",
|
clone: "https://github.com/octocat/Hello-World.git",
|
||||||
event: "push",
|
|
||||||
commit: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
|
commit: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
|
||||||
ref: "refs/heads/master",
|
ref: "refs/heads/master",
|
||||||
file: "README",
|
file: "README",
|
||||||
@ -160,7 +152,6 @@ func getCommits() []testCommit {
|
|||||||
name: "head commit",
|
name: "head commit",
|
||||||
path: "octocat/Hello-World",
|
path: "octocat/Hello-World",
|
||||||
clone: "https://github.com/octocat/Hello-World.git",
|
clone: "https://github.com/octocat/Hello-World.git",
|
||||||
event: "push",
|
|
||||||
commit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
commit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
||||||
ref: "refs/heads/master",
|
ref: "refs/heads/master",
|
||||||
file: "README",
|
file: "README",
|
||||||
@ -170,7 +161,6 @@ func getCommits() []testCommit {
|
|||||||
name: "pull request commit",
|
name: "pull request commit",
|
||||||
path: "octocat/Hello-World",
|
path: "octocat/Hello-World",
|
||||||
clone: "https://github.com/octocat/Hello-World.git",
|
clone: "https://github.com/octocat/Hello-World.git",
|
||||||
event: "pull_request",
|
|
||||||
commit: "762941318ee16e59dabbacb1b4049eec22f0d303",
|
commit: "762941318ee16e59dabbacb1b4049eec22f0d303",
|
||||||
ref: "refs/pull/6/merge",
|
ref: "refs/pull/6/merge",
|
||||||
file: "README",
|
file: "README",
|
||||||
@ -180,7 +170,6 @@ func getCommits() []testCommit {
|
|||||||
name: "branch",
|
name: "branch",
|
||||||
path: "octocat/Hello-World",
|
path: "octocat/Hello-World",
|
||||||
clone: "https://github.com/octocat/Hello-World.git",
|
clone: "https://github.com/octocat/Hello-World.git",
|
||||||
event: "push",
|
|
||||||
commit: "b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf",
|
commit: "b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf",
|
||||||
ref: "refs/heads/test",
|
ref: "refs/heads/test",
|
||||||
file: "CONTRIBUTING.md",
|
file: "CONTRIBUTING.md",
|
||||||
@ -190,7 +179,6 @@ func getCommits() []testCommit {
|
|||||||
name: "tags",
|
name: "tags",
|
||||||
path: "github/mime-types",
|
path: "github/mime-types",
|
||||||
clone: "https://github.com/github/mime-types.git",
|
clone: "https://github.com/github/mime-types.git",
|
||||||
event: "tag",
|
|
||||||
commit: "bf68d60215a167c935bc5976b7d06a7ffb290926",
|
commit: "bf68d60215a167c935bc5976b7d06a7ffb290926",
|
||||||
ref: "refs/tags/v1.17",
|
ref: "refs/tags/v1.17",
|
||||||
file: ".gitignore",
|
file: ".gitignore",
|
||||||
@ -200,7 +188,6 @@ func getCommits() []testCommit {
|
|||||||
name: "submodules",
|
name: "submodules",
|
||||||
path: "test-assets/woodpecker-git-test-submodule",
|
path: "test-assets/woodpecker-git-test-submodule",
|
||||||
clone: "https://github.com/test-assets/woodpecker-git-test-submodule.git",
|
clone: "https://github.com/test-assets/woodpecker-git-test-submodule.git",
|
||||||
event: "push",
|
|
||||||
commit: "cc020eb6aaa601c13ca7b0d5db9d1ca694e7a003",
|
commit: "cc020eb6aaa601c13ca7b0d5db9d1ca694e7a003",
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/main",
|
||||||
file: "Hello-World/README",
|
file: "Hello-World/README",
|
||||||
@ -211,7 +198,6 @@ func getCommits() []testCommit {
|
|||||||
name: "checkout with ref only",
|
name: "checkout with ref only",
|
||||||
path: "octocat/Hello-World",
|
path: "octocat/Hello-World",
|
||||||
clone: "https://github.com/octocat/Hello-World.git",
|
clone: "https://github.com/octocat/Hello-World.git",
|
||||||
event: "push",
|
|
||||||
// commit: "a11fb45a696bf1d696fc9ab2c733f8f123aa4cf5",
|
// commit: "a11fb45a696bf1d696fc9ab2c733f8f123aa4cf5",
|
||||||
ref: "pull/2403/head",
|
ref: "pull/2403/head",
|
||||||
file: "README",
|
file: "README",
|
||||||
@ -222,7 +208,6 @@ func getCommits() []testCommit {
|
|||||||
name: "checkout with lfs skip",
|
name: "checkout with lfs skip",
|
||||||
path: "test-assets/woodpecker-git-test-lfs",
|
path: "test-assets/woodpecker-git-test-lfs",
|
||||||
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
|
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
|
||||||
event: "push",
|
|
||||||
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
|
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/main",
|
||||||
file: "4M.bin",
|
file: "4M.bin",
|
||||||
@ -232,7 +217,6 @@ func getCommits() []testCommit {
|
|||||||
name: "checkout with lfs",
|
name: "checkout with lfs",
|
||||||
path: "test-assets/woodpecker-git-test-lfs",
|
path: "test-assets/woodpecker-git-test-lfs",
|
||||||
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
|
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
|
||||||
event: "push",
|
|
||||||
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
|
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/main",
|
||||||
file: "4M.bin",
|
file: "4M.bin",
|
||||||
|
@ -16,10 +16,6 @@ type Plugin struct {
|
|||||||
Settings *Settings
|
Settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pipeline struct {
|
|
||||||
Event string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Netrc struct {
|
type Netrc struct {
|
||||||
Machine string
|
Machine string
|
||||||
Login string
|
Login string
|
||||||
@ -39,9 +35,8 @@ type Settings struct {
|
|||||||
Home string
|
Home string
|
||||||
WorkDir string
|
WorkDir string
|
||||||
|
|
||||||
Pipeline Pipeline
|
Netrc Netrc
|
||||||
Netrc Netrc
|
Repo git.Repository
|
||||||
Repo git.Repository
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(options wp.Options, settings *Settings) *Plugin {
|
func New(options wp.Options, settings *Settings) *Plugin {
|
||||||
|
Loading…
Reference in New Issue
Block a user