diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml deleted file mode 100644 index 22c275b..0000000 --- a/.github/workflows/example.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Example - -on: - workflow_dispatch: - -jobs: - mirror-main: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Check tools - run: | - gh --version - git --version - - - name: Login Source GitHub - run: | - echo "${{ secrets.SOURCE_TOKEN }}" > /tmp/.github_token - gh auth login --with-token < /tmp/.github_token - gh auth status - rm -f /tmp/.github_token - - - name: List repos - id: list_repos - run: | - gh repo list ${{ secrets.SOURCE_USERNAME }} -L 1000 > /tmp/repos.txt - cat /tmp/repos.txt | while read -r repo; do - repo_name=$(echo ${repo} | awk '{print $1}' | awk -F/ '{print $2}') - if [[ -f "/tmp/repo_list.txt" ]]; then - echo -n ",${repo_name}" >> /tmp/repo_list.txt - else - echo -n "${repo_name}" >> /tmp/repo_list.txt - fi - done - repo_list=$(cat /tmp/repo_list.txt) - echo "::set-output name=repo_list::${repo_list}" - - - name: action-git-mirror - uses: k8scat/action-git-mirror@v0.1.0 - with: - source_protocol: https - source_host: github.com - source_username: ${{ secrets.SOURCE_USERNAME }} - source_token: ${{ secrets.SOURCE_TOKEN }} - dest_protocol: ssh - dest_host: github.com - dest_username: ${{ secrets.DEST_USERNAME }} - dest_private_key: ${{ secrets.DEST_PRIVATE_KEY }} - push_tags: "true" - mirror_repos: ${{ steps.list_repos.outputs.repo_list }} - # repo3 and repo4 will only sync branches and commits - skip_tags_repos: "repo3,repo4" - # repo5 and repo6 will not be synced - ignored_repos: "repo5,repo6" - dest_create_repo_script: | - # create repo via github cli - if ! gh auth status; then - token_file="/tmp/.github_token" - echo "${INPUT_DEST_TOKEN}" > "${token_file}" - gh auth login --with-token < "${token_file}" - gh auth status - fi - - repo="${INPUT_DEST_USERNAME}/${REPO_NAME}" - found=$(gh repo list ${{ secrets.SOURCE_USERNAME }} -L 1000 | grep -i "${repo}") - if [[ -z "${found}" ]]; then - gh repo create "${INPUT_DEST_USERNAME}/${REPO_NAME}" --private - fi - slack_webhook: ${{ secrets.SLACK_WEBHOOK }} - # dingtalk_webhook: ${{ secrets.DINGTALK_WEBHOOK }} - # lark_webhook: ${{ secrets.LARK_WEBHOOK }} - force_push: "true" - dest_delete_repo_script: | - # delete repo via github cli - if ! gh auth status; then - token_file="/tmp/.github_token" - echo "${INPUT_DEST_TOKEN}" > "${token_file}" - gh auth login --with-token < "${token_file}" - gh auth status - fi - gh repo delete "${INPUT_DEST_USERNAME}/${REPO_NAME}" --confirm diff --git a/.github/workflows/github-org-to-gitee-org.yml b/.github/workflows/github-org-to-gitee-org.yml index 80c698a..b453c63 100644 --- a/.github/workflows/github-org-to-gitee-org.yml +++ b/.github/workflows/github-org-to-gitee-org.yml @@ -23,7 +23,7 @@ jobs: repo_list=$(gh repo list huayin-opensource -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') echo "::set-output name=repo_list::${repo_list}" - - name: Mirror Git + - name: GitHub Org to Gitee Org uses: k8scat/action-mirror-git@v0.1.0 with: source_protocol: https diff --git a/.github/workflows/github-to-bitbucket.yml b/.github/workflows/github-to-bitbucket.yml index baabd52..ebf5b1e 100644 --- a/.github/workflows/github-to-bitbucket.yml +++ b/.github/workflows/github-to-bitbucket.yml @@ -23,7 +23,7 @@ jobs: repo_list=$(gh repo list k8scat -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') echo "::set-output name=repo_list::${repo_list}" - - name: Mirror Git + - name: GitHub to BitBucket uses: k8scat/action-mirror-git@v0.1.0 with: source_protocol: https diff --git a/.github/workflows/github-to-gitea.yml b/.github/workflows/github-to-gitea.yml new file mode 100644 index 0000000..c501a1a --- /dev/null +++ b/.github/workflows/github-to-gitea.yml @@ -0,0 +1,53 @@ +name: GitHub to Gitee + +on: + workflow_dispatch: + schedule: + - cron: "0 2 * * 3" + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Login Source GitHub + run: | + gh --version + echo "${{ secrets.SOURCE_TOKEN }}" | gh auth login --with-token + gh auth status + + - name: List repos + id: list_repos + run: | + repo_list=$(gh repo list -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') + echo "::set-output name=repo_list::${repo_list}" + + - name: GitHub to Gitea + uses: k8scat/action-mirror-git@v0.1.0 + with: + source_protocol: https + source_host: github.com + source_username: k8scat + source_token: ${{ secrets.SOURCE_TOKEN }} + dest_protocol: https + dest_host: gitee.com + dest_username: k8scat + dest_token: ${{ secrets.DEST_TOKEN_GITEA }} + push_tags: "true" + mirror_repos: ${{ steps.list_repos.outputs.repo_list }} + ignored_repos: "Gigrator" + dest_create_repo_script: | + curl \ + -H 'Content-Type: application/json' \ + -H "Authorization: token ${INPUT_DEST_TOKEN}" \ + -d "{\"name\":\"test\",\"private\":true}" \ + 'https://gitea.com/api/v1/user/repos' + dest_delete_repo_script: | + curl \ + -X DELETE \ + -H "Authorization: token ${INPUT_DEST_TOKEN}" \ + "https://gitea.com/api/v1/repos/${INPUT_DEST_USERNAME}/${REPO_NAME}" + lark_webhook: ${{ secrets.LARK_WEBHOOK }} + notify_prefix: "GitHub to Gitea" + force_push: "true" diff --git a/.github/workflows/github-to-gitee.yml b/.github/workflows/github-to-gitee.yml index 89b03ed..425008a 100644 --- a/.github/workflows/github-to-gitee.yml +++ b/.github/workflows/github-to-gitee.yml @@ -23,7 +23,7 @@ jobs: repo_list=$(gh repo list -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') echo "::set-output name=repo_list::${repo_list}" - - name: Mirror Git + - name: GitHub to Gitee uses: k8scat/action-mirror-git@v0.1.0 with: source_protocol: https diff --git a/.github/workflows/github-to-github.yml b/.github/workflows/github-to-github.yml index 1684fd7..63be81e 100644 --- a/.github/workflows/github-to-github.yml +++ b/.github/workflows/github-to-github.yml @@ -23,7 +23,7 @@ jobs: repo_list=$(gh repo list k8scat -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') echo "::set-output name=repo_list::${repo_list}" - - name: Mirror Git + - name: GitHub to GitHub uses: k8scat/action-mirror-git@v0.1.0 with: source_protocol: https diff --git a/.github/workflows/github-to-gitlab.yml b/.github/workflows/github-to-gitlab.yml index a02ee15..ea9c3c3 100644 --- a/.github/workflows/github-to-gitlab.yml +++ b/.github/workflows/github-to-gitlab.yml @@ -34,7 +34,7 @@ jobs: repo_list=$(gh repo list -L 1000 --json name -t '{{range $i, $n := .}}{{if (gt $i 0)}},{{end}}{{$n.name}}{{end}}') echo "::set-output name=repo_list::${repo_list}" - - name: Mirror Git + - name: GitHub to GitLab uses: k8scat/action-mirror-git@v0.1.0 with: source_protocol: https diff --git a/Dockerfile b/Dockerfile index bbee550..94aa29b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/gigrator/base:0.0.6 +FROM ghcr.io/gigrator/base:0.0.7 LABEL maintainer="K8sCat " LABEL repository="https://github.com/k8scat/action-mirror-git.git" COPY mirror.sh /mirror.sh diff --git a/Makefile b/Makefile index e099282..85abe01 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ os = $(shell uname -s) -version = 0.1.0 +version = 0.1.1 image = mirror-git:$(version) cr_user = gigrator @@ -44,7 +44,6 @@ endif ifeq ($(os),Darwin) sed -i "" 's/$(version)/$(new_version)/g' Makefile sed -i "" 's/$(version)/$(new_version)/g' action.yml - sed -i "" 's/$(version)/$(new_version)/g' .github/workflows/example.yml sed -i "" 's/$(version)/$(new_version)/g' README.md sed -i "" 's/$(version)/$(new_version)/g' .github/workflows/github-to-github.yml sed -i "" 's/$(version)/$(new_version)/g' .github/workflows/github-to-gitee.yml @@ -54,7 +53,6 @@ ifeq ($(os),Darwin) else sed -i 's/$(version)/$(new_version)/g' Makefile sed -i 's/$(version)/$(new_version)/g' action.yml - sed -i 's/$(version)/$(new_version)/g' .github/workflows/example.yml sed -i 's/$(version)/$(new_version)/g' README.md sed -i 's/$(version)/$(new_version)/g' .github/workflows/github-to-github.yml sed -i 's/$(version)/$(new_version)/g' .github/workflows/github-to-gitee.yml diff --git a/README.md b/README.md index e8cebec..acc2443 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ dest_delete_repo_script: | - [GitHub to GitHub](./.github/workflows/github-to-github.yml) - [GitHub to GitLab](./.github/workflows/github-to-gitlab.yml) - [GitHub to BitBucket](./.github/workflows/github-to-bitbucket.yml) +- [GitHub to Gitea] ## Run diff --git a/action.yml b/action.yml index 82bc783..33aa5cd 100644 --- a/action.yml +++ b/action.yml @@ -100,4 +100,4 @@ inputs: default: "false" runs: using: "docker" - image: "docker://ghcr.io/k8scat/mirror-git:0.1.0" + image: "docker://ghcr.io/k8scat/mirror-git:0.1.1" diff --git a/mirror.sh b/mirror.sh index 6b3fd68..a3d7ff0 100755 --- a/mirror.sh +++ b/mirror.sh @@ -199,9 +199,6 @@ function mirror() { source_addr=$(gen_source_addr) echo "source_addr: ${source_addr}" - dest_addr=$(gen_dest_addr) - echo "dest_addr: ${dest_addr}" - if ! git clone --bare "${source_addr}" "${REPO_NAME}"; then notify "Failed to clone ${source_addr}" if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then @@ -221,6 +218,9 @@ function mirror() { fi fi + dest_addr=$(gen_dest_addr) + echo "dest_addr: ${dest_addr}" + repo_dir="${WORKDIR}/${REPO_NAME}" cd "${repo_dir}" || exit 1 if ! git push --all -f "${dest_addr}"; then