Skip to content

Commit

Permalink
update: mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
k8scat committed May 12, 2022
1 parent 1651f12 commit 96b5d3c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/github-org-to-gitee-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -24,12 +24,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub Org to Gitee Org
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: huayin-opensource
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: gitee.com
dest_username: huayin-opensource
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-bitbucket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -24,12 +24,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to BitBucket
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: bitbucket.org
dest_username: k8scat
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-coding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -26,12 +26,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to Coding
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: e.coding.com/k8scat
dest_username: ${{ secrets.CODING_PROJECT_NAME }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-gitea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -24,12 +24,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to Gitea
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: gitea.com
dest_username: k8scat
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-gitee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -24,12 +24,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to Gitee
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: gitee.com
dest_username: k8scat
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -24,12 +24,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to GitHub
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: github.com
dest_username: k8scat-archived
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/github-to-gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Login Source GitHub
run: |
gh --version
echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: List repos
Expand All @@ -35,12 +35,12 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: GitHub to GitLab
uses: k8scat/[email protected].2
uses: k8scat/[email protected].3
with:
source_protocol: https
source_host: github.com
source_username: k8scat
source_token: ${{ secrets.SOURCE_TOKEN }}
source_token: ${{ secrets.GITHUB_TOKEN }}
dest_protocol: https
dest_host: gitlab.com
dest_username: k8scat
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
os = $(shell uname -s)

version = 0.1.2
version = 0.1.3
image = mirror-git:$(version)

cr_user = gigrator
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ docker run \
-e INPUT_LARK_WEBHOOK="xxx" \
-e INPUT_NOTIFY_PREFIX="Mirror Git" \
-e INPUT_NOTIFY_SUFFIX="Powered by https://github.com/k8scat/action-mirror-git" \
gigrator/mirror-git:0.1.2
gigrator/mirror-git:0.1.3
```

## LICENSE
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ inputs:
default: "false"
runs:
using: "docker"
image: "docker://ghcr.io/k8scat/mirror-git:0.1.2"
image: "docker://ghcr.io/k8scat/mirror-git:0.1.3"
17 changes: 10 additions & 7 deletions mirror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Created by K8sCat <[email protected]>
set +e

PROTOCOL_SSH="ssh"
PROTOCOL_HTTPS="https"

function init_workdir() {
WORKDIR="/data/repos"
mkdir -p ${WORKDIR}
Expand Down Expand Up @@ -125,23 +128,23 @@ function init_ssh() {
mkdir -p "${SSH_DIR}"
chmod 0700 "${SSH_DIR}"

if [[ "${INPUT_SOURCE_PROTOCOL}" = "ssh" ]]; then
if [[ "${INPUT_SOURCE_PROTOCOL}" = "${PROTOCOL_SSH}" ]]; then
INPUT_SOURCE_HOST=$(write_ssh_config "source" "${INPUT_SOURCE_HOST}" "${INPUT_SOURCE_PORT}" "${INPUT_SOURCE_USERNAME}" "${INPUT_SOURCE_PRIVATE_KEY}")
export INPUT_SOURCE_HOST
fi
if [[ "${INPUT_DEST_PROTOCOL}" = "ssh" ]]; then
if [[ "${INPUT_DEST_PROTOCOL}" = "${PROTOCOL_SSH}" ]]; then
INPUT_DEST_HOST=$(write_ssh_config "dest" "${INPUT_DEST_HOST}" "${INPUT_DEST_PORT}" "${INPUT_DEST_USERNAME}" "${INPUT_DEST_PRIVATE_KEY}")
export INPUT_DEST_HOST
fi
}

function gen_source_addr() {
if [[ "${INPUT_SOURCE_PROTOCOL}" = "ssh" ]]; then
if [[ "${INPUT_SOURCE_PROTOCOL}" = "${PROTOCOL_SSH}" ]]; then
source_addr="git@${INPUT_SOURCE_HOST}:${INPUT_SOURCE_USERNAME}/${REPO_NAME}.git"
echo "${source_addr}"
return
fi
if [[ "${INPUT_SOURCE_PROTOCOL}" = "https" ]]; then
if [[ "${INPUT_SOURCE_PROTOCOL}" = "${PROTOCOL_HTTPS}" ]]; then
source_addr="https://${INPUT_SOURCE_TOKEN_USERNAME}:${INPUT_SOURCE_TOKEN}@${INPUT_SOURCE_HOST}"
if [[ -n "${INPUT_SOURCE_PORT}" ]]; then
source_addr="${source_addr}:${INPUT_SOURCE_PORT}"
Expand All @@ -155,12 +158,12 @@ function gen_source_addr() {
}

function gen_dest_addr() {
if [[ "${INPUT_DEST_PROTOCOL}" = "ssh" ]]; then
if [[ "${INPUT_DEST_PROTOCOL}" = "${PROTOCOL_SSH}" ]]; then
dest_addr="git@${INPUT_DEST_HOST}:${INPUT_DEST_USERNAME}/${REPO_NAME}.git"
echo "${dest_addr}"
return
fi
if [[ "${INPUT_DEST_PROTOCOL}" = "https" ]]; then
if [[ "${INPUT_DEST_PROTOCOL}" = "${PROTOCOL_HTTPS}" ]]; then
dest_addr="https://${INPUT_DEST_TOKEN_USERNAME}:${INPUT_DEST_TOKEN}@${INPUT_DEST_HOST}"
if [[ -n "${INPUT_DEST_PORT}" ]]; then
dest_addr="${dest_addr}:${INPUT_DEST_PORT}"
Expand Down Expand Up @@ -246,7 +249,7 @@ function main() {
init_message
init_ssh

notify "Mirror Git starting"
notify "Mirror Git started"
if mirror; then
notify "Mirror Git finished"
else
Expand Down

0 comments on commit 96b5d3c

Please sign in to comment.