From 02f1627ade9e6b3b69e6a6d4fe8bc997474f48d1 Mon Sep 17 00:00:00 2001 From: Yuki Kimura Date: Thu, 26 Sep 2019 18:36:11 +0900 Subject: [PATCH] initial commit --- Dockerfile | 9 +++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ action.yml | 19 +++++++++++++++++++ mirror.sh | 8 ++++++++ setup-ssh.sh | 6 ++++++ 6 files changed, 107 insertions(+) create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100755 mirror.sh create mode 100755 setup-ssh.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63435dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.10 + +RUN apk update && apk upgrade && \ + apk add --no-cache git openssh + +COPY mirror.sh /mirror.sh +COPY setup-ssh.sh /setup-ssh.sh + +ENTRYPOINT ["/mirror.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8784dcc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 PIXTA Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cec6bed --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# README + +A GitHub Action for mirroring a repository to another repository on GitHub, GitLab, BitBucket, AWS CodeCommit, etc. + +This will copy all commits, branches and tags. + +>⚠️ Note that the other settings will not be copied. Please check which branch is 'default branch' after the first mirroring. + +## Usage + +Customize following example workflow and save as .github/workflows/main.yml on your source repository. + +cf. [Creating and using secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) . + +```yaml +name: Mirroring + +on: [push, delete] + +jobs: + to_gitlab: + runs-on: ubuntu-18.04 + steps: # <-- must use actions/checkout@v1 before mirroring! + - uses: actions/checkout@v1 + - uses: pixta-dev/repository-mirroring-action@v1 + with: + target_repo_url: + git@gitlab.com:/.git + ssh_private_key: # <-- use 'secrets' to pass credential information. + ${{ secrets.GITLAB_SSH_PRIVATE_KEY }} + + to_codecommit: # <-- different jobs are executed in parallel. + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v1 + - uses: pixta-dev/repository-mirroring-action@v1 + with: + target_repo_url: + ssh://git-codecommit..amazonaws.com/v1/repos/ + ssh_private_key: + ${{ secrets.CODECOMMIT_SSH_PRIVATE_KEY }} + ssh_username: # <-- (for codecommit) you need to specify ssh-key-id as ssh username. + ${{ secrets.CODECOMMIT_SSH_PRIVATE_KEY_ID }} +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ba3964a --- /dev/null +++ b/action.yml @@ -0,0 +1,19 @@ +name: "Mirroring Repository" +description: "Mirror a repository to another repository on GitHub, GitLab, BitBucket, AWS CodeCommit, etc." +branding: + icon: "archive" + color: "blue" +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' diff --git a/mirror.sh b/mirror.sh new file mode 100755 index 0000000..67ea71f --- /dev/null +++ b/mirror.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -eu + +/setup-ssh.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-ssh.sh b/setup-ssh.sh new file mode 100755 index 0000000..276559c --- /dev/null +++ b/setup-ssh.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -eu + +mkdir ~/.ssh +echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa +chmod 600 ~/.ssh/id_rsa