Skip to content

Commit

Permalink
documentation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Amesbury committed Aug 31, 2018
1 parent 1a4440f commit 4a9910c
Show file tree
Hide file tree
Showing 18 changed files with 1,108 additions and 66 deletions.
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

name: Bug report

about: \[Create a report to help us improve\]

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Provide a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org/)

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
- OS: [e.g. linux]
- Plugin Version: [0.0.6]
- Git Version [e.g. 2.16]

**Additional context**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

name: Feature request

about: \[Suggest an idea for this project\]

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# How to contribute

#### **Did you find a bug?**

* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/moonlitdoor/mld-git-version/issues).

* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/moonlitdoor/mld-git-version/issues/new).

* Use the this [Bug Report](./.github/ISSUE_TEMPLATE/bug_report.md) template to facilitate the fixing of the bug.

#### **Did you write a patch that fixes a bug?**

* Open a new GitHub pull request with the patch.

* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

#### **Did you fix whitespace, format code, or make a purely cosmetic patch?**

* Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability will generally not be accepted.

#### **Do you intend to add a new feature or change an existing one?**

* Open an issue [here](https://github.com/moonlitdoor/mld-git-version/issues/new).

* Use the this [Feature Request](./.github/ISSUE_TEMPLATE/feature_request.md) template to facilitate the request.

---

Thanks for your help!

Moonlit Door Software
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2018] [Moonlit Door Software]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
116 changes: 113 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,116 @@
mld-git-version
===============
# mld-git-version

A Gradle plugin that sets various properties available for use as the version based on the git repository.

[![Build Status](https://travis-ci.com/moonlitdoor/mld-git-version.svg?branch=master)](https://travis-ci.com/moonlitdoor/mld-git-version)

[![Travis (.com) branch](https://img.shields.io/travis/com/moonlitdoor/mld-git-version/master.svg?style=for-the-badge)](https://travis-ci.com/moonlitdoor/mld-git-version)
[![Version](https://img.shields.io/github/release/moonlitdoor/mld-git-version.svg?style=for-the-badge)](https://github.com/moonlitdoor/mld-git-version/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)


[Published to Gradle Plugins](https://plugins.gradle.org/plugin/com.moonlitdoor.git-version)

## Description

After applying the plugin, it will expose 5 properties based on the git repository:
* `gitVersion` The current version based on the most recent tag on the current git branch. Examples:
* `HEAD` is tagged as `v1.0.0` and the `git status` is clean, the value would be `v1.0.0`.
* `HEAD` is tagged as `v1.0.0` and the `git status` is not clean, the value would be `v1.0.0-1-SNAPSHOT`.
* `HEAD^` is tagged as `v1.0.0`, the `git status` is clean, and commit hash of `HEAD` is `1a4440f73d7c91b53dacc072e1eab03516477c94` the value would be `v1.0.0-1-g1a4440f7`.
* `HEAD^` is tagged as `v1.0.0`, the `git status` is not clean, and commit hash of `HEAD` is `1a4440f73d7c91b53dacc072e1eab03516477c94` the value would be `v1.0.0-2-SNAPSHOT`.
* `gitCommitCount` The number of commits on the current git branch.
* `gitTagCount` The number of tags on the current git branch.
* `gitCommitAndTagCount` The number of commits and tags on the current git branch.
* `gitBranchName` The current git branch.

## Usage

#### [Groovy](./build.groovy.gradle)

```groovy
plugins {
id "com.moonlitdoor.git-version" version "0.0.7"
}
task demo {
doLast {
println "gitVersion='$gitVersion'"
println "gitCommitCount='$gitCommitCount'"
println "gitTagCount='$gitTagCount'"
println "gitCommitAndTagCount='$gitCommitAndTagCount'"
println "gitBranchName='$gitBranchName'"
}
}
```

```
$ gradlew -b build.groovy.gradle demo
> Task :demo
gitVersion='0.0.5-5-SNAPSHOT'
gitCommitCount='17'
gitTagCount='5'
gitCommitAndTagCount='22'
gitBranchName='master-1-SNAPSHOT'
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
```

#### [Kotlin](./build.kotlin.gradle.kts)

```kotlin
plugins {
id("com.moonlitdoor.git-version") version "0.0.7"
}

tasks.register("demo") {
doLast {
println("gitVersion='$gitVersion'")
println("gitCommitCount='$gitCommitCount'")
println("gitTagCount='$gitTagCount'")
println("gitCommitAndTagCount='$gitCommitAndTagCount'")
println("gitBranchName='$gitBranchName'")
}
}
```

```
$ gradlew -b build.kotlin.gradle.kts demo
> Task :demo
gitVersion='0.0.5-5-SNAPSHOT'
gitCommitCount='17'
gitTagCount='5'
gitCommitAndTagCount='22'
gitBranchName='master-1-SNAPSHOT'
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
```

#### [Master Builds](https://jitpack.io/private#moonlitdoor/mld-git-version/master-SNAPSHOT)

```groovy
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

```groovy
dependencies {
implementation 'com.github.moonlitdoor:mld-git-version:master-SNAPSHOT'
}
```

## Issue Tracking
Want to file a bug? Want to suggest an idea? Add an [issue](https://github.com/moonlitdoor/mld-git-version/issues).

## License
All Moonlit Door Software is licensed under the [MIT License](./LICENSE).

## Contributing
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details of how to build and contribute to the project.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import java.io.OutputStream
allprojects {
group = "com.moonlitdoor.git-version"
version = getGitVersionName()
repositories {
jcenter()
}
}

fun getGitVersionName(): String {
Expand Down
13 changes: 13 additions & 0 deletions build.groovy.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id "com.moonlitdoor.git-version" version "0.0.7"
}

task demo {
doLast {
println "gitVersion='$gitVersion'"
println "gitCommitCount='$gitCommitCount'"
println "gitTagCount='$gitTagCount'"
println "gitCommitAndTagCount='$gitCommitAndTagCount'"
println "gitBranchName='$gitBranchName'"
}
}
13 changes: 13 additions & 0 deletions build.kotlin.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id("com.moonlitdoor.git-version") version "0.0.7"
}

tasks.register("demo") {
doLast {
println("gitVersion='$gitVersion'")
println("gitCommitCount='$gitCommitCount'")
println("gitTagCount='$gitTagCount'")
println("gitCommitAndTagCount='$gitCommitAndTagCount'")
println("gitBranchName='$gitBranchName'")
}
}
21 changes: 21 additions & 0 deletions build.local.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
buildscript {
repositories {
mavenLocal()
}

dependencies {
classpath "com.moonlitdoor.git-version:git-version:0.0.7-1-SNAPSHOT"
}
}

apply plugin: "com.moonlitdoor.git-version"

task demo {
doLast {
println "gitVersion='$gitVersion'"
println "gitCommitCount='$gitCommitCount'"
println "gitTagCount='$gitTagCount'"
println "gitCommitAndTagCount='$gitCommitAndTagCount'"
println "gitBranchName='$gitBranchName'"
}
}
12 changes: 10 additions & 2 deletions git-version/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ plugins {
id("com.gradle.plugin-publish") version "0.10.0"
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}

dependencies {
testImplementation("junit:junit:4.12")
}

gradlePlugin {
(plugins) {
"git-version" {
plugins {
register("git-version") {
id = "com.moonlitdoor.git-version"
implementationClass = "com.moonlitdoor.git.version.GitVersionPlugin"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moonlitdoor.git.version

import java.io.File
import java.util.concurrent.TimeUnit

open class GitFacade {

open fun runCommand(projectDir: File, vararg command: String): String {
val process = ProcessBuilder(*command)
.directory(projectDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
process.waitFor(60, TimeUnit.SECONDS)
return process.inputStream.bufferedReader().readText().trim()
}
}
Loading

0 comments on commit 4a9910c

Please sign in to comment.