[
  {
    "path": ".github/workflows/versioning.yml",
    "content": "name: Keep the major version tag up-to-date\n\non:\n  release:\n    types: [published, edited]\n\nconcurrency:\n  group: ${{ github.workflow }}-${{ github.ref }}\n  cancel-in-progress: false\n\njobs:\n  update-major-tag:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: Actions-R-Us/actions-tagger@v2\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [1.0.1] - 2020-03-23\n\n### Changed\n* Exclude hidden refs created by GitHub for pull request before pushing to mirror.\n\n## [1.0.0] - 2019-11-26\n\n### Added\n* Initial release.\n\n[Unreleased]: https://github.com/wearerequired/git-mirror-action/compare/v1.0.1...HEAD\n[1.0.1]: https://github.com/wearerequired/git-mirror-action/compare/v1.0.0...v1.1.0\n[1.0.0]: https://github.com/wearerequired/git-mirror-action/compare/26c99373bfd4beb7811a3fd8a068ec944dadedcc...v1.0.0\n"
  },
  {
    "path": "Dockerfile",
    "content": "FROM alpine\n\nRUN apk add --no-cache git openssh-client\n\nADD *.sh /\n\nENTRYPOINT [\"/entrypoint.sh\"]\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2019 required gmbh\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Git Mirror Action\n\nA 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.\n\n## Inputs\n\n### `source-repo`\n\n**Required** SSH URL of the source repo.\n\n### `destination-repo`\n\n**Required** SSH URL of the destination repo.\n\n### `dry-run`\n\n**Optional** *(default: `false`)* Execute a dry run. All steps are executed, but no updates are pushed to the destination repo.\n\n## Environment variables\n\n`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.  \nStore 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.\n\n`SSH_KNOWN_HOSTS`: Known hosts as used in the `known_hosts` file. *StrictHostKeyChecking* is disabled in case the variable isn't available.\n\nIf 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.\n\n## Example workflow\n\n```yml\nname: Mirror to Bitbucket Repo\n\non: [ push, delete, create ]\n\n# Ensures that only one mirror task will run at a time.\nconcurrency:\n  group: git-mirror\n\njobs:\n  git-mirror:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: wearerequired/git-mirror-action@v1\n        env:\n          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}\n          SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}\n        with:\n          source-repo: \"git@github.com:wearerequired/git-mirror-action.git\"\n          destination-repo: \"git@bitbucket.org:wearerequired/git-mirror-action.git\"\n```\n\n## Docker\n\n```sh\ndocker run --rm -e \"SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)\" $(docker build -q .) \"$SOURCE_REPO\" \"$DESTINATION_REPO\"\n```\n\n\n## License\n\nThe Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).\n"
  },
  {
    "path": "action.yml",
    "content": "name: 'Mirror a repository using SSH'\ndescription: 'Action for mirroring a repository in another location (Bitbucket, GitHub, GitLab, …) using SSH.'\nbranding:\n  icon: 'copy'\n  color: 'orange'\ninputs:\n  source-repo:\n    description: 'SSH URL of the source repo.'\n    required: true\n    default: ''\n  destination-repo:\n    description: 'SSH URL of the destination repo.'\n    required: true\n    default: ''\n  dry-run:\n    description: 'Execute a dry run.'\n    required: false\n    default: 'false'\nruns:\n  using: 'docker'\n  image: 'Dockerfile'\n  args:\n    - ${{ inputs.source-repo }}\n    - ${{ inputs.destination-repo }}\n    - ${{ inputs.dry-run }}\n"
  },
  {
    "path": "entrypoint.sh",
    "content": "#!/bin/sh\n\nset -e\n\nif [ -n \"$SSH_PRIVATE_KEY\" ]\nthen\n  mkdir -p /root/.ssh\n  echo \"$SSH_PRIVATE_KEY\" > /root/.ssh/id_rsa\n  chmod 600 /root/.ssh/id_rsa\nfi\n\nif [ -n \"$SSH_KNOWN_HOSTS\" ]\nthen\n  mkdir -p /root/.ssh\n  echo \"StrictHostKeyChecking yes\" >> /etc/ssh/ssh_config\n  echo \"$SSH_KNOWN_HOSTS\" > /root/.ssh/known_hosts\n  chmod 600 /root/.ssh/known_hosts\nelse\n  echo \"WARNING: StrictHostKeyChecking disabled\"\n  echo \"StrictHostKeyChecking no\" >> /etc/ssh/ssh_config\nfi\n\nmkdir -p ~/.ssh\ncp /root/.ssh/* ~/.ssh/ 2> /dev/null || true\n\nsh -c \"/git-mirror.sh $*\"\n"
  },
  {
    "path": "git-mirror.sh",
    "content": "#!/bin/sh\n\nset -e\n\nSOURCE_REPO=$1\nDESTINATION_REPO=$2\nSOURCE_DIR=$(basename \"$SOURCE_REPO\")\nDRY_RUN=$3\n\nGIT_SSH_COMMAND=\"ssh -v\"\n\necho \"SOURCE=$SOURCE_REPO\"\necho \"DESTINATION=$DESTINATION_REPO\"\necho \"DRY RUN=$DRY_RUN\"\n\ngit clone --mirror \"$SOURCE_REPO\" \"$SOURCE_DIR\" && cd \"$SOURCE_DIR\"\ngit remote set-url --push origin \"$DESTINATION_REPO\"\ngit fetch -p origin\n# Exclude refs created by GitHub for pull request.\ngit for-each-ref --format 'delete %(refname)' refs/pull | git update-ref --stdin\n\nif [ \"$DRY_RUN\" = \"true\" ]\nthen\n    echo \"INFO: Dry Run, no data is pushed\"\n    git push --mirror --dry-run\nelse\n    git push --mirror\nfi\n"
  }
]