From 08f4369245d5cfe98eafdda0a147af07edbb49ff Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 4 Oct 2024 16:47:42 +0800 Subject: [PATCH] MDL-83365 upgradenotes: Add release notes link generator --- .grunt/notes/src/releasenotes.mjs | 58 +++++++++++++++++++++++++++++++ .grunt/upgradenotes.mjs | 8 +++++ 2 files changed, 66 insertions(+) create mode 100644 .grunt/notes/src/releasenotes.mjs diff --git a/.grunt/notes/src/releasenotes.mjs b/.grunt/notes/src/releasenotes.mjs new file mode 100644 index 00000000000..093d64a2771 --- /dev/null +++ b/.grunt/notes/src/releasenotes.mjs @@ -0,0 +1,58 @@ +#!/usr/bin/env node +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +import { getAllComponents } from './components.mjs'; +import { getCombinedNotesByComponent } from './note.mjs'; +import logger from './logger.mjs'; +import { existsSync } from 'fs'; + +/** + * Generate links to component-specific upgrade notes for each component. + * + * @param {string|undefined} tag The git tag to link to + * @returns {Promise} + */ +export default async (tag) => { + const notes = await getCombinedNotesByComponent(); + + if (Object.keys(notes).length === 0) { + logger.warn('No notes to generate'); + return; + } + + if (!tag) { + logger.error('No tag provided'); + return; + } + + // Generate the links for the components which have upgrade notes in this release. + let upgradeNotes = `### Component API updates\n\n\n`; + + const componentList = Object.fromEntries( + Object.values(getAllComponents()).map(({path, value}) => [value, path]), + ); + Object.entries(notes) + .map(([component]) => ({ + component, + componentPath: componentList[component], + })) + .filter(({ componentPath }) => existsSync(`./${componentPath}/UPGRADING.md`)) + .forEach(({component, componentPath}) => { + upgradeNotes += `- [${component}](https://github.com/moodle/moodle/blob/${tag}/${componentPath}/UPGRADING.md)\n`; + }); + + console.log(upgradeNotes); +}; diff --git a/.grunt/upgradenotes.mjs b/.grunt/upgradenotes.mjs index c274049bfaf..bf1d0d0e658 100755 --- a/.grunt/upgradenotes.mjs +++ b/.grunt/upgradenotes.mjs @@ -20,6 +20,7 @@ import chalk from 'chalk'; import { getNoteNames } from './notes/src/noteTypes.mjs'; import createAction from './notes/src/create.mjs'; import generateAction from './notes/src/generate.mjs'; +import generateReleaseNotesLinks from './notes/src/releasenotes.mjs'; import logger from './notes/src/logger.mjs'; console.log(` @@ -74,6 +75,13 @@ program new Argument('[version]', 'The Moodle version to create the summary notes for') ) .action((version) => generateAction(version)); +program + .command('releasenotes') + .summary('Generate a list of upgrade notes for individual components in markdown format for the release notes') + .addArgument( + new Argument('[tag]', 'The Moodle tag') + ) + .action((tag) => generateReleaseNotesLinks(tag)); program .command('release')