Skip to content

Commit

Permalink
feat(ci): add enterprise and community edition release info to change…
Browse files Browse the repository at this point in the history
…sets
  • Loading branch information
BatuhanW committed Dec 6, 2024
1 parent 68c8d42 commit ec23f00
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/refine-registry-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/scripts/changesets/add-enterprise-header.js
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ec23f00

Please sign in to comment.