-
Notifications
You must be signed in to change notification settings - Fork 105
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 19f7e7d
Showing
4 changed files
with
102 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"="Github Sync" | ||
LABEL "com.github.actions.description"="⤵️ Sync current repository with remote" | ||
LABEL "com.github.actions.icon"="git-branch" | ||
LABEL "com.github.actions.color"="black" | ||
|
||
LABEL "repository"="http://github.com/wei/github-sync" | ||
LABEL "homepage"="http://github.com/wei/github-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,51 @@ | ||
# Github Sync | ||
|
||
A GitHub Action for syncing the current repository using **force push**. | ||
|
||
|
||
## Features | ||
* Sync branches between two Github repositories | ||
* Sync branches from a remote repository | ||
* Github action can be triggered on a timer or on push | ||
* To push to a remote repository, please checkout [wei/git-sync](https://github.com/wei/git-sync) | ||
|
||
|
||
## Usage | ||
|
||
### Github Actions | ||
``` | ||
action "repo-sync" { | ||
uses = "wei/github-sync@master" | ||
args = "$SOURCE_REPO $SOURCE_BRANCH:$DESTINATION_BRANCH" | ||
secrets = ["GITHUB_TOKEN"] | ||
env = { | ||
SOURCE_REPO = "" | ||
SOURCE_BRANCH = "" | ||
DESTINATION_BRANCH = "" | ||
} | ||
} | ||
``` | ||
`GITHUB_TOKEN` must be checked under secrets. | ||
|
||
If `SOURCE_REPO` is private or with another provider, either (1) use an authenticated HTTPS repo clone url like `https://username:[email protected]/username/repository.git` or (2) set a `SSH_PRIVATE_KEY` secret and use the SSH clone url | ||
|
||
|
||
## Known Issue | ||
The job may fail if upstream has a `.workflow` file present. Consider using [git-sync](https://github.com/wei/git-sync) instead. | ||
|
||
|
||
## Advanced Usage: Sync all branches | ||
1. Make a backup | ||
2. Create a new branch in your repo (destination repo), it should not share the name with any branch in source repo | ||
3. Make the new branch the default branch under repo settings | ||
4. Use `*:*` in place of `$SOURCE_BRANCH:$DESTINATION_BRANCH` | ||
|
||
This will force sync ALL branches to match source repo. Branches that are created only in the destination repo will not be affected but all the other branches will be *hard reset* to match source repo. ⚠️ This does mean if upstream ever creates a branch that shares the name, your changes will be gone. | ||
|
||
|
||
## 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 "/github-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,19 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
UPSTREAM_REPO=$1 | ||
BRANCH_MAPPING=$2 | ||
|
||
if ! echo $UPSTREAM_REPO | grep '.git' | ||
then | ||
UPSTREAM_REPO="https://github.com/${UPSTREAM_REPO}.git" | ||
fi | ||
|
||
echo "UPSTREAM_REPO=$UPSTREAM_REPO" | ||
echo "BRANCHES=$BRANCH_MAPPING" | ||
|
||
git remote add upstream "$UPSTREAM_REPO" | ||
git fetch upstream | ||
git remote -v | ||
git push origin "refs/remotes/upstream/${BRANCH_MAPPING%%:*}:refs/heads/${BRANCH_MAPPING#*:}" -f |