Repository: wearerequired/git-mirror-action Branch: master Commit: c44c68aebe42 Files: 8 Total size: 6.5 KB Directory structure: gitextract_ccxwoefh/ ├── .github/ │ └── workflows/ │ └── versioning.yml ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── entrypoint.sh └── git-mirror.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/versioning.yml ================================================ name: Keep the major version tag up-to-date on: release: types: [published, edited] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false jobs: update-major-tag: runs-on: ubuntu-latest steps: - uses: Actions-R-Us/actions-tagger@v2 ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.0.1] - 2020-03-23 ### Changed * Exclude hidden refs created by GitHub for pull request before pushing to mirror. ## [1.0.0] - 2019-11-26 ### Added * Initial release. [Unreleased]: https://github.com/wearerequired/git-mirror-action/compare/v1.0.1...HEAD [1.0.1]: https://github.com/wearerequired/git-mirror-action/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/wearerequired/git-mirror-action/compare/26c99373bfd4beb7811a3fd8a068ec944dadedcc...v1.0.0 ================================================ FILE: Dockerfile ================================================ FROM alpine RUN apk add --no-cache git openssh-client ADD *.sh / ENTRYPOINT ["/entrypoint.sh"] ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2019 required gmbh 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. ================================================ FILE: README.md ================================================ # Git Mirror Action A GitHub Action for [mirroring a git repository](https://help.github.com/en/articles/duplicating-a-repository#mirroring-a-repository-in-another-location) to another location via SSH. ## Inputs ### `source-repo` **Required** SSH URL of the source repo. ### `destination-repo` **Required** SSH URL of the destination repo. ### `dry-run` **Optional** *(default: `false`)* Execute a dry run. All steps are executed, but no updates are pushed to the destination repo. ## Environment variables `SSH_PRIVATE_KEY`: Create a [SSH key](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) **without** a passphrase which has access to both repositories. On GitHub you can add the public key as [a deploy key to the repository](https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys). GitLab has also [deploy keys with write access](https://docs.gitlab.com/ee/user/project/deploy_keys/) and for any other services you may have to add the public key to your personal account. Store the private key as [an encrypted secret](https://docs.github.com/en/actions/reference/encrypted-secrets) and use it in your workflow as seen in the example workflow below. `SSH_KNOWN_HOSTS`: Known hosts as used in the `known_hosts` file. *StrictHostKeyChecking* is disabled in case the variable isn't available. If you added the private key or known hosts in an [environment](https://docs.github.com/en/actions/reference/environments) make sure to [reference the environment name in your workflow](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idenvironment) otherwise the secret is not passed to the workflow. ## Example workflow ```yml name: Mirror to Bitbucket Repo on: [ push, delete, create ] # Ensures that only one mirror task will run at a time. concurrency: group: git-mirror jobs: git-mirror: runs-on: ubuntu-latest steps: - uses: wearerequired/git-mirror-action@v1 env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} with: source-repo: "git@github.com:wearerequired/git-mirror-action.git" destination-repo: "git@bitbucket.org:wearerequired/git-mirror-action.git" ``` ## Docker ```sh docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) "$SOURCE_REPO" "$DESTINATION_REPO" ``` ## License The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE). ================================================ FILE: action.yml ================================================ name: 'Mirror a repository using SSH' description: 'Action for mirroring a repository in another location (Bitbucket, GitHub, GitLab, …) using SSH.' branding: icon: 'copy' color: 'orange' inputs: source-repo: description: 'SSH URL of the source repo.' required: true default: '' destination-repo: description: 'SSH URL of the destination repo.' required: true default: '' dry-run: description: 'Execute a dry run.' required: false default: 'false' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.source-repo }} - ${{ inputs.destination-repo }} - ${{ inputs.dry-run }} ================================================ FILE: entrypoint.sh ================================================ #!/bin/sh set -e if [ -n "$SSH_PRIVATE_KEY" ] then mkdir -p /root/.ssh echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa fi if [ -n "$SSH_KNOWN_HOSTS" ] then mkdir -p /root/.ssh echo "StrictHostKeyChecking yes" >> /etc/ssh/ssh_config echo "$SSH_KNOWN_HOSTS" > /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts else echo "WARNING: StrictHostKeyChecking disabled" echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config fi mkdir -p ~/.ssh cp /root/.ssh/* ~/.ssh/ 2> /dev/null || true sh -c "/git-mirror.sh $*" ================================================ FILE: git-mirror.sh ================================================ #!/bin/sh set -e SOURCE_REPO=$1 DESTINATION_REPO=$2 SOURCE_DIR=$(basename "$SOURCE_REPO") DRY_RUN=$3 GIT_SSH_COMMAND="ssh -v" echo "SOURCE=$SOURCE_REPO" echo "DESTINATION=$DESTINATION_REPO" echo "DRY RUN=$DRY_RUN" git clone --mirror "$SOURCE_REPO" "$SOURCE_DIR" && cd "$SOURCE_DIR" git remote set-url --push origin "$DESTINATION_REPO" git fetch -p origin # Exclude refs created by GitHub for pull request. git for-each-ref --format 'delete %(refname)' refs/pull | git update-ref --stdin if [ "$DRY_RUN" = "true" ] then echo "INFO: Dry Run, no data is pushed" git push --mirror --dry-run else git push --mirror fi