Skip to content

Commit

Permalink
v3.2.1 (#209)
Browse files Browse the repository at this point in the history
* Support unreleased only changelogs
  • Loading branch information
dangoslen authored Jul 18, 2022
1 parent 4c246b1 commit 83e1e99
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)\\]'`
Expand Down
37 changes: 37 additions & 0 deletions __tests__/changelog-enforcer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
2 changes: 1 addition & 1 deletion coverage/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions src/changelog-enforcer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 83e1e99

Please sign in to comment.