-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f90c2d1
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM alpine | ||
|
||
LABEL "com.github.actions.name"="Git Sync Action" | ||
LABEL "com.github.actions.description"="🔃 Sync between two independent repositories" | ||
LABEL "com.github.actions.icon"="git-branch" | ||
LABEL "com.github.actions.color"="black" | ||
|
||
LABEL "repository"="http://github.com/wei/git-sync" | ||
LABEL "homepage"="http://github.com/wei/git-sync" | ||
LABEL "maintainer"="Wei He <[email protected]>" | ||
|
||
RUN apk add --no-cache git openssh-client && \ | ||
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config | ||
|
||
ADD *.sh / | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Git Sync | ||
|
||
A GitHub Action for syncing between two independent repositories using **force push**. | ||
|
||
|
||
## Features | ||
* Sync branches between two Github repositories | ||
* Sync branches to/from a remote repository | ||
* Github action can be triggered on a timer or on push | ||
|
||
|
||
## Usage | ||
|
||
### Github Actions | ||
``` | ||
action "repo-sync" { | ||
uses = "wei/git-sync@master" | ||
args = "$SOURCE_REPO $SOURCE_BRANCH $DESTINATION_REPO $DESTINATION_BRANCH" | ||
env = { | ||
SOURCE_REPO = "" | ||
SOURCE_BRANCH = "" | ||
DESTINATION_REPO = "" | ||
DESTINATION_BRANCH = "" | ||
} | ||
secrets = ["SSH_PRIVATE_KEY"] | ||
} | ||
``` | ||
`SSH_PRIVATE_KEY` can be omitted if using authenticated HTTPS repo clone urls like `https://username:[email protected]/username/repository.git`. | ||
|
||
### Docker | ||
``` | ||
docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) \ | ||
$SOURCE_REPO $SOURCE_BRANCH $DESTINATION_REPO $DESTINATION_BRANCH | ||
``` | ||
|
||
## Author | ||
[Wei He](https://github.com/wei) _[email protected]_ | ||
|
||
|
||
## License | ||
[MIT](https://wei.mit-license.org) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/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 | ||
|
||
mkdir -p ~/.ssh | ||
cp /root/.ssh/* ~/.ssh/ 2> /dev/null || true | ||
|
||
sh -c "/git-sync.sh $*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
SOURCE_REPO=$1 | ||
SOURCE_BRANCH=$2 | ||
DESTINATION_REPO=$3 | ||
DESTINATION_BRANCH=$4 | ||
|
||
if ! echo $SOURCE_REPO | grep '.git' | ||
then | ||
if [[ -n "$SSH_PRIVATE_KEY" ]] | ||
then | ||
SOURCE_REPO="[email protected]:${SOURCE_REPO}.git" | ||
GIT_SSH_COMMAND="ssh -v" | ||
else | ||
SOURCE_REPO="https://github.com/${SOURCE_REPO}.git" | ||
fi | ||
fi | ||
if ! echo $DESTINATION_REPO | grep '.git' | ||
then | ||
if [[ -n "$SSH_PRIVATE_KEY" ]] | ||
then | ||
DESTINATION_REPO="[email protected]:${DESTINATION_REPO}.git" | ||
GIT_SSH_COMMAND="ssh -v" | ||
else | ||
DESTINATION_REPO="https://github.com/${DESTINATION_REPO}.git" | ||
fi | ||
fi | ||
|
||
echo "SOURCE=$SOURCE_REPO:$SOURCE_BRANCH" | ||
echo "DESTINATION=$DESTINATION_REPO:$DESTINATION_BRANCH" | ||
|
||
git clone "$SOURCE_REPO" --origin source && cd `basename "$SOURCE_REPO" .git` | ||
git checkout "$SOURCE_BRANCH" | ||
git show --name-status | ||
git remote add destination "$DESTINATION_REPO" | ||
git remote -v | ||
git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f |