diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5662ff7d..4de70c6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
# CHANGELOG
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
+## [v3.2.1]
+### Changed
+- `expectedLatestVersion` no longer enforces validation if the only version in the changelog is an unreleased version.
+ - See more in the [README](./README.md#expectedlatestversion)
+
## [v3.2.0]
### Changed
- Now runs on Node 16
diff --git a/README.md b/README.md
index a04a781a..a60f4249 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Below are the properties allowed by the Changelog Enforcer. These properties are
#### `expectedLatestVersion`
* Default: `''`
-* The latest version of the software expected in the changelog. Should be in the form of `v1.1.0`, `v3.5.6` etc.
+* The latest version of the software expected in the changelog. Should be in the form of `v1.1.0`, `v3.5.6` etc. Allows for the first version in the changelog to be an unreleased version (either `unreleased|Unreleased|UNRELEASED`) before checking versions. If the only version in the changelog is an unreleased version, no validation occurs. This is to support a repository adding a changelog after other versions have been released and don't want to backport previous versions (though doing so is recommended).
#### `versionPattern`
* Default: `'## \\[((v|V)?\\d*\\.\\d*\\.\\d*-?\\w*|unreleased|Unreleased|UNRELEASED)\\]'`
diff --git a/__tests__/changelog-enforcer.test.js b/__tests__/changelog-enforcer.test.js
index 64ea89b6..1c9c7596 100644
--- a/__tests__/changelog-enforcer.test.js
+++ b/__tests__/changelog-enforcer.test.js
@@ -191,4 +191,41 @@ describe('the changelog-enforcer', () => {
done()
})
})
+
+ it('should enforce when label is not present; changelog is changed; only one unreleased version exists', (done) => {
+ const contentsUrl = 'some-url'
+ inputs['skipLabels'] = 'A different label'
+ inputs['expectedLatestVersion'] = 'v2.0.0'
+
+ const files = [
+ {
+ "filename": "CHANGELOG.md",
+ "status": "modified",
+ "contents_url": contentsUrl
+ }
+ ]
+
+ const changelog =
+ `## [Unreleased]
+ - Changelog
+`
+
+ fetch.mockImplementation((url, options) => {
+ if (url === contentsUrl) {
+ return Promise.resolve(new Response(changelog))
+ }
+ return prepareResponse(JSON.stringify(files))
+ })
+
+ changelogEnforcer.enforce()
+ .then(() => {
+ expect(infoSpy).toHaveBeenCalledTimes(5)
+ expect(failureSpy).not.toHaveBeenCalled()
+ expect(outputSpy).not.toHaveBeenCalled()
+
+ expect(fetch).toHaveBeenCalledTimes(2)
+
+ done()
+ })
+ })
})
\ No newline at end of file
diff --git a/coverage/badge.svg b/coverage/badge.svg
index 367f1bd7..f9d5e0b0 100644
--- a/coverage/badge.svg
+++ b/coverage/badge.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index 4b5a9988..fc295b49 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -9088,6 +9088,10 @@ async function validateLatestVersion(token, expectedLatestVersion, versionPatter
let latest = versions[0]
core.debug(`Latest version is ${latest}`)
if (latest.toUpperCase() == "UNRELEASED") {
+ if (versions.length == 1) {
+ core.debug('There is only on unreleased version found in the changelog. Not validating expected version.')
+ return
+ }
latest = versions[1]
}
if (latest !== expectedLatestVersion) {
diff --git a/package-lock.json b/package-lock.json
index a9b69032..870ac5d9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "changelog-enforcer",
- "version": "3.2.0",
+ "version": "3.2.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "changelog-enforcer",
- "version": "3.2.0",
+ "version": "3.2.1",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.6.0",
diff --git a/package.json b/package.json
index 160a01c0..f83b49e2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "changelog-enforcer",
- "version": "3.2.0",
+ "version": "3.2.1",
"description": "Enforces that a changelog is kept up-to-date",
"main": "index.js",
"scripts": {
diff --git a/src/changelog-enforcer.js b/src/changelog-enforcer.js
index 2dd8a94e..f098da2b 100644
--- a/src/changelog-enforcer.js
+++ b/src/changelog-enforcer.js
@@ -104,6 +104,10 @@ async function validateLatestVersion(token, expectedLatestVersion, versionPatter
let latest = versions[0]
core.debug(`Latest version is ${latest}`)
if (latest.toUpperCase() == "UNRELEASED") {
+ if (versions.length == 1) {
+ core.debug('There is only on unreleased version found in the changelog. Not validating expected version.')
+ return
+ }
latest = versions[1]
}
if (latest !== expectedLatestVersion) {