Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker_image: &docker_image
docker:
- image: docker:19.03.6
- image: cimg/openjdk:11.0
auth:
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
Expand All @@ -19,6 +19,28 @@ executors:

version: 2.1
jobs:
test:
executor: docker-executor
steps:
- checkout
- attach_workspace:
at: ~/git-sync
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
- v1-dependencies-
- run: |
git clone --depth=1 --branch=master https://github.com/devatherock/gradle-includes.git ../gradle-includes
sh unit-tests.sh
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}
- store_artifacts:
path: build/reports/jacoco
- store_test_results:
path: build/test-results

groovy_script_to_jar:
docker:
- image: devatherock/drone-groovy-script-to-jar:0.6.2
Expand Down Expand Up @@ -70,7 +92,7 @@ jobs:
- attach_workspace:
at: ~/git-sync
- run: |
TAG=1.0.7
TAG=${CIRCLE_SHA1:0:8}
docker build -t devatherock/git-sync:$TAG -f docker/CircleCI.Dockerfile .
docker tag devatherock/git-sync:$TAG devatherock/git-sync:latest
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
Expand All @@ -84,7 +106,7 @@ jobs:
- attach_workspace:
at: ~/git-sync
- run: |
TAG=1.0.7
TAG=${CIRCLE_SHA1:0:8}
docker build -t devatherock/drone-git-sync:$TAG -f docker/Drone.Dockerfile .
docker tag devatherock/drone-git-sync:$TAG devatherock/drone-git-sync:latest
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
Expand All @@ -98,7 +120,7 @@ jobs:
- attach_workspace:
at: ~/git-sync
- run: |
TAG=1.0.7
TAG=${CIRCLE_SHA1:0:8}
docker build -t devatherock/vela-git-sync:$TAG -f docker/Vela.Dockerfile .
docker tag devatherock/vela-git-sync:$TAG devatherock/vela-git-sync:latest
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
Expand All @@ -124,12 +146,20 @@ workflows:
version: 2.1
build_publish:
jobs:
- test:
context:
- docker-credentials
filters:
branches:
only: master
- groovy_script_to_jar:
context:
- docker-credentials
filters:
branches:
only: master
requires:
- test
- publish_circle:
context:
- docker-credentials
Expand All @@ -155,12 +185,20 @@ workflows:
- publish_vela
pr_check:
jobs:
- test:
context:
- docker-credentials
filters:
branches:
ignore: master
- groovy_script_to_jar:
context:
- docker-credentials
filters:
branches:
ignore: master
requires:
- test
- docker_build_dry_run_circle:
context:
- docker-credentials
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.project
git-sync.iml
*.jar
.DS_Store
!gradle-wrapper.jar
.DS_Store
/.gradle/
/build/
.classpath
/bin/
.settings
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]
### Changed
- test([#9](https://github.com/devatherock/git-sync/issues/9)): Added unit tests

## [1.0.7] - 2021-01-16
### Changed
- [#7](https://github.com/devatherock/git-sync/issues/7): Changed the order in which commits are applied.
Expand Down
24 changes: 24 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,28 @@ steps:
secrets: [ git_sync_token ]
parameters:
target_branch: prod
```

### CircleCI
To add SSH key with write access to target repository, follow these [instructions](https://circleci.com/docs/2.0/add-ssh-key/)

```yaml
version: 2
jobs:
sync:
docker:
- image: devatherock/git-sync:latest
working_directory: ~/my-source-repo
environment:
PLUGIN_TARGET_REPO: "[email protected]:xyz/my-target-repo.git" # Git URI of target repository. If not specified, same as the source repo
PLUGIN_TARGET_BRANCH: master # Branch to sync to in target repository. Optional, defaults to master
PLUGIN_START_COMMIT: 29186cd # Commit sha of the first commit to sync. All commits after that will be synced. If not specified, commit sha of the penultimate tag will be used. And if no tags are present, all commits up to the 100th will be synced
PLUGIN_DEBUG: false # Flag to enable debug logs. Optional, by default, debug logs are disabled
GIT_SYNC_TOKEN: xyz # Github API token with push access to the repository. Required if HTTP URI of target repository is used
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "ssh key fingerprint" # Fingerprint of SSH key with write access to target repository
- run: sh /scripts/entry-point.sh
```
59 changes: 17 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,31 @@
[![CircleCI](https://circleci.com/gh/devatherock/git-sync.svg?style=svg)](https://circleci.com/gh/devatherock/git-sync)
[![Version](https://img.shields.io/docker/v/devatherock/vela-git-sync?sort=date)](https://hub.docker.com/r/devatherock/vela-git-sync/)
[![Coverage Status](https://coveralls.io/repos/github/devatherock/git-sync/badge.svg?branch=master)](https://coveralls.io/github/devatherock/git-sync?branch=master)
[![Docker Pulls](https://img.shields.io/docker/pulls/devatherock/vela-git-sync.svg)](https://hub.docker.com/r/devatherock/vela-git-sync/)
[![Docker Image Size](https://img.shields.io/docker/image-size/devatherock/vela-git-sync.svg?sort=date)](https://hub.docker.com/r/devatherock/vela-git-sync/)
[![Docker Image Layers](https://img.shields.io/microbadger/layers/devatherock/vela-git-sync.svg)](https://microbadger.com/images/devatherock/vela-git-sync)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
# git-sync
CI plugin to sync the contents of a git repository with another

# Usage
## CircleCI
### On push
## Usage
### Docker

```yaml
version: 2
jobs:
sync:
docker:
- image: devatherock/git-sync:latest
working_directory: ~/my-source-repo
environment:
PLUGIN_TARGET_REPO: "[email protected]:xyz/my-target-repo.git" # Git URI of target repository. If not specified, same as the source repo
PLUGIN_TARGET_BRANCH: master # Branch to sync to in target repository. Optional, defaults to master
PLUGIN_START_COMMIT: 29186cd # Commit sha of the first commit to sync. All commits after that will be synced. If not specified, commit sha of the penultimate tag will be used. And if no tags are present, all commits up to the 100th will be synced
PLUGIN_DEBUG: false # Flag to enable debug logs. Optional, by default, debug logs are disabled
GIT_SYNC_TOKEN: xyz # Github API token with push access to the repository. Required if HTTP URI of target repository is used
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "ssh key fingerprint" # Fingerprint of SSH key with write access to target repository
- run: sh /scripts/entry-point.sh

workflows:
version: 2
git-sync:
jobs:
- sync:
filters:
branches:
only: master # Source branch
```shell
docker run --rm \
-e PLUGIN_DEBUG=true \
-e PLUGIN_START_COMMIT=29186cd \
-e PLUGIN_TARGET_BRANCH=test \
-v path/to/repo:/repo \
-w=/repo \
devatherock/drone-git-sync:latest
```

### On tag
Change `filters` section to below:
### CI
Please refer [docs](DOCS.md)

```yaml
tags:
only: /^v[0-9\.]+$/ # Regex to match tag pattern
## Tests
To test the latest plugin images, run the below command
```shell
sh functional-tests.sh
```

Note: To add SSH key with write access to target repository, follow these
[instructions](https://circleci.com/docs/2.0/add-ssh-key/)

## drone.io and vela
Please refer [docs](DOCS.md)
48 changes: 48 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'groovy'
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.10.2'
}

repositories {
jcenter()
}

sourceCompatibility = '1.6'
targetCompatibility = '1.6'

dependencies {
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.5.13'

testImplementation group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5'
testImplementation group: 'cglib', name: 'cglib-nodep', version: '3.3.0'
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.1'
}

sourceSets {
main {
groovy {
srcDirs = ['.']
exclude(['**/test/**', 'gradle/**', 'build/**', 'docker/**', 'bin/**'])
}
}
}

compileGroovy {
groovyOptions.configurationScript = file('gradle/config.groovy')
}

ext.jacoco = [
exclusions: [
'SyncGitRepos$_run_closure*'
],
coverageThresholds: [
'SyncGitRepos': [
'BRANCH': 0.42,
'COMPLEXITY': 0.33,
'INSTRUCTION': 0.61,
'LINE': 0.71
]
]
]
apply from: '../gradle-includes/checks.gradle'
9 changes: 9 additions & 0 deletions functional-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cp -r . ../git-sync-test
cd ../git-sync-test
export CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
git remote set-url origin https://git-sync-token:[email protected]/devatherock/git-sync.git
./gradlew test --tests '*SyncGitReposDockerSpec*' -x jacocoTestCoverageVerification
exit_code=$?
cd ../git-sync
rm -rf ../git-sync-test
exit $?
4 changes: 4 additions & 0 deletions gradle/config.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
withConfig(configuration) {
// To skip processing @Grab annotations when running unit tests
configuration.setDisabledGlobalASTTransformations(['groovy.grape.GrabAnnotationTransformation'] as Set)
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading