Skip to content

Commit

Permalink
update: test script
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtong committed May 10, 2023
1 parent bdc4c8b commit 2853ec0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 51 deletions.
38 changes: 11 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
<div align=center>
<img src="https://avatars.githubusercontent.com/u/40497166?s=100" width = "100" height = "100" style="border-radius: 50%;" div align=center />
</div>
<p align="center">
<a href="https://github.com/yehan-coding/yehan-git-sync">
<img src="https://img.shields.io/badge/git-sync-orange" alt="git-sync">
</a>
<a href="https://github.com/yehan-coding/yehan-git-sync/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-orange" alt="license">
</a>
</p>

# Yehan Git Sync

用于将当前仓库同步到指定的仓库的 action.
# Yehan Repo Sync

>Synchronize the current GitHub repository to the specified repository.
## Usage

### GitHub Actions
```
# File: .github/workflows/repo-sync.yml
name: "Git Repository Sync"
name: "Repo Sync"
on:
push:
jobs:
repo-sync:
runs-on: ubuntu-latest
steps:
- name: repo-sync
uses: yehan-coding/yehan-git-sync@v1
uses: yehan68/yehan-repo-sync@v2
with:
source_repo_url: git@github.com:${{ github.repository }}.git
source_branch: master
destination_repo_url: git@gitee.com:charleszht/test001.git
destination_branch: master
destination_repo_url: git@gitee.com:yehan68/repo-sync.git
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
```

### GitHub Actions 参数说明
```
source_repo_url 需要同步的仓库地址
### Parameter Description

```
source_repo_url: 需要同步的仓库地址
source_branch: 需要同步的仓库分支
destination_repo_url: 目标仓库地址
destination_branch: 目标仓库分支
ssh_private_key: 将本地 .ssh 文件夹中的 id_rsa 添加到仓库的secret中(同时需要将对应的 id_rsa.pub 添加到目标 git 仓库的 ssh keys 中)
```



## Author
[Ye Han](https://github.com/yehan-coding) _zhangtong.mr@aliyun.com_

[Ye Han](https://github.com/yehan-coding) _zhangtong.mr@aliyun.com_

## License

[MIT](https://github.com/yehan-coding/yehan-git-sync/blob/master/LICENSE)
12 changes: 2 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Yehan Git Sync Action
name: Yehan Repo Sync Action
author: Ye Han <zhangtong.mr@aliyun.com>
description: Sync current repo to specified repo
branding:
Expand All @@ -8,15 +8,9 @@ inputs:
source_repo_url:
description: source repo url
required: true
source_branch:
description: source repo branch
required: true
destination_repo_url:
description: destination repo url
required: true
destination_branch:
description: destination repo branch
required: true
ssh_private_key:
description: SSH_KEY
required: true
Expand All @@ -27,6 +21,4 @@ runs:
SSH_PRIVATE_KEY: ${{ inputs.ssh_private_key }}
args:
- ${{ inputs.source_repo_url }}
- ${{ inputs.source_branch }}
- ${{ inputs.destination_repo_url }}
- ${{ inputs.destination_branch }}
- ${{ inputs.destination_repo_url }}
4 changes: 2 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine

LABEL "repository"="https://github.com/yehan68/yehan-git-sync"
LABEL "homepage"="https://github.com/marketplace/actions/yehan-git-sync-action"
LABEL "repository"="https://github.com/yehan68/yehan-repo-sync"
LABEL "homepage"="https://github.com/marketplace/actions/yehan-repo-sync-action"
LABEL "maintainer"="Ye Han <zhangtong.mr@aliyun.com>"

RUN apk add --no-cache git openssh-client && \
Expand Down
20 changes: 8 additions & 12 deletions src/sync-repo.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/sh

# 检查参数
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then
echo "Usage: $0 source_repo_url source_branch target_repo_url target_branch"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 source_repo_url target_repo_url"
exit 1
fi

SOURCE_REPO_URL="$1"
SOURCE_BRANCH="$2"
DESTINATION_REPO_URL="$3"
DESTINATION_BRANCH="$4"
DESTINATION_REPO_URL="$2"

# 函数:克隆 Git 仓库
function clone_repo() {
Expand All @@ -24,13 +22,11 @@ function clone_repo() {
}

# 函数:推送分支
function push_branch() {
local source_branch="$1"
local destination_branch="$2"
local repo_dir="$3"
function push_target() {
local repo_dir="$1"
cd "$repo_dir"
echo "Pushing branch $source_branch to $destination_branch..."
git push destination "$source_branch:$destination_branch"
echo "Pushing ..."
git push destination
}

# 克隆源 Git 仓库
Expand All @@ -46,4 +42,4 @@ git fetch destination '+refs/heads/*:refs/heads/*' --update-head-ok
git branch -a -v

# 推送源分支到目标分支
push_branch "$SOURCE_BRANCH" "$TARGET_BRANCH" "/root/source"
push_target "/root/source"

0 comments on commit 2853ec0

Please sign in to comment.