From 92eb8ce65116bfd1949531c8b2b801ac0cadf574 Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Sat, 17 Sep 2022 11:32:38 +0530 Subject: [PATCH] Inital Release --- .github/workflows/gitea.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/gitlab.yml | 30 ++++++++++++++++++++++++++++++ Dockerfile | 11 +++++++++++ README.md | 2 ++ action.yml | 19 +++++++++++++++++++ mirror.sh | 8 ++++++++ setup.sh | 6 ++++++ 7 files changed, 107 insertions(+) create mode 100644 .github/workflows/gitea.yml create mode 100644 .github/workflows/gitlab.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 action.yml create mode 100644 mirror.sh create mode 100644 setup.sh diff --git a/.github/workflows/gitea.yml b/.github/workflows/gitea.yml new file mode 100644 index 0000000..02128dd --- /dev/null +++ b/.github/workflows/gitea.yml @@ -0,0 +1,31 @@ +name: Test on Gitea + +on: + delete: + push: + pull_request: + +jobs: + check_preconditions: + runs-on: ubuntu-latest + outputs: + results: ${{ join(steps.*.outcome) }} + steps: + - id: secrets + continue-on-error: true + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + TARGET_REPO_URL: ${{ secrets.TARGET_GITEA_REPO_URL }} + run: '[ -n "$SSH_PRIVATE_KEY" ] && [ -n "$TARGET_REPO_URL" ]' + mirroring: + needs: check_preconditions + if: "!contains(needs.check_preconditions.outputs.results, 'failure')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: ./ + with: + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + target_repo_url: ${{ secrets.TARGET_REPO_URL }} diff --git a/.github/workflows/gitlab.yml b/.github/workflows/gitlab.yml new file mode 100644 index 0000000..f2e3ea2 --- /dev/null +++ b/.github/workflows/gitlab.yml @@ -0,0 +1,30 @@ +name: Test on Gitlab +on: + delete: + push: + pull_request: + +jobs: + check_preconditions: + runs-on: ubuntu-latest + outputs: + results: ${{ join(steps.*.outcome) }} + steps: + - id: secrets + continue-on-error: true + env: + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + TARGET_REPO_URL: ${{ secrets.TARGET_GITLAB_REPO_URL }} + run: '[ -n "$SSH_PRIVATE_KEY" ] && [ -n "$TARGET_REPO_URL" ]' + mirroring: + needs: check_preconditions + if: "!contains(needs.check_preconditions.outputs.results, 'failure')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: ./ + with: + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + target_repo_url: ${{ secrets.TARGET_GITLAB_REPO_URL }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..36d1136 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM alpine + +RUN apk update && apk upgrade && \ + apk add --no-cache git openssh git-lfs + +RUN git lfs install + +COPY mirror.sh /mirror.sh +COPY setup-ssh.sh /setup-ssh.sh + +ENTRYPOINT ["/mirror.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..d87d182 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Git Sync Mirror + diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..8353c30 --- /dev/null +++ b/action.yml @@ -0,0 +1,19 @@ +name: "Git Sync Mirror" +description: "Mirror your repository into another repository (Gitea and GitLab)" +branding: + icon: "copy" + color: "yellow" +inputs: + ssh_private_key: + description: "SSH private key for ssh connection to the target repository" + required: false + target_repo_url: + description: "Target url" + required: true + ssh_username: + description: "Username for ssh connection" + required: false + default: "git" +runs: + using: 'docker' + image: 'Dockerfile' \ No newline at end of file diff --git a/mirror.sh b/mirror.sh new file mode 100644 index 0000000..b822206 --- /dev/null +++ b/mirror.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -eu + +/setup.sh + +export GIT_SSH_COMMAND="ssh -v -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -l $INPUT_SSH_USERNAME" +git remote add mirror "$INPUT_TARGET_REPO_URL" +git push --tags --force --prune mirror "refs/remotes/origin/*:refs/heads/*" diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..fde0cfa --- /dev/null +++ b/setup.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -eu + +mkdir -p ~/.ssh +echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa +chmod 600 ~/.ssh/id_rsa