File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,6 +51,18 @@ An example of specifying the path to a repo:
5151 path : path/to/repo
5252` ` `
5353
54+ An example of mirroring all refs to a remote repository:
55+
56+ ` ` ` yaml
57+ - name : mirror push
58+ image : appleboy/drone-git-push
59+ settings :
60+ remote : git@github.com:foo/bar-mirror.git
61+ mirror : true
62+ ssh_key :
63+ from_secret : deploy_key
64+ ` ` `
65+
5466## Parameter Reference
5567
5668| setting | description
@@ -71,3 +83,4 @@ An example of specifying the path to a repo:
7183| author_email | the email address to use for the author of the commit (if blank, assume push commiter name)
7284| followtags | push with --follow-tags option
7385| rebase | pull --rebase before pushing
86+ | mirror | push all refs to remote repository with --mirror, defaults to false
Original file line number Diff line number Diff line change @@ -46,3 +46,17 @@ docker run --rm \
4646 -w " $( pwd) " \
4747 appleboy/drone-git-push
4848```
49+
50+ Mirror all refs to a remote repository:
51+
52+ ``` sh
53+ docker run --rm \
54+ -e DRONE_COMMIT_AUTHOR=Octocat \
55+ -e DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com \
56+ -e PLUGIN_SSH_KEY=" $( cat " ${HOME} /.ssh/id_rsa" ) " \
57+ -e PLUGIN_REMOTE=git@github.com:foo/bar.git \
58+ -e PLUGIN_MIRROR=true \
59+ -v " $( pwd) :$( pwd) " \
60+ -w " $( pwd) " \
61+ appleboy/drone-git-push
62+ ```
Original file line number Diff line number Diff line change 1-
21# drone-git-push
32
43[ English] ( README.md ) | [ 繁體中文] ( README.zh-tw.md )
54
65[ ![ GoDoc] ( https://godoc.org/github.com/appleboy/drone-git-push?status.svg )] ( https://godoc.org/github.com/appleboy/drone-git-push )
76[ ![ Lint and Testing] ( https://github.com/appleboy/drone-git-push/actions/workflows/testing.yml/badge.svg )] ( https://github.com/appleboy/drone-git-push/actions/workflows/testing.yml )
7+ [ ![ Trivy Security Scan] ( https://github.com/appleboy/drone-git-push/actions/workflows/trivy.yml/badge.svg )] ( https://github.com/appleboy/drone-git-push/actions/workflows/trivy.yml )
88[ ![ codecov] ( https://codecov.io/gh/appleboy/drone-git-push/branch/master/graph/badge.svg )] ( https://codecov.io/gh/appleboy/drone-git-push )
99[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/appleboy/drone-git-push )] ( https://goreportcard.com/report/github.com/appleboy/drone-git-push )
1010[ ![ Docker Pulls] ( https://img.shields.io/docker/pulls/appleboy/drone-git-push.svg )] ( https://hub.docker.com/r/appleboy/drone-git-push/ )
1515## 构建
1616
1717使用以下命令构建二进制文件:
18+
19+ ``` sh
20+ go build
21+ go test
22+ ```
23+
24+ ## Docker
25+
26+ 使用以下命令构建 Docker 镜像:
27+
28+ ``` sh
29+ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-git-push
30+ docker build --rm -t appleboy/drone-git-push .
31+ ```
32+
33+ ## 使用方式
34+
35+ 从工作目录执行:
36+
37+ ``` sh
38+ docker run --rm \
39+ -e DRONE_COMMIT_AUTHOR=Octocat \
40+ -e DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com \
41+ -e PLUGIN_SSH_KEY=" $( cat " ${HOME} /.ssh/id_rsa" ) " \
42+ -e PLUGIN_BRANCH=master \
43+ -e PLUGIN_REMOTE=git@github.com:foo/bar.git \
44+ -e PLUGIN_FORCE=false \
45+ -v " $( pwd) :$( pwd) " \
46+ -w " $( pwd) " \
47+ appleboy/drone-git-push
48+ ```
49+
50+ 镜像所有 refs 到远程仓库:
51+
52+ ``` sh
53+ docker run --rm \
54+ -e DRONE_COMMIT_AUTHOR=Octocat \
55+ -e DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com \
56+ -e PLUGIN_SSH_KEY=" $( cat " ${HOME} /.ssh/id_rsa" ) " \
57+ -e PLUGIN_REMOTE=git@github.com:foo/bar.git \
58+ -e PLUGIN_MIRROR=true \
59+ -v " $( pwd) :$( pwd) " \
60+ -w " $( pwd) " \
61+ appleboy/drone-git-push
62+ ```
Original file line number Diff line number Diff line change 1-
21# drone-git-push
32
43[ English] ( README.md ) | [ 简体中文] ( README.zh-cn.md )
54
65[ ![ GoDoc] ( https://godoc.org/github.com/appleboy/drone-git-push?status.svg )] ( https://godoc.org/github.com/appleboy/drone-git-push )
76[ ![ Lint and Testing] ( https://github.com/appleboy/drone-git-push/actions/workflows/testing.yml/badge.svg )] ( https://github.com/appleboy/drone-git-push/actions/workflows/testing.yml )
7+ [ ![ Trivy Security Scan] ( https://github.com/appleboy/drone-git-push/actions/workflows/trivy.yml/badge.svg )] ( https://github.com/appleboy/drone-git-push/actions/workflows/trivy.yml )
88[ ![ codecov] ( https://codecov.io/gh/appleboy/drone-git-push/branch/master/graph/badge.svg )] ( https://codecov.io/gh/appleboy/drone-git-push )
99[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/appleboy/drone-git-push )] ( https://goreportcard.com/report/github.com/appleboy/drone-git-push )
1010[ ![ Docker Pulls] ( https://img.shields.io/docker/pulls/appleboy/drone-git-push.svg )] ( https://hub.docker.com/r/appleboy/drone-git-push/ )
1515## 建置
1616
1717使用以下命令建置二進位檔:
18+
19+ ``` sh
20+ go build
21+ go test
22+ ```
23+
24+ ## Docker
25+
26+ 使用以下命令建置 Docker 映像檔:
27+
28+ ``` sh
29+ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-git-push
30+ docker build --rm -t appleboy/drone-git-push .
31+ ```
32+
33+ ## 使用方式
34+
35+ 從工作目錄執行:
36+
37+ ``` sh
38+ docker run --rm \
39+ -e DRONE_COMMIT_AUTHOR=Octocat \
40+ -e DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com \
41+ -e PLUGIN_SSH_KEY=" $( cat " ${HOME} /.ssh/id_rsa" ) " \
42+ -e PLUGIN_BRANCH=master \
43+ -e PLUGIN_REMOTE=git@github.com:foo/bar.git \
44+ -e PLUGIN_FORCE=false \
45+ -v " $( pwd) :$( pwd) " \
46+ -w " $( pwd) " \
47+ appleboy/drone-git-push
48+ ```
49+
50+ 鏡像所有 refs 到遠端儲存庫:
51+
52+ ``` sh
53+ docker run --rm \
54+ -e DRONE_COMMIT_AUTHOR=Octocat \
55+ -e DRONE_COMMIT_AUTHOR_EMAIL=octocat@github.com \
56+ -e PLUGIN_SSH_KEY=" $( cat " ${HOME} /.ssh/id_rsa" ) " \
57+ -e PLUGIN_REMOTE=git@github.com:foo/bar.git \
58+ -e PLUGIN_MIRROR=true \
59+ -v " $( pwd) :$( pwd) " \
60+ -w " $( pwd) " \
61+ appleboy/drone-git-push
62+ ```
Original file line number Diff line number Diff line change @@ -161,6 +161,11 @@ func main() {
161161 Usage : "pull rebase branch before push" ,
162162 EnvVars : []string {"PLUGIN_REBASE" , "GIT_PUSH_REBASE" , "INPUT_REBASE" },
163163 },
164+ & cli.BoolFlag {
165+ Name : "mirror" ,
166+ Usage : "push all refs to remote repository with --mirror" ,
167+ EnvVars : []string {"PLUGIN_MIRROR" , "GIT_PUSH_MIRROR" , "INPUT_MIRROR" },
168+ },
164169 }
165170
166171 if err := app .Run (os .Args ); err != nil {
@@ -197,6 +202,7 @@ func run(c *cli.Context) error {
197202 EmptyCommit : c .Bool ("empty-commit" ),
198203 NoVerify : c .Bool ("no-verify" ),
199204 Rebase : c .Bool ("rebase" ),
205+ Mirror : c .Bool ("mirror" ),
200206 },
201207 }
202208
Original file line number Diff line number Diff line change 4343 EmptyCommit bool
4444 NoVerify bool
4545 Rebase bool
46+ Mirror bool
4647 }
4748
4849 // Plugin Structure
@@ -206,6 +207,10 @@ func (p Plugin) HandleTag(ctx context.Context) error {
206207
207208// HandlePush pushs the changes to the remote repo.
208209func (p Plugin ) HandlePush (ctx context.Context ) error {
210+ if p .Config .Mirror {
211+ return execute (repo .RemotePushMirror (ctx , p .Config .RemoteName ))
212+ }
213+
209214 var (
210215 name = p .Config .RemoteName
211216 local = p .Config .LocalBranch
Original file line number Diff line number Diff line change @@ -93,3 +93,18 @@ func RemotePushNamedBranch(
9393
9494 return cmd
9595}
96+
97+ // RemotePushMirror pushes all refs to remote repository using --mirror.
98+ func RemotePushMirror (ctx context.Context , remote string ) * exec.Cmd {
99+ sanitizedRemote := sanitizeInput (remote )
100+
101+ cmd := exec .CommandContext (
102+ ctx ,
103+ "git" ,
104+ "push" ,
105+ "--mirror" ,
106+ sanitizedRemote ,
107+ )
108+
109+ return cmd
110+ }
You can’t perform that action at this time.
0 commit comments