Skip to content

Commit

Permalink
docs: generate changelog from github releases (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleroux authored Apr 26, 2024
1 parent e9322b0 commit 7e72ef1
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 728 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Build
run: pnpm build --cache-dir=.turbo --filter documentation --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FIGMA_API_TOKEN: ${{ secrets.FIGMA_API_TOKEN }}
CSC: ${{ secrets.READ_CSC_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
env:
FIGMA_API_TOKEN: ${{ secrets.FIGMA_API_TOKEN }}
CSC: ${{ secrets.READ_CSC_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
id: publish
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ packages/html-test-app/src/public/additional-theme
# documentation
###

packages/documentation/docs/installation/CHANGELOG.md
packages/documentation/docs/auto-generated/
packages/documentation/.build-temp
packages/documentation/scripts/.typedoc/
Expand Down
723 changes: 0 additions & 723 deletions packages/documentation/docs/installation/CHANGELOG.md

This file was deleted.

12 changes: 7 additions & 5 deletions packages/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "MIT",
"scripts": {
"docusaurus": "docusaurus",
"start": "pnpm run download-theme && pnpm run generate-markdown && docusaurus start -h 127.0.0.1",
"build": "pnpm run download-theme && pnpm run generate-markdown && docusaurus build",
"start": "pnpm run download-theme && pnpm run generate-markdown && pnpm run generate-changelog && docusaurus start -h 127.0.0.1",
"build": "pnpm run download-theme && pnpm run generate-markdown && pnpm run generate-changelog && docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
Expand All @@ -16,14 +16,14 @@
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc",
"download-theme": "ts-node -P ./scripts/tsconfig.json ./scripts/download-theme.ts",
"generate-markdown": "ts-node -P ./scripts/tsconfig.json ./scripts/generate-markdown.ts"
"generate-markdown": "ts-node -P ./scripts/tsconfig.json ./scripts/generate-markdown.ts",
"generate-changelog": "ts-node -P ./scripts/tsconfig.json ./scripts/generate-changelog.ts"
},
"dependencies": {
"@docusaurus/core": "3.1.0",
"@docusaurus/preset-classic": "3.1.0",
"@docusaurus/theme-live-codeblock": "3.1.0",
"@mdx-js/react": "^3.0.0",
"html-test-app": "workspace:*",
"@siemens/ix": "workspace:*",
"@siemens/ix-echarts": "workspace:*",
"@siemens/ix-icons": "2.1.0",
Expand All @@ -33,6 +33,7 @@
"docusaurus-lunr-search": "^2.3.2",
"docusaurus-plugin-sass": "^0.2.2",
"execa": "^5.1.1",
"html-test-app": "workspace:*",
"prism-react-renderer": "^2.1.0",
"raw-loader": "^4.0.2",
"react": "^18.0.0",
Expand All @@ -44,12 +45,13 @@
"@docusaurus/module-type-aliases": "3.1.0",
"@docusaurus/tsconfig": "3.1.0",
"@docusaurus/types": "3.1.0",
"figma-plugin": "workspace:*",
"@types/fs-extra": "^9.0.13",
"@types/rimraf": "^3.0.2",
"@types/tar": "^6.1.7",
"axios": "^1.5.1",
"figma-plugin": "workspace:*",
"listr2": "^7.0.1",
"octokit": "^3.2.0",
"rimraf": "^3.0.2",
"tar": "^6.2.0",
"ts-node": "^10.9.1",
Expand Down
77 changes: 77 additions & 0 deletions packages/documentation/scripts/generate-changelog.ts
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();
Loading

0 comments on commit 7e72ef1

Please sign in to comment.