Skip to content

Commit

Permalink
[OSCI][FEAT] Rollout OSD - Proposal Changelog and Release Notes Proje…
Browse files Browse the repository at this point in the history
…ct (#5718)

* updating change set .yml template file according what agreed last meeting

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add 'Changelog' section to PR template

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* adding dummy change set files for work in release notes script

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* adding dummy change set files for work in release notes script

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* creating 'create_change_set_worflow.yml' file - starting version

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* commenting Build and Test worflow and correcting name for Create Change Set worflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* commenting Build and Test worflow and correcting name for Create Change Set worflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* uncommenting Build and Test workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* removing dummy changesets

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* updating pull_request_template.md for changelog entries

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* removing old changeset with wrong format

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* adding change sets dummy files 1.yml, 3.yml and 4.yml

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* fix a line in changeset 2.yml file, add scripting for updating the changelog.md and generate a opensearch-dashboards.release-notes-pkgVersion.md when we make a release, have not implemented deleting all the changeset files in the script

Signed-off-by: Qiwen Li <qiwen_li@brown.edu>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Bump actions/checkout from v2 to v4

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* release note script refactor + deletes fragment

added the deletiong of fragment files at the end.
Did minor refactoring/cleanup

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Update language in 'Changelog' section of PR template

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Update src/dev/generate_release_note.ts

Co-authored-by: Ashwin P Chandran <ashwinpc1993@gmail.com>
Signed-off-by: Qiwen Li <qiwen_li@brown.edu>

* Add changeset for PR #2

* Add first draft of changelog process README

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Add changeset for PR #2

* changed error handling behaviors.

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add changeset for PR #2

* Add more details to changelog README

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Add changeset for PR #2

* added error

Signed-off-by: qiwen li <qiwen_li@brown.edu>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Abbreviate README and link to workflow README

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* deleting test.txt file used to test if other contributors of project were able to push updates to this branch

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* fixing formatting in create_change_set_workflow.yml file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating title for README.md in changelogs directory

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating description of README.md in changelogs directory

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* removing demo fragments and adding new single one specifiying new feat of Changelog and Release Notes projects in this PR

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* removing demo fragment 2.yml

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* removed fragment thats too long. added helper file, used async functions, and added validation.

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* adding 5519.yml fragment file and removing 2.yml dummy fragment file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating changeset worflow removing syncronize option

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* deleting 5519.yml fragment file (now will be generated by workflow)

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* removing 2.yml fragment dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* removing 2.yml fragment dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* refactored code (deleteFragments, readFragments returns sections and paths)

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add changeset for PR #2

* removing 2.yml fragment dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* moved deleteFragment to end of script

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* removing changelog_verifier.yml

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changed max_length to 100

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* adding write permissions to for changeset workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* removing 2.yml fragment dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* adding write permissions to for changeset workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* adding write permissions to for changeset workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* refactored code/main function, now move fragment to temp folder.

Signed-off-by: CMDWillYang <williamyang721@gmail.com>

* Add test.txt

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* Remove test.txt

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* updating token name for workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* update token name

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* Add changeset for PR #2

* updating changeset workflow by giving correct reference for checkout action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating changeset workflow by removing reference for checkout action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating github action event from pull_request to pull_request_target

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #19

* deleting fragment 19.yml

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* adding CHANGESET_TOKEN and related logic

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing event pull_request_target to pull_request

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #25

* changing event pull_request to pull_request_target

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add changeset for PR #24

* Add changeset for PR #24

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* deleting workflow file for creating changeset files

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* removing fragment files

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* create changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update changeset file 25.yml for PR #25

* update file 25.yml for PR #25

* update file 25.yml for PR #25

* test:
- Data ([#29](BigSamu#29))
- Data2 ([#29](BigSamu#29))

* create file 29.yml for PR #29

* test:
- Data ([#29](BigSamu#29))
- Data 2 ([#29](BigSamu#29))

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 deleted

* changeset file for PR #29 created

* changeset file for PR #29 updated

* changeset file for PR #29 deleted

* changeset file for PR #29 created

* changeset file for PR #29 deleted

* changeset file for PR #29 created

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* changeset file for PR #29 updated

* Changeset file for PR #29 updated

* Changeset file for PR #29 deleted

* Changeset file for PR #29 created

* Changeset file for PR #29 deleted

* Changeset file for PR #29 created

* Changeset file for PR #29 updated

* Changeset file for PR #29 updated

* Changeset file for PR #29 updated

* Changeset file for PR #29 updated

* Changeset file for PR #29 updated

* Changeset file for PR #29 deleted

* Changeset file for PR #29 created

* Changeset file for PR #29 deleted

* adding parse_changelog_workflow.yml file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating permissions for parse changelog workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating permissions for parse chaneglog action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating permissions for parse chaneglog action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating permissions for parse chaneglog action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating permissions for parse chaneglog action

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing name of changelog action file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* removing dummy fragment file '25.yml'

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating name of workflow in opensearch_changelog_workflow.yml file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* addin dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* removing dummy file

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Add input secrets to be used in workflow runs

Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>

* updating input variables for opensearch chnagelog workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* updating location reusable workflow

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing branch for reusable workflow for developing manual checking approach of changesets

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing branch for reusable workflow to 'main'

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing branch for reusable workflow to 'main'

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* changing branch of chnagelog workflow to 'feat/manual-changesets' for dev purposes

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* removing 'token' input from 'opensearch_changelog_workflow.yml'

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>

* Revert "removing 'token' input from 'opensearch_changelog_workflow.yml'"

This reverts commit 9b1c1a6.

* Update .github/workflows/opensearch_changelog_workflow.yml

Signed-off-by: Ashwin P Chandran <ashwinpc1993@gmail.com>

---------

Signed-off-by: Samuel Valdes Gutierrez <valdesgutierrez@gmail.com>
Signed-off-by: Johnathon Bowers <johnathonbowers@gmail.com>
Signed-off-by: Qiwen Li <qiwen_li@brown.edu>
Signed-off-by: CMDWillYang <williamyang721@gmail.com>
Signed-off-by: qiwen li <qiwen_li@brown.edu>
Signed-off-by: Ashwin P Chandran <ashwinpc1993@gmail.com>
Co-authored-by: Johnathon Bowers <johnathonbowers@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Qiwen Li <qiwen_li@brown.edu>
Co-authored-by: CMDWillYang <williamyang721@gmail.com>
Co-authored-by: Ashwin P Chandran <ashwinpc1993@gmail.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: autochangeset[bot] <154024398+autochangeset[bot]@users.noreply.github.com>
Co-authored-by: opensearch-bot[bot] <154024398+opensearch-bot[bot]@users.noreply.github.com>
Co-authored-by: opensearch-bot-dev[bot] <154634848+opensearch-bot-dev[bot]@users.noreply.github.com>
  • Loading branch information
11 people authored Feb 22, 2024
1 parent e83b7ee commit efc0fcc
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 20 deletions.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
the functionality of your change
-->

## Changelog
<!--
Add each of the changelog entries as a line item in this section. e.g.
- fix: Updates the graph
- feat: Adds a new feature
If this change does not need to added to the changelog, just add a single `skip` line e.g.
- skip
Valid prefixes: breaking, chore, deprecate, doc, feat, fix, infra, refactor, test
Descriptions following the prefixes must be 50 characters or less
-->

### Check List

- [ ] All tests pass
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/changelog_verifier.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/opensearch_changelog_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: OpenSearch Changelog Workflow

on:
pull_request_target:
types: [opened, edited]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Parse changelog entries and submit request for changset creation
# uses: BigSamu/OpenSearch_Changelog_Workflow@main
uses: BigSamu/OpenSearch_Changelog_Workflow@feat/manual-changesets
with:
token: ${{secrets.GITHUB_TOKEN}}
CHANGELOG_PR_BRIDGE_URL_DOMAIN: ${{secrets.CHANGELOG_PR_BRIDGE_URL_DOMAIN}}
CHANGELOG_PR_BRIDGE_API_KEY: ${{secrets.CHANGELOG_PR_BRIDGE_API_KEY}}
5 changes: 5 additions & 0 deletions changelogs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog and Release Notes

For information regarding the changelog and release notes process, please consult the README in the GitHub Actions repository that this process utilizes. To view this README, follow the link below:

[GitHub Actions Workflow README](https://github.com/BigSamu/OpenSearch_Change_Set_Create_Action/blob/main/README.md)
1 change: 1 addition & 0 deletions changeset file for PR #29 created
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changelogs/fragments/29.yml
1 change: 1 addition & 0 deletions changeset file for PR #29 updated
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changelogs/fragments/29.yml
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"docs:acceptApiChanges": "scripts/use_node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "scripts/use_node scripts/build_ts_refs && scripts/use_node scripts/register_git_hook",
"spec_to_console": "scripts/use_node scripts/spec_to_console",
"pkg-version": "scripts/use_node -e \"console.log(require('./package.json').version)\""
"pkg-version": "scripts/use_node -e \"console.log(require('./package.json').version)\"",
"release_note:generate": "scripts/use_node scripts/generate_release_note"
},
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions scripts/generate_release_note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

require('../src/setup_node_env');
require('../src/dev/generate_release_note');
require('../src/dev/generate_release_note_helper');
137 changes: 137 additions & 0 deletions src/dev/generate_release_note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { resolve } from 'path';
import { readFileSync, writeFileSync, Dirent, renameSync, rm } from 'fs';
import { load as loadYaml } from 'js-yaml';
import { mkdir, readdir } from 'fs/promises';
import { version as pkgVersion } from '../../package.json';
import {
validateFragment,
getCurrentDateFormatted,
Changelog,
SECTION_MAPPING,
fragmentDirPath,
fragmentTempDirPath,
SectionKey,
releaseNotesDirPath,
filePath,
} from './generate_release_note_helper';

// Function to add content after the 'Unreleased' section in the changelog
function addContentAfterUnreleased(path: string, newContent: string): void {
let fileContent = readFileSync(path, 'utf8');
const targetString = '## [Unreleased]';
const targetIndex = fileContent.indexOf(targetString);

if (targetIndex !== -1) {
const endOfLineIndex = fileContent.indexOf('\n', targetIndex);

if (endOfLineIndex !== -1) {
fileContent =
fileContent.slice(0, endOfLineIndex + 1) +
'\n' +
newContent +
fileContent.slice(endOfLineIndex + 1);
} else {
throw new Error('End of line for "Unreleased" section not found.');
}
} else {
throw new Error("'## [Unreleased]' not found in the file.");
}

writeFileSync(path, fileContent);
}

async function deleteFragments() {
rm(fragmentTempDirPath, { recursive: true }, (err: any) => {
if (err) {
throw err;
}
});
}

// Read fragment files and populate sections
async function readFragments() {
// Initialize sections
const sections: Changelog = (Object.fromEntries(
Object.keys(SECTION_MAPPING).map((key) => [key, []])
) as unknown) as Changelog;

const fragmentPaths = await readdir(fragmentDirPath, { withFileTypes: true });
for (const fragmentFilename of fragmentPaths) {
// skip non yml or yaml files
if (!fragmentFilename.name.endsWith('.yml') && !fragmentFilename.name.endsWith('.yaml')) {
// eslint-disable-next-line no-console
console.warn(`Skipping non yml or yaml file ${fragmentFilename.name}`);
continue;
}

const fragmentPath = resolve(fragmentDirPath, fragmentFilename.name);
const fragmentContents = readFileSync(fragmentPath, { encoding: 'utf-8' });

validateFragment(fragmentContents);

const fragmentYaml = loadYaml(fragmentContents) as Changelog;

for (const [sectionKey, entries] of Object.entries(fragmentYaml)) {
sections[sectionKey as SectionKey].push(...entries);
}
}
return { sections, fragmentPaths };
}

async function moveFragments(fragmentPaths: Dirent[]): Promise<void> {
// create folder for temp fragments at fragmentTempDirPath
await mkdir(fragmentTempDirPath, { recursive: true });

// Move fragment files to temp fragments folder
for (const fragmentFilename of fragmentPaths) {
const fragmentPath = resolve(fragmentDirPath, fragmentFilename.name);
const fragmentTempPath = resolve(fragmentTempDirPath, fragmentFilename.name);
renameSync(fragmentPath, fragmentTempPath);
}
}

function generateChangelog(sections: Changelog) {
// Generate changelog sections
const changelogSections = Object.entries(sections).map(([sectionKey, entries]) => {
const sectionName = SECTION_MAPPING[sectionKey as SectionKey];
return entries.length === 0
? `### ${sectionName}`
: `### ${sectionName}\n\n${entries.map((entry) => ` - ${entry}`).join('\n')}`;
});

// Generate full changelog
const currentDate = getCurrentDateFormatted();
const changelog = `## [${pkgVersion}-${currentDate}](
${changelogSections.join('\n\n')}
`;
// Update changelog file
addContentAfterUnreleased(filePath, changelog);
return changelogSections;
}

function generateReleaseNote(changelogSections: string[]) {
// Generate release note
const releaseNoteFilename = `opensearch-dashboards.release-notes-${pkgVersion}.md`;
const releaseNoteHeader = `# VERSION ${pkgVersion} Release Note`;
const releaseNote = `${releaseNoteHeader}\n\n${changelogSections.join('\n\n')}`;
writeFileSync(resolve(releaseNotesDirPath, releaseNoteFilename), releaseNote);
}

(async () => {
const { sections, fragmentPaths } = await readFragments();

// move fragments to temp fragments folder
await moveFragments(fragmentPaths);

const changelogSections = generateChangelog(sections);

generateReleaseNote(changelogSections);

// remove temp fragments folder
await deleteFragments();
})();
68 changes: 68 additions & 0 deletions src/dev/generate_release_note_helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { resolve } from 'path';

export const filePath = resolve(__dirname, '..', '..', 'CHANGELOG.md');
export const fragmentDirPath = resolve(__dirname, '..', '..', 'changelogs', 'fragments');
export const fragmentTempDirPath = resolve(__dirname, '..', '..', 'changelogs', 'temp_fragments');
export const releaseNotesDirPath = resolve(__dirname, '..', '..', 'release-notes');

export function getCurrentDateFormatted(): string {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
const day = now.getDate();

const formattedMonth = month.toString().padStart(2, '0');
const formattedDay = day.toString().padStart(2, '0');

return `${year}-${formattedMonth}-${formattedDay}`;
}

export const SECTION_MAPPING = {
breaking: '💥 Breaking Changes',
deprecate: 'Deprecations',
security: '🛡 Security',
feat: '📈 Features/Enhancements',
fix: '🐛 Bug Fixes',
infra: '🚞 Infrastructure',
doc: '📝 Documentation',
chore: '🛠 Maintenance',
refactor: '🪛 Refactoring',
test: '🔩 Tests',
};

export type SectionKey = keyof typeof SECTION_MAPPING;
export type Changelog = Record<SectionKey, string[]>;

const MAX_ENTRY_LENGTH = 100;

// validate format of fragment files
export function validateFragment(content: string) {
const sections = content.split('\n\n');

// validate each section
for (const section of sections) {
const lines = section.split('\n');
const sectionName = lines[0];
const sectionKey = sectionName.slice(0, -1);

if (!SECTION_MAPPING[sectionKey as SectionKey] || !sectionName.endsWith(':')) {
throw new Error(`Unknown section ${sectionKey}.`);
}
// validate entries. each entry must start with '-' and a space. then followed by a string. string must be non-empty and less than 50 characters
const entryRegex = new RegExp(`^-.{1,${MAX_ENTRY_LENGTH}}\\(\\[#.+]\\(.+\\)\\)$`);
for (const entry of lines.slice(1)) {
if (entry === '') {
continue;
}
// if (!entryRegex.test(entry)) {
if (!entryRegex.test(entry.trim())) {
throw new Error(`Invalid entry ${entry} in section ${sectionKey}.`);
}
}
}
}

0 comments on commit efc0fcc

Please sign in to comment.