File tree Expand file tree Collapse file tree 4 files changed +112
-0
lines changed Expand file tree Collapse file tree 4 files changed +112
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM alpine
2+
3+ LABEL "com.github.actions.name" ="Git Sync Action"
4+ LABEL "com.github.actions.description" ="🔃 Sync between two independent repositories"
5+ LABEL "com.github.actions.icon" ="git-branch"
6+ LABEL "com.github.actions.color" ="black"
7+
8+ LABEL "repository" ="http://github.com/wei/git-sync"
9+ LABEL "homepage" ="http://github.com/wei/git-sync"
10+ LABEL "maintainer" ="Wei He <github@weispot.com>"
11+
12+ RUN apk add --no-cache git openssh-client && \
13+ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
14+
15+ ADD *.sh /
16+
17+ ENTRYPOINT ["/entrypoint.sh" ]
Original file line number Diff line number Diff line change 1+ # Git Sync
2+
3+ A GitHub Action for syncing between two independent repositories using ** force push** .
4+
5+
6+ ## Features
7+ * Sync branches between two Github repositories
8+ * Sync branches to/from a remote repository
9+ * Github action can be triggered on a timer or on push
10+
11+
12+ ## Usage
13+
14+ ### Github Actions
15+ ```
16+ action "repo-sync" {
17+ uses = "wei/git-sync@master"
18+ args = "$SOURCE_REPO $SOURCE_BRANCH $DESTINATION_REPO $DESTINATION_BRANCH"
19+ env = {
20+ SOURCE_REPO = ""
21+ SOURCE_BRANCH = ""
22+ DESTINATION_REPO = ""
23+ DESTINATION_BRANCH = ""
24+ }
25+ secrets = ["SSH_PRIVATE_KEY"]
26+ }
27+ ```
28+ ` SSH_PRIVATE_KEY ` can be omitted if using authenticated HTTPS repo clone urls like ` https://username:access_token@github.com/username/repository.git ` .
29+
30+ ### Docker
31+ ```
32+ docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) \
33+ $SOURCE_REPO $SOURCE_BRANCH $DESTINATION_REPO $DESTINATION_BRANCH
34+ ```
35+
36+ ## Author
37+ [ Wei He] ( https://github.com/wei ) _ github@weispot.com _
38+
39+
40+ ## License
41+ [ MIT] ( https://wei.mit-license.org )
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ set -e
4+
5+ if [[ -n " $SSH_PRIVATE_KEY " ]]
6+ then
7+ mkdir -p /root/.ssh
8+ echo " $SSH_PRIVATE_KEY " > /root/.ssh/id_rsa
9+ chmod 600 /root/.ssh/id_rsa
10+ fi
11+
12+ mkdir -p ~ /.ssh
13+ cp /root/.ssh/* ~ /.ssh/ 2> /dev/null || true
14+
15+ sh -c " /git-sync.sh $* "
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ set -e
4+
5+ SOURCE_REPO=$1
6+ SOURCE_BRANCH=$2
7+ DESTINATION_REPO=$3
8+ DESTINATION_BRANCH=$4
9+
10+ if ! echo $SOURCE_REPO | grep ' .git'
11+ then
12+ if [[ -n " $SSH_PRIVATE_KEY " ]]
13+ then
14+ SOURCE_REPO=" git@github.com:${SOURCE_REPO} .git"
15+ GIT_SSH_COMMAND=" ssh -v"
16+ else
17+ SOURCE_REPO=" https://github.com/${SOURCE_REPO} .git"
18+ fi
19+ fi
20+ if ! echo $DESTINATION_REPO | grep ' .git'
21+ then
22+ if [[ -n " $SSH_PRIVATE_KEY " ]]
23+ then
24+ DESTINATION_REPO=" git@github.com:${DESTINATION_REPO} .git"
25+ GIT_SSH_COMMAND=" ssh -v"
26+ else
27+ DESTINATION_REPO=" https://github.com/${DESTINATION_REPO} .git"
28+ fi
29+ fi
30+
31+ echo " SOURCE=$SOURCE_REPO :$SOURCE_BRANCH "
32+ echo " DESTINATION=$DESTINATION_REPO :$DESTINATION_BRANCH "
33+
34+ git clone " $SOURCE_REPO " --origin source && cd ` basename " $SOURCE_REPO " .git`
35+ git checkout " $SOURCE_BRANCH "
36+ git show --name-status
37+ git remote add destination " $DESTINATION_REPO "
38+ git remote -v
39+ git push destination " ${SOURCE_BRANCH} :${DESTINATION_BRANCH} " -f
You can’t perform that action at this time.
0 commit comments