Skip to content

Commit

Permalink
Merge pull request #1 from net-engine/add-action-test
Browse files Browse the repository at this point in the history
Initial test and working implementation
  • Loading branch information
Martin Bjeldbak Madsen committed Feb 11, 2020
2 parents aee64c7 + bfe7822 commit 9e4e725
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
name: "build-test"
on: # rebuild any PRs and main branch changes
name: "test"
on:
pull_request:
push:
branches:
- master
- 'releases/*'

jobs:
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: ./
with:
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git
source_branch: master
target_branch: master
target_repo_url: git@github.com:net-engine/github-repository-sync-action-test.git
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM alpine:3.11

RUN apk update && apk upgrade && \
apk add --no-cache git openssh-client && \
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
<p align="center">
<a href="https://github.com/net-engine/github-action-repository-sync"><img alt="typescript-action status" src="https://github.com/net-engine/github-action-repository-sync/workflows/build-test/badge.svg"></a>
<a href="https://github.com/net-engine/github-repository-sync-action"><img alt="GitHub action build status" src="https://github.com/net-engine/github-repository-sync-action/workflows/build-test/badge.svg"></a>
</p>

# Git Repository Sync Action

A [GitHub action](https://github.com/features/actions) to push changes to a branch in a current GitHub repository to any remote repository, i.e. another GitHub, GitLab, AWS CodeCommit repository.

Check out a [sample workflow](https://github.com/net-engine/github-repository-sync-action/blob/master/.github/workflows/test.yml).

Inspired by the following actions

* [wei/git-sync](https://github.com/wei/git-sync)
* [pixta-dev/repository-mirroring-action](https://github.com/pixta-dev/repository-mirroring-action)

## Inputs

### `who-to-greet`
### `ssh_private_key`

**Required** The SSH private key for SSH connection to the target repository. We strongly recommend saving this value within [GitHub secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets).

**Required** The name of the person to greet. Default `"World"`.
### `target_repo_url`

**Required** The SSH-based URL to the target repository, e.g. `git@github.com:net-engine/github-repository-sync-action.git`

## Example usage

uses: actions/hello-world-docker-action@v1
uses: netengine/github-repository-sync-action
with:
who-to-greet: 'Mona the Octocat'

## TODO

* Support for any to and from branch, similar to [actions/checkout@v2](https://github.com/actions/checkout)
* Make SSH key-based authentication optional to support username/password authentication
13 changes: 0 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ inputs:
ssh_private_key:
description: SSH private key for ssh connection to the target repository
required: false
source_branch:
description: The branch from this repository that you want to push to the remote
required: false
default: master
target_branch:
description: The branch from the remote repository that you want to push the source_branch to
required: false
default: master
target_repo_url:
description: Target git repository URL
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.ssh_private_key }}
- ${{ inputs.source_branch }}
- ${{ inputs.target_branch }}
- ${{ inputs.target_repo_url }}
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh -l

# Setup SSH
mkdir ~/.ssh
echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
mkdir -p /root/.ssh
echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa

git remote add destination "$INPUT_TARGET_REPO_URL"
git push destination "$INPUT_SOURCE_BRANCH:$INPUT_TARGET_BRANCH" -f
git push destination "$GITHUB_REF:$GITHUB_REF" -f

0 comments on commit 9e4e725

Please sign in to comment.