-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
204b2a0
commit f30b543
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Check if PR changelog was filled | ||
on: | ||
merge_group: | ||
pull_request: | ||
|
||
jobs: | ||
check-changelog: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- run: npm install js-yaml@4.1.0 | ||
- name: Fail if PR changelog has not been filled | ||
uses: actions/github-script@v6 | ||
id: check-changelog | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const yaml = require('js-yaml'); | ||
const prDescription = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
const changelogRegex = /# Changelog([\s\S]*?)(?=\n#[^#])/; | ||
const changelogMatch = prDescription.data.body.match(changelogRegex); | ||
const changelogContent = changelogMatch ? changelogMatch [1].trim() : ''; | ||
const yamlRegex = /```yaml([\s\S]*?)```/; | ||
const yamlMatch = changelogContent.match(yamlRegex); | ||
const yamlContent = yamlMatch ? yamlMatch[1].trim() : ''; | ||
changelog = yaml.load(yamlContent)[0] | ||
let isCompatibilityValid = false; | ||
const validCompatibilityValues = ['no-api-changes', 'compatible', 'breaking']; | ||
if (Array.isArray(data.compatibility) && !!data.compatibility) { | ||
isCompatibilityValid = data.compatibility.every(value => validCompatibilityValues.includes(value)); | ||
} else { | ||
isCompatibilityValid = validCompatibilityValues.includes(data.compatibility); | ||
} | ||
if(!isCompatibilityValid) { | ||
console.error('PR changelog has invalid compatibility! Expected one, or more of:', validCompatibilityValues) | ||
} | ||
let isTypeValid = false; | ||
const validTypeValues = ['feature', 'bugfix', 'test', 'maintenance'];; | ||
if (Array.isArray(data.type) && !!data.type) { | ||
isTypeValid = data.type.every(value => validTypeValues.includes(value)); | ||
} else { | ||
isTypeValid = validTypeValues.includes(data.compatibility); | ||
} | ||
if (!isTypeValid) { | ||
console.error('PR changelog has invalid type! Expected one, or more of:', validTypeValues) | ||
} | ||
let isDescriptionValid = true; | ||
if (changelog.description === '<insert-changelog-description-here>') { | ||
console.error('PR changelog description has not been updated!') | ||
isDescriptionValid = false; | ||
} else if (changelog.description === '') { | ||
console.error('PR changelog description field is missing!') | ||
isDescriptionValid = false; | ||
} | ||
if (!isCompatibilityValid || !isTypeValid || !isDescriptionValid) { | ||
throw 'Failed PR changelog checks!' | ||
} | ||