Skip to content

Commit aa45bf5

Browse files
committed
test: Added unit tests
Closes #9
1 parent e059360 commit aa45bf5

File tree

16 files changed

+692
-47
lines changed

16 files changed

+692
-47
lines changed

.circleci/config.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
docker_image: &docker_image
22
docker:
3-
- image: docker:19.03.6
3+
- image: cimg/openjdk:11.0
44
auth:
55
username: $DOCKER_USERNAME
66
password: $DOCKER_PASSWORD
@@ -19,6 +19,28 @@ executors:
1919

2020
version: 2.1
2121
jobs:
22+
test:
23+
executor: docker-executor
24+
steps:
25+
- checkout
26+
- attach_workspace:
27+
at: ~/git-sync
28+
- restore_cache:
29+
keys:
30+
- v1-dependencies-{{ checksum "build.gradle" }}
31+
- v1-dependencies-
32+
- run: |
33+
git clone --depth=1 --branch=master https://github.com/devatherock/gradle-includes.git ../gradle-includes
34+
sh unit-tests.sh
35+
- save_cache:
36+
paths:
37+
- ~/.gradle
38+
key: v1-dependencies-{{ checksum "build.gradle" }}
39+
- store_artifacts:
40+
path: build/reports/jacoco
41+
- store_test_results:
42+
path: build/test-results
43+
2244
groovy_script_to_jar:
2345
docker:
2446
- image: devatherock/drone-groovy-script-to-jar:0.6.2
@@ -70,7 +92,7 @@ jobs:
7092
- attach_workspace:
7193
at: ~/git-sync
7294
- run: |
73-
TAG=1.0.7
95+
TAG=${CIRCLE_SHA1:0:8}
7496
docker build -t devatherock/git-sync:$TAG -f docker/CircleCI.Dockerfile .
7597
docker tag devatherock/git-sync:$TAG devatherock/git-sync:latest
7698
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
@@ -84,7 +106,7 @@ jobs:
84106
- attach_workspace:
85107
at: ~/git-sync
86108
- run: |
87-
TAG=1.0.7
109+
TAG=${CIRCLE_SHA1:0:8}
88110
docker build -t devatherock/drone-git-sync:$TAG -f docker/Drone.Dockerfile .
89111
docker tag devatherock/drone-git-sync:$TAG devatherock/drone-git-sync:latest
90112
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
@@ -98,7 +120,7 @@ jobs:
98120
- attach_workspace:
99121
at: ~/git-sync
100122
- run: |
101-
TAG=1.0.7
123+
TAG=${CIRCLE_SHA1:0:8}
102124
docker build -t devatherock/vela-git-sync:$TAG -f docker/Vela.Dockerfile .
103125
docker tag devatherock/vela-git-sync:$TAG devatherock/vela-git-sync:latest
104126
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
@@ -124,12 +146,20 @@ workflows:
124146
version: 2.1
125147
build_publish:
126148
jobs:
149+
- test:
150+
context:
151+
- docker-credentials
152+
filters:
153+
branches:
154+
only: master
127155
- groovy_script_to_jar:
128156
context:
129157
- docker-credentials
130158
filters:
131159
branches:
132160
only: master
161+
requires:
162+
- test
133163
- publish_circle:
134164
context:
135165
- docker-credentials
@@ -155,12 +185,20 @@ workflows:
155185
- publish_vela
156186
pr_check:
157187
jobs:
188+
- test:
189+
context:
190+
- docker-credentials
191+
filters:
192+
branches:
193+
ignore: master
158194
- groovy_script_to_jar:
159195
context:
160196
- docker-credentials
161197
filters:
162198
branches:
163199
ignore: master
200+
requires:
201+
- test
164202
- docker_build_dry_run_circle:
165203
context:
166204
- docker-credentials

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.project
22
git-sync.iml
33
*.jar
4-
.DS_Store
4+
!gradle-wrapper.jar
5+
.DS_Store
6+
/.gradle/
7+
/build/
8+
.classpath
9+
/bin/
10+
.settings

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [Unreleased]
4+
### Changed
5+
- test([#9](https://github.com/devatherock/git-sync/issues/9)): Added unit tests
6+
37
## [1.0.7] - 2021-01-16
48
### Changed
59
- [#7](https://github.com/devatherock/git-sync/issues/7): Changed the order in which commits are applied.

DOCS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ steps:
4040
secrets: [ git_sync_token ]
4141
parameters:
4242
target_branch: prod
43+
```
44+
45+
### CircleCI
46+
To add SSH key with write access to target repository, follow these [instructions](https://circleci.com/docs/2.0/add-ssh-key/)
47+
48+
```yaml
49+
version: 2
50+
jobs:
51+
sync:
52+
docker:
53+
- image: devatherock/git-sync:latest
54+
working_directory: ~/my-source-repo
55+
environment:
56+
PLUGIN_TARGET_REPO: "[email protected]:xyz/my-target-repo.git" # Git URI of target repository. If not specified, same as the source repo
57+
PLUGIN_TARGET_BRANCH: master # Branch to sync to in target repository. Optional, defaults to master
58+
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
59+
PLUGIN_DEBUG: false # Flag to enable debug logs. Optional, by default, debug logs are disabled
60+
GIT_SYNC_TOKEN: xyz # Github API token with push access to the repository. Required if HTTP URI of target repository is used
61+
steps:
62+
- checkout
63+
- add_ssh_keys:
64+
fingerprints:
65+
- "ssh key fingerprint" # Fingerprint of SSH key with write access to target repository
66+
- run: sh /scripts/entry-point.sh
4367
```

README.md

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,31 @@
11
[![CircleCI](https://circleci.com/gh/devatherock/git-sync.svg?style=svg)](https://circleci.com/gh/devatherock/git-sync)
22
[![Version](https://img.shields.io/docker/v/devatherock/vela-git-sync?sort=date)](https://hub.docker.com/r/devatherock/vela-git-sync/)
3+
[![Coverage Status](https://coveralls.io/repos/github/devatherock/git-sync/badge.svg?branch=master)](https://coveralls.io/github/devatherock/git-sync?branch=master)
34
[![Docker Pulls](https://img.shields.io/docker/pulls/devatherock/vela-git-sync.svg)](https://hub.docker.com/r/devatherock/vela-git-sync/)
45
[![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/)
56
[![Docker Image Layers](https://img.shields.io/microbadger/layers/devatherock/vela-git-sync.svg)](https://microbadger.com/images/devatherock/vela-git-sync)
67
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
78
# git-sync
89
CI plugin to sync the contents of a git repository with another
910

10-
# Usage
11-
## CircleCI
12-
### On push
11+
## Usage
12+
### Docker
1313

14-
```yaml
15-
version: 2
16-
jobs:
17-
sync:
18-
docker:
19-
- image: devatherock/git-sync:latest
20-
working_directory: ~/my-source-repo
21-
environment:
22-
PLUGIN_TARGET_REPO: "[email protected]:xyz/my-target-repo.git" # Git URI of target repository. If not specified, same as the source repo
23-
PLUGIN_TARGET_BRANCH: master # Branch to sync to in target repository. Optional, defaults to master
24-
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
25-
PLUGIN_DEBUG: false # Flag to enable debug logs. Optional, by default, debug logs are disabled
26-
GIT_SYNC_TOKEN: xyz # Github API token with push access to the repository. Required if HTTP URI of target repository is used
27-
steps:
28-
- checkout
29-
- add_ssh_keys:
30-
fingerprints:
31-
- "ssh key fingerprint" # Fingerprint of SSH key with write access to target repository
32-
- run: sh /scripts/entry-point.sh
33-
34-
workflows:
35-
version: 2
36-
git-sync:
37-
jobs:
38-
- sync:
39-
filters:
40-
branches:
41-
only: master # Source branch
14+
```shell
15+
docker run --rm \
16+
-e PLUGIN_DEBUG=true \
17+
-e PLUGIN_START_COMMIT=29186cd \
18+
-e PLUGIN_TARGET_BRANCH=test \
19+
-v path/to/repo:/repo \
20+
-w=/repo \
21+
devatherock/drone-git-sync:latest
4222
```
4323

44-
### On tag
45-
Change `filters` section to below:
24+
### CI
25+
Please refer [docs](DOCS.md)
4626

47-
```yaml
48-
tags:
49-
only: /^v[0-9\.]+$/ # Regex to match tag pattern
27+
## Tests
28+
To test the latest plugin images, run the below command
29+
```shell
30+
sh functional-tests.sh
5031
```
51-
52-
Note: To add SSH key with write access to target repository, follow these
53-
[instructions](https://circleci.com/docs/2.0/add-ssh-key/)
54-
55-
## drone.io and vela
56-
Please refer [docs](DOCS.md)

build.gradle

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
id 'groovy'
3+
id 'jacoco'
4+
id 'com.github.kt3k.coveralls' version '2.10.2'
5+
}
6+
7+
repositories {
8+
jcenter()
9+
}
10+
11+
sourceCompatibility = '1.6'
12+
targetCompatibility = '1.6'
13+
14+
dependencies {
15+
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.5.13'
16+
17+
testImplementation group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.5'
18+
testImplementation group: 'cglib', name: 'cglib-nodep', version: '3.3.0'
19+
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.1'
20+
}
21+
22+
sourceSets {
23+
main {
24+
groovy {
25+
srcDirs = ['.']
26+
exclude(['**/test/**', 'gradle/**', 'build/**', 'docker/**', 'bin/**'])
27+
}
28+
}
29+
}
30+
31+
compileGroovy {
32+
groovyOptions.configurationScript = file('gradle/config.groovy')
33+
}
34+
35+
ext.jacoco = [
36+
exclusions: [
37+
'SyncGitRepos$_run_closure*'
38+
],
39+
coverageThresholds: [
40+
'SyncGitRepos': [
41+
'BRANCH': 0.42,
42+
'COMPLEXITY': 0.33,
43+
'INSTRUCTION': 0.61,
44+
'LINE': 0.71
45+
]
46+
]
47+
]
48+
apply from: '../gradle-includes/checks.gradle'

functional-tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cp -r . ../git-sync-test
2+
cd ../git-sync-test
3+
export CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
4+
git remote set-url origin https://git-sync-token:$GIT_TOKEN@github.com/devatherock/git-sync.git
5+
./gradlew test --tests '*SyncGitReposDockerSpec*' -x jacocoTestCoverageVerification
6+
exit_code=$?
7+
cd ../git-sync
8+
rm -rf ../git-sync-test
9+
exit $?

gradle/config.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
withConfig(configuration) {
2+
// To skip processing @Grab annotations when running unit tests
3+
configuration.setDisabledGlobalASTTransformations(['groovy.grape.GrabAnnotationTransformation'] as Set)
4+
}

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)