├── .github
└── workflows
│ └── test.yml
├── Dockerfile
├── LICENSE.md
├── README.md
├── action.yml
└── entrypoint.sh
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: "test"
2 | on:
3 | push:
4 |
5 | jobs:
6 | test: # make sure the action works on a clean machine without building
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v2
10 | with:
11 | fetch-depth: 0
12 | - uses: ./
13 | with:
14 | ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
15 | target_repo_url: git@github.com:net-engine/github-repository-sync-action-test.git
16 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine:3.11
2 |
3 | RUN apk update && apk upgrade && \
4 | apk add --no-cache git openssh-client && \
5 | echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
6 |
7 | COPY entrypoint.sh /entrypoint.sh
8 |
9 | ENTRYPOINT ["/entrypoint.sh"]
10 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 NetEngine
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | # Git Repository Sync Action
8 |
9 | This action pushes all commits in the branch that this action is run on into any remote git repository.
10 |
11 | Check out a [sample workflow](.github/workflows/test.yml).
12 |
13 | ## Usage
14 |
15 | Be sure to run the [`actions/checkout`](https://github.com/actions/checkout) action in a step before
16 | this action so that the git repository is initialized.
17 |
18 | ```yaml
19 | # File: .github/workflows/mirror.yml
20 | - uses: net-engine/github-repository-sync-action@v1
21 | with:
22 | # The SSH private key for SSH connection to the target repository.
23 | # We strongly recommend saving this value as a GitHub Secret and using deploy
24 | # keys within the target repository
25 | ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
26 | # The SSH-based URL to the target repository
27 | target_repo_url: git@github.com:net-engine/github-repository-sync-action-test.git
28 | ```
29 |
30 | ## Notes
31 |
32 | Inspired by the following actions which may be more suitable for your workflow, e.g. syncing any
33 | source repository and branch to any destination, or copying all branches.
34 |
35 | * [wei/git-sync](https://github.com/wei/git-sync)
36 | * [pixta-dev/repository-mirroring-action](https://github.com/pixta-dev/repository-mirroring-action)
37 |
38 | ## TODO
39 |
40 | * Support for any to and from branch, similar to [actions/checkout@v2](https://github.com/actions/checkout)
41 | * Make SSH key-based authentication optional to support username/password authentication
42 | * Support for the `pull_request` [event](https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request)
43 |
44 | # License
45 |
46 | The scripts and documentation in this project are released under the [MIT License](LICENSE.md)
47 |
--------------------------------------------------------------------------------
/action.yml:
--------------------------------------------------------------------------------
1 | name: Git Repository Sync
2 | description: Sync current repository to a remote repository on GitHub, GitLab, AWS CodeCommit, etc.
3 | author: NetEngine
4 | branding:
5 | icon: upload-cloud
6 | color: blue
7 | inputs:
8 | ssh_private_key:
9 | description: SSH private key for ssh connection to the target repository
10 | required: false
11 | target_repo_url:
12 | description: Target git repository URL
13 | required: true
14 | runs:
15 | using: 'docker'
16 | image: 'Dockerfile'
17 |
--------------------------------------------------------------------------------
/entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -l
2 |
3 | # Setup SSH
4 | mkdir -p /root/.ssh
5 | echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
6 | chmod 600 /root/.ssh/id_rsa
7 |
8 | git remote add destination "$INPUT_TARGET_REPO_URL"
9 | git push destination "$GITHUB_REF:$GITHUB_REF" -f
10 |
--------------------------------------------------------------------------------