-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: generate changelog from github releases (#1247)
- Loading branch information
1 parent
e9322b0
commit 7e72ef1
Showing
7 changed files
with
460 additions
and
728 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
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
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import { Octokit } from 'octokit'; | ||
import fs from 'fs-extra'; | ||
import path from 'path/posix'; | ||
|
||
const markdownMeta = [ | ||
'---', | ||
'sidebar_title: Changelog', | ||
'title: Changelog', | ||
'hide_table_of_contents: true', | ||
'sidebar_position: 100', | ||
'---', | ||
].join('\n'); | ||
|
||
function getChangelogMarkdown( | ||
releases: { | ||
html_url: string; | ||
id: number; | ||
name: string | null; | ||
body?: string | null | undefined; | ||
published_at: string | null; | ||
}[] | ||
) { | ||
const markdownReleases = releases.map((release) => { | ||
const markdownReleaseTitle = `## [${release.name}](${release.html_url}) (${release.published_at})`; | ||
const markdownReleaseBody = release.body; | ||
return [markdownReleaseTitle, markdownReleaseBody].join('\n'); | ||
}); | ||
|
||
return [markdownMeta, ...markdownReleases].join('\n'); | ||
} | ||
|
||
async function fetchGitHubReleases() { | ||
const result = await octokit.rest.repos.listReleases({ | ||
owner: 'siemens', | ||
repo: 'ix', | ||
}); | ||
|
||
if (result.status !== 200) { | ||
throw new Error('Failed to fetch releases'); | ||
} | ||
|
||
return result.data; | ||
} | ||
|
||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
}); | ||
|
||
async function generateChangelog() { | ||
console.log('Generating changelog...'); | ||
const changelogPath = path.join( | ||
__dirname, | ||
'../docs/installation/CHANGELOG.md' | ||
); | ||
|
||
if (!process.env.GITHUB_TOKEN) { | ||
console.error('No GITHUB_TOKEN provided, creating empty changelog'); | ||
fs.writeFileSync(changelogPath, markdownMeta, 'utf-8'); | ||
return; | ||
} | ||
|
||
const releases = await fetchGitHubReleases(); | ||
const markdown = getChangelogMarkdown(releases); | ||
|
||
fs.writeFileSync(changelogPath, markdown, 'utf-8'); | ||
console.log('Changelog generated successfully! 🎉'); | ||
} | ||
|
||
generateChangelog(); |
Oops, something went wrong.