From ec23f0032a318b0ea4dd880335305456f2c90ea4 Mon Sep 17 00:00:00 2001 From: Batuhan Wilhelm Date: Fri, 6 Dec 2024 14:56:46 +0300 Subject: [PATCH] feat(ci): add enterprise and community edition release info to changesets --- .github/workflows/refine-registry-release.yml | 8 +- .../changesets/add-enterprise-header.js | 53 +++++++++++ .../prepare-community-edition-changesets.js | 90 +++++++++++++++++++ 3 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/scripts/changesets/add-enterprise-header.js create mode 100644 .github/workflows/scripts/changesets/prepare-community-edition-changesets.js diff --git a/.github/workflows/refine-registry-release.yml b/.github/workflows/refine-registry-release.yml index 4f0014ee225e..ea82b912ef3a 100644 --- a/.github/workflows/refine-registry-release.yml +++ b/.github/workflows/refine-registry-release.yml @@ -53,10 +53,10 @@ jobs: - name: Test run: pnpm test:all if: ${{ env.RELEASE_ONLY != 'YES' }} - - name: Copy changesets for Community version - run: mkdir -p ./_changeset/ && cp -r ./.changeset/* ./_changeset/ - - name: Convert major and minor changesets to patch - run: node ./.github/workflows/scripts/convert-to-patch.js + - name: Prepare Community Edition changesets + run: node ./.github/workflows/scripts/changesets/prepare-community-edition-changesets.js + - name: Add Enterprise Header to Changesets + run: node ./.github/workflows/scripts/changesets/add-enterprise-header.js - name: Create Release Pull Request or Publish to npm id: changesets uses: changesets/action@v1 diff --git a/.github/workflows/scripts/changesets/add-enterprise-header.js b/.github/workflows/scripts/changesets/add-enterprise-header.js new file mode 100644 index 000000000000..d9d41026bebe --- /dev/null +++ b/.github/workflows/scripts/changesets/add-enterprise-header.js @@ -0,0 +1,53 @@ +const { readdirSync, readFileSync, writeFileSync } = require("fs"); +const { join } = require("path"); + +function updateChangesetTitles() { + const TITLE_TO_ADD = "# Refine Enterprise Release\n"; + const changesetDir = join(process.cwd(), ".changeset"); + + try { + const files = readdirSync(changesetDir); + const mdFiles = files.filter( + (file) => file !== "README.md" && file.endsWith(".md"), + ); + + if (!mdFiles.length) { + console.log("✅ No changesets found"); + return; + } + + let updatedFilesCount = 0; + + for (const file of mdFiles) { + const filePath = join(changesetDir, file); + const content = readFileSync(filePath, "utf-8"); + + if (content.includes("# Refine Enterprise Release")) { + continue; + } + + const [_, frontmatter, ...bodyParts] = content.split("---"); + if (!frontmatter) continue; + + const body = bodyParts.join("---").trim(); + + const updatedContent = [ + "---", + frontmatter.trim(), + "---\n", + TITLE_TO_ADD, + body, + ].join("\n"); + + writeFileSync(filePath, updatedContent); + updatedFilesCount++; + } + + console.log(`✅ Successfully updated ${updatedFilesCount} changeset files`); + } catch (error) { + console.error("Error updating changeset files:", error); + process.exit(1); + } +} + +updateChangesetTitles(); diff --git a/.github/workflows/scripts/changesets/prepare-community-edition-changesets.js b/.github/workflows/scripts/changesets/prepare-community-edition-changesets.js new file mode 100644 index 000000000000..5e0efb4a7485 --- /dev/null +++ b/.github/workflows/scripts/changesets/prepare-community-edition-changesets.js @@ -0,0 +1,90 @@ +const { mkdirSync, readdirSync, readFileSync, writeFileSync } = require("fs"); +const { join } = require("path"); + +function copyChangesetFiles() { + const sourceDir = join(process.cwd(), ".changeset"); + const targetDir = join(process.cwd(), "_changeset"); + + try { + try { + mkdirSync(targetDir, { recursive: true }); + } catch (error) { + if (error.code !== "EEXIST") { + throw error; + } + } + + const files = readdirSync(sourceDir); + + for (const file of files) { + const sourcePath = join(sourceDir, file); + const targetPath = join(targetDir, file); + + try { + const content = readFileSync(sourcePath); + writeFileSync(targetPath, content); + console.log(`Copied: ${file}`); + } catch (error) { + console.error(`Failed to copy ${file}:`, error.message); + } + } + + console.log(`✅ Successfully copied ${files.length} files to _changeset`); + } catch (error) { + console.error("Error during changeset files copy operation:", error); + process.exit(1); + } +} + +function updateChangesetFiles() { + const TITLE_TO_ADD = "# Refine Community Edition Release\n"; + const changesetDir = join(process.cwd(), "_changeset"); + + try { + const files = readdirSync(changesetDir); + const mdFiles = files.filter((file) => file.endsWith(".md")); + + let updatedFilesCount = 0; + + for (const file of mdFiles) { + const filePath = join(changesetDir, file); + const content = readFileSync(filePath, "utf-8"); + + const [_, frontmatter, ...bodyParts] = content.split("---"); + if (!frontmatter) continue; + + const updatedFrontmatter = frontmatter.replace( + /": minor|": major/g, + '": patch', + ); + + const body = bodyParts.join("---").trim(); + + const cleanBody = body + .replace(/# Refine Enterprise Release\s*/g, "") + .replace(/# Refine Community Edition Release\s*/g, "") + .trim(); + + const updatedContent = [ + "---", + updatedFrontmatter.trim(), + "---\n", + TITLE_TO_ADD, + cleanBody, + ].join("\n"); + + writeFileSync(filePath, updatedContent); + console.log(`File updated: ${file}`); + updatedFilesCount++; + } + + console.log(`✅ Successfully updated ${updatedFilesCount} changeset files`); + } catch (error) { + console.error("Error updating changeset files:", error); + process.exit(1); + } +} + +copyChangesetFiles(); + +updateChangesetFiles();