-
Notifications
You must be signed in to change notification settings - Fork 4
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 f4e89a1
Showing
8 changed files
with
796 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 @@ | ||
.DS_Store |
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,11 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.0.0] - 2021-03-16 | ||
|
||
### Added | ||
* Initial release. |
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,8 @@ | ||
FROM alpine | ||
|
||
RUN apk add --no-cache git openssh-client && \ | ||
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config | ||
|
||
ADD *.sh / | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
# Sync Git Branch Action | ||
|
||
A GitHub Action for synchronizing a git branch to another location via SSH. | ||
|
||
## Inputs | ||
|
||
| Name | Description | Default | Required | | ||
| -------------------- | ----------------------------------------- | ----------------------------------- | -------- | | ||
| `source-branch` | Branch name in the source repository | | Yes | | ||
| `destination-repo` | SSH URL of the destination repository | | Yes | | ||
| `source-repo` | SSH URL of the source repository | The respository this action runs in | No | | ||
| `destination-branch` | Branch name in the destination repository | Same as `source-branch` | No | | ||
|
||
## Environment variables | ||
|
||
`SSH_PRIVATE_KEY`: Create a [SSH key](https://help.github.com/en/github/authenticating-to-github/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 should add the public key to repository "deploy keys". | ||
|
||
Store [the private key as a secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) and use it in your workflow as seen in the example usage below. | ||
|
||
## Example workflow | ||
|
||
```yml | ||
name: Sync main branch to Bitbucket | ||
|
||
on: [push, delete, create] | ||
|
||
jobs: | ||
git-mirror: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: zent-contrib/git-branch-sync-action@v1 | ||
env: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
with: | ||
source-branch: main | ||
destination-repo: "git@bitbucket.org:<org>/<repo>.git" | ||
``` |
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,30 @@ | ||
name: "Sync Git Branch Action" | ||
description: "Action for synchronizing a git branch to another location (Bitbucket, GitHub, GitLab, etc.) using SSH." | ||
branding: | ||
icon: "copy" | ||
color: "#155bd4" | ||
inputs: | ||
source-repo: | ||
description: "SSH URL of the source repository. Defaults to the repository this actions runs in." | ||
required: false | ||
default: 'git@github.com:${{ github.repository }}.git' | ||
source-branch: | ||
description: "Branch name in source repository." | ||
required: true | ||
default: "" | ||
destination-repo: | ||
description: "SSH URL of the destination repository." | ||
required: true | ||
default: "" | ||
destination-branch: | ||
description: "Branch name in destination repository. Defaults to source-branch if not present." | ||
required: false | ||
default: "" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
args: | ||
- ${{ inputs.source-repo }} | ||
- ${{ inputs.source-branch }} | ||
- ${{ inputs.destination-repo }} | ||
- ${{ inputs.destination-branch }} |
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 "/sync-git-branch.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,18 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
SOURCE_REPO="$1" | ||
SOURCE_BRANCH="$2" | ||
DESTINATION_REPO="$3" | ||
DESTINATION_BRANCH="${4:-$2}" | ||
REPO_DIR="repo" | ||
|
||
echo "SOURCE=$SOURCE_REPO:$SOURCE_BRANCH" | ||
echo "DESTINATION=$DESTINATION_REPO:$DESTINATION_BRANCH" | ||
|
||
# Only clone the branch we want to sync | ||
git clone --single-branch --branch "$SOURCE_BRANCH" "$SOURCE_REPO" "$REPO_DIR" | ||
cd "$REPO_DIR" | ||
git remote add mirror "$DESTINATION_REPO" | ||
git push mirror "$SOURCE_BRANCH:$DESTINATION_BRANCH" |