Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Implementing empty changelog #3

Merged
merged 12 commits into from
Mar 28, 2021
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
# keep-changelog-maven-plugin
`CHANGELOG.md` is one of the most important files in a repository. It allows others to find out about
the most important changes in the project in short time.
To achieve this, `CHANGELOG.md` should be created be in accordance with the rules, however there is no one
standard agreed by community.

This is a maven plugin created for keep a changelog style and reduce merge request conflicts.
Another big problem with `CHANGELOG.md` is a problem with merge conflicts. Probably you, as a developer also
encounter it, when someone merged changes to `CHANGELOG.md` before you.

https://keepachangelog.com/en/1.0.0/
**To solve these problems, this maven plugin was created. It allows to keep a changelog style and reduce merge request conflicts by keeping every change
in a separate YAML file and generate `CHANGELOG.md` during release.**

https://about.gitlab.com/blog/2018/07/03/solving-gitlabs-changelog-conflict-crisis/
This plugin is also helpful to create reliable release notes during your release process.

### Reference

TODO:
The convention is maintained according to the principles set out in the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and with some additions as a result from experience in developing various types of projects.

The same problem with merge conflicts with `CHANGELOG.md` was described by GitLab. [LINK](https://about.gitlab.com/blog/2018/07/03/solving-gitlabs-changelog-conflict-crisis/)

### Example
The example project with this plugin usage you can find in `example` directory.

## Usage
### Starting
Add a plugin to your `pom.xml`. For multi-module projects with one `CHANGELOG.md` add it in main `pom.xml`.

```xml
<build>
<plugins>
<plugin>
<groupId>io.github.marwin1991</groupId>
<artifactId>keep-changelog-maven-plugin</artifactId>
<version>0.1.0</version>
</plugin>
</plugins>
</build>
```

[in-progress] Use this command from your terminal to create important directories and empty CHANGELOG.md
```shell
mvn keep-changelog:init
```

If you already had a `CHANGELOG.md` file you can move it to `changelog/archive.md` file. The name of the archive file have to start from `archive` phrase (f.e. `archive-1.0.0.md`).

After using `init` command or just creating `changelog/unreleased` directory your project is ready, and you can start adding new changelog entries by creating YAML files.

**IMPORTANT:** If you develop on two main branches like f.e 1.1.X and 1.2.X **do not** merge 1.1.X branch to 1.2.X before release otherwise YAML files will merge in one big version.
_In future there is a plan to support `unreleased*` directories names like `unreleased-1.1`_

### Adding new change
TODO

### YAML format
TODO

### Generating `CHANGELOG.md`
TODO

### `CHANGELOG.md` overview
TODO

### Releasing the version
TODO

### Archives
TODO


## TODO:
- add generating changelog directory with .gitkepp and empty changelog file, if not exists with init command
- update README to include all important aspects: first steps (add to pom.xml etc.), available commands
- move current changelog directory to example
Expand All @@ -16,11 +77,10 @@ TODO:
- add tests
- add issue to snakeyaml-anno to include specific sl4j lib
- add javadocs
- support `unreleased*` directories names like `unreleased-1.1`

Usage:
- add a directory to your project with name `changelog`
- add a directory to your `changelog` directory with name `unreleased`
- add a file to your project with name `CHANGELOG.md`



Requirements:
- set up the JAVA_HOME system variable
7 changes: 7 additions & 0 deletions changelog/unreleased/0001-example-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Added example direcotry witch contains simple springboot project with `keep-changelog` plugin
authors:
- name: Piotr
nick: marwin1991
url: https://github.com/marwin1991
type: added # [added/changed/deprecated/removed/fixed/security]

7 changes: 7 additions & 0 deletions changelog/v0.1.0/0001-generateing-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Added 'generate' maven command that generates `CHANGELOG.md` from YAML files
authors:
- name: Piotr
nick: marwin1991
url: https://github.com/marwin1991
type: added # [added/changed/deprecated/removed/fixed/security]

File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.github.marwin1991</groupId>
<artifactId>keep-changelog-maven-plugin</artifactId>
<version>0.2.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>

Expand Down
69 changes: 23 additions & 46 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<lombok.version>1.18.18</lombok.version>
<lombok-maven.version>1.18.18.0</lombok-maven.version>
<maven-plugin-api.version>3.6.3</maven-plugin-api.version>
Expand All @@ -44,7 +46,8 @@

<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>
<maven-site-plugin.version>3.8.2</maven-site-plugin.version>
<snakeyaml.version>1.26</snakeyaml.version>

<snakeyaml-anno.version>1.2.0</snakeyaml-anno.version>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -99,40 +102,10 @@
<version>${maven-project.version}</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>

<dependency>
<groupId>com.github.beosign</groupId>
<artifactId>snakeyaml-anno</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
<version>${snakeyaml-anno.version}</version>
</dependency>

<dependency>
Expand All @@ -146,7 +119,6 @@
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>

</dependencies>

<build>
Expand All @@ -166,6 +138,11 @@
</pluginManagement>

<plugins>
<plugin>
<groupId>io.github.marwin1991</groupId>
<artifactId>keep-changelog-maven-plugin</artifactId>
<version>${project.version}</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
Expand All @@ -186,19 +163,6 @@
</execution>
</executions>
</plugin>
<plugin>
marwin1991 marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -234,6 +198,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ public class GenerateChangelogMojo extends AbstractMojo {
@Parameter(defaultValue = "", property = "header")
private String header;

@Parameter(defaultValue = "changelog", property = "changelogDirectory")
private String changelogDirectoryName;
@Parameter(defaultValue = "changelog", property = "yamlFilesDirectory")
private String yamlFilesDirectory;

@Parameter(defaultValue = "CHANGELOG.md", property = "finalChangelogName")
@Parameter(defaultValue = "src/CHANGELOG.md", property = "finalChangelogName")
private String finalChangelogName;

@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Started generating " + finalChangelogName);
File changelogDirectory = findChangelogDirectory(project.getFile().getParent());

generate(changelogDirectory, finalChangelogName);

getLog().info("HELLO WORLD");
getLog().info("Generating " + finalChangelogName + " successful");
}

public void generate(File changelogDirectory, String finalChangelogName) {
Expand Down Expand Up @@ -106,17 +105,17 @@ private OffsetDateTime getReleaseDate(File version) {


private File findChangelogDirectory(String directoryPath) {
File changelogDirectory = new File(directoryPath + "/" + changelogDirectoryName);
if (!changelogDirectory.exists()) {
File changelogDir = new File(directoryPath + "/" + yamlFilesDirectory);
if (!changelogDir.exists()) {
getLog().error("There is no 'changelog' directory in this project !!!");
throw new RuntimeException("No changelog directory");
}

if (!changelogDirectory.isDirectory()) {
if (!changelogDir.isDirectory()) {
getLog().error("File 'changelog' is not a directory !!!");
throw new RuntimeException("File changelog is not a directory");
}

return changelogDirectory;
return changelogDir;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.github.marwin1991.keep_changelog;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;

@Mojo(name = "init", defaultPhase = LifecyclePhase.NONE)
public class InitProjectMojo extends AbstractMojo {

private static final String GIT_KEEP = ".gitkeep";

@Parameter(defaultValue = "CHANGELOG.md", property = "finalChangelogName")
private String finalChangelogName;

marwin1991 marked this conversation as resolved.
Show resolved Hide resolved
@Parameter(defaultValue = "changelog", property = "yamlFilesDirectory")
private String yamlFilesDirectory;

@Parameter(defaultValue = "unreleased", property = "unreleasedVersionDirectory")
private String unreleasedVersionDirectory;

@Override
public void execute() {
getLog().info("Initialize project for keep-changelog maven plugin");
generateChangelog(finalChangelogName);
generateChangelogDirUnreleasedDirGitKeep(yamlFilesDirectory + "/" + unreleasedVersionDirectory + "/");
getLog().info("Initialize project successful");
}

public void generateChangelog(String path) {

try {
File changelog = new File(path);
if (changelog.createNewFile()) {
getLog().info("Created: " + changelog.getName());
} else {
getLog().warn(changelog.getName() + " already exists.");
}
} catch (IOException e) {
getLog().error("An error occurred while creating empty changelog.");
}
}

public void generateChangelogDirUnreleasedDirGitKeep(String path) {

try {
File gitKeep = new File(path + GIT_KEEP);
if (gitKeep.createNewFile()) {
getLog().info("Created: " + gitKeep.getName());
} else {
getLog().warn(gitKeep.getName() + " already exists.");
}
} catch (IOException e) {
getLog().error("An error occurred while creating empty .gitkeep.");
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class MarkdownChangelogEntry implements Markdown {

private static final String entryFormat = "${title} ${merge_request} ${issues} ${links} ${authors}";
private static final String entryFormat = "${title} ${merge_request_format} ${issues} ${links} ${authors}";
private static final String mergeRequestFormat = "!${merge_request}";
private static final String issueFormat = "#${issue}";
private static final String authorFormat = "(${author})";
Expand All @@ -37,7 +37,7 @@ public String toString() {
private String getEntry() {
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("title", entry.getTitle());
valuesMap.put("merge_request", getMergeRequest());
valuesMap.put("merge_request_format", getMergeRequest());
valuesMap.put("issues", getIssues());
valuesMap.put("links", getLinks());
valuesMap.put("authors", getAuthors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ private List<Configuration> getConfigurations() {
List<Configuration> configurations = new LinkedList<>();

for (ChangelogEntry entry : changelogVersion.getEntries()) {
configurations.addAll(entry.getConfiguration());
if(entry.getConfiguration() != null) {
configurations.addAll(entry.getConfiguration());
}
}

Collections.sort(configurations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
public class TestGenerateChangelogMojo {

public static void main(String[] args) throws MojoFailureException, MojoExecutionException {
new GenerateChangelogMojo().generate(new File("./changelog"), "CHANGELOG.md");
marwin1991 marked this conversation as resolved.
Show resolved Hide resolved
new GenerateChangelogMojo().generate(new File("./changelog"), "src/CHANGELOG.md");
}
}