Skip to content

Commit fc3d076

Browse files
committed
Merge branch 'release/4.1.0'
2 parents 436f49f + bfefc31 commit fc3d076

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [4.1.0](https://github.com/cloudogu/ces-build-lib/releases/tag/4.1.0) - 2025-02-19
12+
### Added
13+
- Add checkChangelog function to make sure your changelog has been updated on an open PR
14+
- Add checkReleaseNotes function to make sure your release notes have been updated on an open PR
15+
1116
## [4.0.1](https://github.com/cloudogu/ces-build-lib/releases/tag/4.0.1) - 2025-01-07
1217
### Fixed
1318
- Archive Trivy scan artifacts correctly

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Jenkins Pipeline Shared library, that contains additional features for Git, Mave
7575
- [findEmailRecipients](#findemailrecipients)
7676
- [findHostName](#findhostname)
7777
- [isBuildSuccessful](#isbuildsuccessful)
78+
- [checkChangelog](#checkchangelog)
79+
- [checkReleaseNotes](#checkreleasenotes)
7880
- [findVulnerabilitiesWithTrivy](#findvulnerabilitieswithtrivy)
7981
- [Simple examples](#simple-examples)
8082
- [Ignore / allowlist](#ignore--allowlist)
@@ -1467,6 +1469,30 @@ For example, if running on `http(s)://server:port/jenkins`, `server` is returned
14671469

14681470
Returns true if the build is successful, i.e. not failed or unstable (yet).
14691471

1472+
## checkChangelog
1473+
1474+
Automatically check if your changelog has been updated if a PR is created.
1475+
If the changelog has not been updated, the build will become unstable.
1476+
1477+
Usage:
1478+
1479+
```groovy
1480+
Changelog changelog = new Changelog(this)
1481+
checkChangelog(changelog)
1482+
```
1483+
1484+
## checkReleaseNotes
1485+
1486+
Automatically check if your release notes have been updated if a PR is created.
1487+
If the release notes have not been updated, the build will become unstable.
1488+
1489+
Usage:
1490+
1491+
```groovy
1492+
ReleaseNotes releaseNotes = new ReleaseNotes(this)
1493+
checkReleaseNotes(releaseNotes)
1494+
```
1495+
14701496
## findVulnerabilitiesWithTrivy (Deprecated)
14711497

14721498
This function is deprecated. Use [Trivy](#trivy) functionality instead.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<groupId>com.cloudogu.ces</groupId>
2020
<artifactId>ces-build-lib</artifactId>
2121
<name>ces-build-lib</name>
22-
<version>4.0.1</version>
22+
<version>4.1.0</version>
2323

2424

2525
<properties>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.cloudogu.ces.cesbuildlib
2+
3+
/**
4+
* Enables interaction with release notes files
5+
*/
6+
class ReleaseNotes implements Serializable {
7+
private script
8+
private String releaseNotesFileNameDE
9+
private String releaseNotesFileNameEN
10+
11+
ReleaseNotes(script) {
12+
this(script, 'docs/gui/release_notes_de.md', 'docs/gui/release_notes_en.md')
13+
}
14+
15+
ReleaseNotes(script, releaseNotesFileNameDE, releaseNotesFileNameEN) {
16+
this.script = script
17+
this.releaseNotesFileNameDE = releaseNotesFileNameDE
18+
this.releaseNotesFileNameEN = releaseNotesFileNameEN
19+
}
20+
21+
/**
22+
* @return Returns the content of german release notes file.
23+
*/
24+
private String readReleaseNotesDE(){
25+
script.readFile releaseNotesFileNameDE
26+
}
27+
28+
/**
29+
* @return Returns the content of english release notes file.
30+
*/
31+
private String readReleaseNotesEN(){
32+
script.readFile releaseNotesFileNameEN
33+
}
34+
35+
/**
36+
* Extracts the changes for a given version out of the german release notes.
37+
*
38+
* @param releaseVersion The version to get the changes for.
39+
* @return Returns the changes as String.
40+
*/
41+
String changesForDEVersion(String releaseVersion) {
42+
def releaseNotesDE = readReleaseNotesDE()
43+
def start = changesStartIndex(releaseNotesDE, releaseVersion)
44+
def end = changesEndIndex(releaseNotesDE, start)
45+
return escapeForJson(releaseNotesDE.substring(start, end).trim())
46+
}
47+
48+
/**
49+
* Extracts the changes for a given version out of the english release notes.
50+
*
51+
* @param releaseVersion The version to get the changes for.
52+
* @return Returns the changes as String.
53+
*/
54+
String changesForENVersion(String releaseVersion) {
55+
def releaseNotesEN = readReleaseNotesEN()
56+
def start = changesStartIndex(releaseNotesEN, releaseVersion)
57+
def end = changesEndIndex(releaseNotesEN, start)
58+
return escapeForJson(releaseNotesEN.substring(start, end).trim())
59+
}
60+
61+
/**
62+
* Removes characters from a string that could break the json struct when passing the string as json value.
63+
*
64+
* @param string The string to format.
65+
* @return Returns the formatted string.
66+
*/
67+
private static String escapeForJson(String string) {
68+
return string
69+
.replace("\"", "")
70+
.replace("'", "")
71+
.replace("\\", "")
72+
.replace("\n", "\\n")
73+
}
74+
75+
/**
76+
* Returns the start index of changes of a specific release version in the release notes.
77+
*
78+
* @param releaseVersion The version to get the changes for.
79+
* @return Returns the index in the release notes string where the changes start.
80+
*/
81+
private static int changesStartIndex(String releaseNotes, String releaseVersion) {
82+
def index = releaseNotes.indexOf("## [${releaseVersion}]")
83+
if (index == -1){
84+
throw new IllegalArgumentException("The desired version '${releaseVersion}' could not be found in the release notes.")
85+
}
86+
def offset = releaseNotes.substring(index).indexOf("\n")
87+
return index + offset
88+
}
89+
90+
/**
91+
* Returns the end index of changes of a specific release version in the release notes.
92+
*
93+
* @param start The start index of the changes for this version.
94+
* @return Returns the index in the release notes string where the changes end.
95+
*/
96+
private static int changesEndIndex(String releaseNotes, int start) {
97+
def releaseNotesAfterStartIndex = releaseNotes.substring(start)
98+
def index = releaseNotesAfterStartIndex.indexOf("\n## [")
99+
if (index == -1) {
100+
return releaseNotes.length()
101+
}
102+
return index + start
103+
}
104+
}

vars/checkChangelog.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.cloudogu.ces.cesbuildlib
2+
3+
def call(Changelog changelog = new Changelog(this)) {
4+
// Checking if this is associated with a pull request
5+
if (env.CHANGE_TARGET) {
6+
echo "Checking changelog..."
7+
String newChanges = changelog.changesForVersion('Unreleased')
8+
if (!newChanges || newChanges.allWhitespace) {
9+
unstable('CHANGELOG.md should contain new change entries in the `[Unreleased]` section but none were found.')
10+
}
11+
}
12+
}

vars/checkReleaseNotes.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.cloudogu.ces.cesbuildlib
2+
3+
def call(ReleaseNotes releaseNotes = new ReleaseNotes(this)) {
4+
// Checking if this is associated with a pull request
5+
if (env.CHANGE_TARGET) {
6+
echo "Checking release notes..."
7+
String newChangesReleaseNotesDE = releaseNotes.changesForDEVersion("Unreleased")
8+
if (!newChangesReleaseNotesDE || newChangesReleaseNotesDE.allWhitespace) {
9+
unstable('Release Notes should contain new change entries in the `[Unreleased]` section but none were found in the german version')
10+
}
11+
String newChangesReleaseNotesEN = releaseNotes.changesForENVersion("Unreleased")
12+
if (!newChangesReleaseNotesEN || newChangesReleaseNotesEN.allWhitespace) {
13+
unstable('Release Notes should contain new change entries in the `[Unreleased]` section but none were found in the english version')
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)