-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add changelog generation script #4386
Closed
BSFishy
wants to merge
3
commits into
opensearch-project:main
from
BSFishy:changesets/generate_changelog
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@ | ||
fix: | ||
- This is a sample fixed | ||
|
||
feat: | ||
- Introduces a new feature |
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,5 @@ | ||
feat: | ||
- Introduces a new feature pt 2 | ||
|
||
doc: | ||
- Document a feature |
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
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,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
require('../src/setup_node_env'); | ||
require('../src/dev/generate_changelog'); |
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,83 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { resolve } from 'path'; | ||
import { readFileSync, writeFileSync, readdirSync } from 'fs'; | ||
import { load as loadYaml } from 'js-yaml'; | ||
import { version as pkgVersion } from '../../package.json'; | ||
|
||
const CHANGELOG_HEADER = `# CHANGELOG | ||
|
||
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)`; | ||
|
||
const SECTION_MAPPING = { | ||
breaking: '💥 Breaking Changes', | ||
deprecate: 'Deprecations', | ||
feat: '📈 Features/Enhancements', | ||
fix: '🐛 Bug Fixes', | ||
infra: '🚞 Infrastructure', | ||
doc: '📝 Documentation', | ||
chore: '🛠 Maintenance', | ||
refactor: '🪛 Refactoring', | ||
test: '🔩 Tests', | ||
}; | ||
|
||
const SECTION_KEYS = Object.keys(SECTION_MAPPING); | ||
type SectionKey = keyof typeof SECTION_MAPPING; | ||
type Changelog = Record<SectionKey, string[]>; | ||
|
||
const sections: Partial<Changelog> = {}; | ||
|
||
const fragmentDirPath = resolve(__dirname, '..', '..', 'changelogs', 'fragments'); | ||
const fragmentPaths = readdirSync(fragmentDirPath).filter( | ||
(path) => path.endsWith('.yml') || path.endsWith('.yaml') | ||
); | ||
|
||
for (const fragmentFilename of fragmentPaths) { | ||
const fragmentPath = resolve(fragmentDirPath, fragmentFilename); | ||
const fragmentContents = readFileSync(fragmentPath, { encoding: 'utf-8' }); | ||
const fragmentYaml = loadYaml(fragmentContents) as Changelog; | ||
|
||
const prNumber = fragmentFilename.split('.').slice(0, -1).join('.'); | ||
|
||
for (const [sectionKey, entries] of Object.entries(fragmentYaml)) { | ||
if (!SECTION_KEYS.includes(sectionKey)) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Unknown section ${sectionKey}. Ignoring`); | ||
continue; | ||
} | ||
|
||
const section = sections[sectionKey as SectionKey] || (sections[sectionKey as SectionKey] = []); | ||
section.push( | ||
...entries.map( | ||
(entry) => | ||
`${entry} ([#${prNumber}](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/${prNumber}))` | ||
) | ||
); | ||
} | ||
} | ||
|
||
const changelogSections = []; | ||
|
||
for (const [sectionKey, entries] of Object.entries(sections)) { | ||
if (!entries) { | ||
continue; | ||
} | ||
|
||
const sectionName = SECTION_MAPPING[sectionKey as SectionKey]; | ||
|
||
changelogSections.push(`### ${sectionName} | ||
|
||
${entries.map((entry) => ` - ${entry}`).join('\n')}`); | ||
} | ||
|
||
const changelog = `${CHANGELOG_HEADER} | ||
|
||
## [${pkgVersion}](https://github.com/opensearch-project/OpenSearch-Dashboards/releases/tag/${pkgVersion}) | ||
|
||
${changelogSections.join('\n\n')} | ||
`; | ||
|
||
writeFileSync(resolve(__dirname, '..', '..', 'CHANGELOG.md'), changelog); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IF we encounter an unknown section I thin id like to be warned more explicitly. We dont want to miss something from the changelog because we missed a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it should blow up with errors and exit without actually modifying the changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah it can modify, we have git histories to revet the change if necessary.