Skip to content

Commit

Permalink
fix: add supported for an automating to changelog with the convention…
Browse files Browse the repository at this point in the history
…al commits (#9)
  • Loading branch information
rising3 committed Sep 4, 2021
1 parent aa48b69 commit 5223d7d
Show file tree
Hide file tree
Showing 45 changed files with 1,986 additions and 632 deletions.
295 changes: 206 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ plugins {

## New features

* Add supported for an automating generate a changelog with the ConventionalCommits. [More...](#changelog)
* Add supported for an automating versioning with the ConventionalCommits. [More...](#task-options)
* Add supported for a get current version from the latest tag. [More...](#plugin-extension)

Expand Down Expand Up @@ -64,78 +65,40 @@ version=1.0.2

> **Note:** The new version you enter must be a valid [SemVer](https://classic.yarnpkg.com/en/docs/dependency-versions#toc-semantic-versioning) version.
Added support for versioning of package.json.
## Plugin Tasks

CASE | gradle.properties | package.json
--- | --- | ---
Not exists | CREATE | -
gradle.properties exists | UPDATE | -
package.json exists | - | UPDATE
gradle.properties,<BR>package.json exists| UPDATE | UPDATE
A plugin consists of the following tasks.

## Git tags
### Latest

if you run `semver` task within a Git repository an annotated Git tag will be created by default following the format `v0.0.0`.

You can customize the git tag that is created or disable this behavior by using `semver extension`.

For example, add with this `build.gradle` file:

``` groovy
semver {
// To change the prefix of the git tag you can use versionTagPrefix:
versionTagPrefix = 'v'
// Or you can change the git message using versionGitMessage where %s is the version string:
versionGitMessage = 'v%s'
// You can even enable or disable the git tagging behavior entirely by using noGitTagVersion:
noGitTagVersion = false
// You can even enable or disable the git command behavior entirely by using noGitCommand:
noGitCommand = false
}
```
## Version lifecycle methods

The `semver` task runs based on [Gradle build lifecycle](https://docs.gradle.org/current/userguide/build_lifecycle.html).
gradle semverLatest
```
Resolve a current version from the latest FILE, or TAG.

You can use the following mechanism of Gradle to execute another task before and after executing the `semver` task.
**DependsOn:** jar

* dependsOn
* reconfigure
### Log

Executing the `semver` task overrides `project.version`, e.g. `project.version` will in the doFirst() hold the version before the version change, and in the doLast() it will hold the version after the version change.
```
gradle semverLog
```
A change log can be generated automatically. The change log can be a FILE or GHR or BOTH.

Here is an example of what a `build.gradle` file:
**DependsOn:** check, semverLatest

``` groovy
tasks.semver.dependsOn test
### Semver

tasks.semver.configure {
doFirst {
println "doFirst preversion: $project.version"
}
doLast {
println "doLast postversion: $project.version"
}
}
```

Executed `semver` task would look something like this:

gradle semver
```
info Current version: 0.1.1
question New version: (default: 0.1.1): 0.1.2

A plugin that can updating the semantic versions like `yarn version` command.
Other than that, it now supports conventional commits, so you can automate your releases.

> Task :semver
doFirst preversion: 0.1.1
info New version: 0.1.2
doLast postversion: 0.1.2
```
**DependsOn:** semverLog

## Task options
### Task options

```
gradle semver
Expand Down Expand Up @@ -199,46 +162,18 @@ The commit message should be structured as follows:

For more information, please refer to [ConventionalCommits](https://www.conventionalcommits.org/en/v1.0.0/)

## Authentication

### Push access to the remote repository

**semver-gradle-plugin**
requires push access to the project Git repository in order to create git branch or git tag .

The Git authentication can be set with one of the following environment variables:

Variables | Description
--- | ---
`GH_ACTOR` `GH_TOKEN` or `GITHUB_ACTOR` `GITHUB_TOKEN` | A GitHub [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line).
`GL_ACTOR` `GL_TOKEN` or `GITLAB_ACTOR` `GITLAB_TOKEN` | A GitLab [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html).
`BB_ACTOR` `BB_TOKEN` or `BITBUCKET_ACTOR` `BITBUCKET_TOKEN` | A Bitbucket [personal access token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html).

or the following system properties:

System properties | Description
--- | ---
`gh.actor` `gh.token` or `github.actor` `github.token` |
`gl.actor` `gl.token` or `gitlab.actor` `gitlab.token` |
`bb.actor` `bb.token` or `bitbucket.actor` `bitbucket.token` |


Here is an example of what a `gradle.properties` file:

**~/.gradle/gradle.properties**
```properties
systemProp.gh.actor=xxx
systemProp.gh.token=xxx
```
## Plugin Extension

The plugin defines an extension with the namespace `semver`. The following properties can be configured:

Property Name | Type | Default value | Description
--- | --- | --- | ---
target | String | 'file' | Choice 'FILE' or 'TAG'.
target | String | 'FILE' | Choice 'FILE' or 'TAG'.
versionTagPrefix | String | 'v' | Change the prefix of the git tag.
versionGitMessage | String | 'v%s' | Change the git message. Where %s is the version string.
changeLog | String | 'NONE' | Choice 'NONE' or FILE' or 'GITHUB' or 'BOTH'.
changeLogOrder | String[] | | Change type order.
changeLogType | String[] | | Change type title.
filename | String | 'gradle.properties' | (FILE Only)<BR>Change the filename of&nbsp;version&nbsp;property.
noGitCommand | boolean | false | (FILE Only)<BR>Even enable or disable the git command behavior entirely.
noGitInit | boolean | true | (FILE Only) <BR>Even enable or disable the git init behavior entirely.
Expand Down Expand Up @@ -286,6 +221,188 @@ semver {
noPackageJson = true
}
```
## Authentication

### Push access to the remote repository

**semver-gradle-plugin**
requires push access to the project Git repository in order to create git branch or git tag.

The Git authentication can be set with one of the following environment variables:

Variables | Description
--- | ---
`GH_ACTOR` `GH_TOKEN` or `GITHUB_ACTOR` `GITHUB_TOKEN` | A GitHub [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line).
`GL_ACTOR` `GL_TOKEN` or `GITLAB_ACTOR` `GITLAB_TOKEN` | A GitLab [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html).
`BB_ACTOR` `BB_TOKEN` or `BITBUCKET_ACTOR` `BITBUCKET_TOKEN` | A Bitbucket [personal access token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html).

or the following system properties:

System properties | Description
--- | ---
`gh.actor` `gh.token` or `github.actor` `github.token` |
`gl.actor` `gl.token` or `gitlab.actor` `gitlab.token` |
`bb.actor` `bb.token` or `bitbucket.actor` `bitbucket.token` |

Here is an example of what a `gradle.properties` file:

**~/.gradle/gradle.properties**
```properties
systemProp.gh.actor=xxx
systemProp.gh.token=xxx
```

## Changelog

A new version of the changelog can be generated automatically.
The changelog will be generated from the Git commit log of the previous release or later.

It also supports the following:
* Markdown format
* ConventionalCommits
* GitHub Releases

For example, add with this `build.gradle` file:

``` groovy
semver {
changeLog = 'FILE'
}
```
* **`NONE`**: Do nothing (default)
* **`FILE`**: Write the changelog to a file (CHANGELOG.md)
* **`GITHUB`**: Upload the changelog to GitHub Releases
* **`BOTH`**: Both `FILE` and `GITHUB`

### Change the type order

For example, add with this `build.gradle` file:

```groovy
semver {
changeLogOrder = [
'__breaking_change__',
'feat',
'fix',
]
}
```
### Change the type title

For example, add with this `build.gradle` file:

```groovy
semver {
changeLogTitle = [
build : 'Build Improvements',
chore : 'Chores',
ci : 'CI Improvements',
docs : 'Documentation',
feat : 'New Features',
fix : 'Bug Fixes',
perf : 'Performance Improvements',
refactor : 'Code Refactoring',
style : 'Styles',
test : 'Tests',
__breaking_change__: '!!! BREAKING CHANGES !!!',
__undefined__ : 'Other Changes',
]
}
```

## Git tags

if you run `semver` task within a Git repository an annotated Git tag will be created by default following the format `v0.0.0`.

You can customize the git tag that is created or disable this behavior by using `semver extension`.

For example, add with this `build.gradle` file:

``` groovy
semver {
// To change the prefix of the git tag you can use versionTagPrefix:
versionTagPrefix = 'v'
// Or you can change the git message using versionGitMessage where %s is the version string:
versionGitMessage = 'v%s'
// You can even enable or disable the git tagging behavior entirely by using noGitTagVersion:
noGitTagVersion = false
// You can even enable or disable the git command behavior entirely by using noGitCommand:
noGitCommand = false
}
```

## Supported for package.json

CASE | gradle.properties | package.json
--- | --- | ---
Not exists | CREATE | -
gradle.properties exists | UPDATE | -
package.json exists | - | UPDATE
gradle.properties,<BR>package.json exists| UPDATE | UPDATE


## Version lifecycle methods

The `semver` task runs based on [Gradle build lifecycle](https://docs.gradle.org/current/userguide/build_lifecycle.html).

You can use the following mechanism of Gradle to execute another task before and after executing the `semver` task.

* dependsOn
* reconfigure

Executing the `semver` task overrides `project.version`, e.g. `project.version` will in the doFirst() hold the version before the version change, and in the doLast() it will hold the version after the version change.

Here is an example of what a `build.gradle` file:

``` groovy
tasks.semver.dependsOn test
tasks.semver.configure {
doFirst {
println "doFirst preversion: $project.version"
}
doLast {
println "doLast postversion: $project.version"
}
}
```

Executed `semver` task would look something like this:

```
info Current version: 0.1.1
question New version: (default: 0.1.1): 0.1.2
> Task :semver
doFirst preversion: 0.1.1
info New version: 0.1.2
doLast postversion: 0.1.2
```

## Building from source

You don’t need to build from source to use `semver-gradle-plugin`, but if you want to try out the latest, `semver-gradle-plugin` can be built and published to your local Maven cache using the Gradle wrapper.

You also need following to:

* Java 11 or higher
* Gradle 7.x or higher

```
$ ./gradlew publishToMavenLocal
```

If you want to build everything, use the build task:

```
$ ./gradlew build
```

## License

Expand Down
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ repositories {
dependencies {
implementation gradleApi()
implementation localGroovy()
implementation("org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r")
implementation "org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r"
implementation "org.kohsuke:github-api:1.132"
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.13.1' // This is the last version of okhttp3 that support UrlConnection
testImplementation platform("org.spockframework:spock-bom:2.0-groovy-3.0")
testImplementation("org.spockframework:spock-core")
testImplementation("org.eclipse.jgit:org.eclipse.jgit.junit:5.12.0.202106070339-r")
testImplementation("org.mockito:mockito-core:3.+")
testImplementation("org.mockito:mockito-inline:3.+")
testImplementation "org.spockframework:spock-core"
testImplementation "org.eclipse.jgit:org.eclipse.jgit.junit:5.12.0.202106070339-r"
testImplementation "org.mockito:mockito-core:3.+"
testImplementation "org.mockito:mockito-inline:3.+"
}

gradlePlugin {
Expand Down
Loading

0 comments on commit 5223d7d

Please sign in to comment.