feat(ci): sync additional files

This commit is contained in:
rektdeckard
2024-12-29 14:38:16 -07:00
committed by Tobias Fried
parent d05dd19606
commit e28695fcd2
5 changed files with 41 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
# Thanks for considering supporting this project! 🎉
github: [phosphor-icons, rektdeckard] github: [phosphor-icons, rektdeckard]
patreon: phosphoricons patreon: phosphoricons
buy_me_a_coffee: phosphoricons buy_me_a_coffee: phosphoricons

BIN
.github/logo.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -4,6 +4,7 @@ on:
push: push:
paths: paths:
- 'README.md' - 'README.md'
- '.github/FUNDING.yaml'
branches: branches:
- master - master
workflow_dispatch: # Allows manual triggering workflow_dispatch: # Allows manual triggering
@@ -84,8 +85,7 @@ jobs:
git checkout -b $BRANCH git checkout -b $BRANCH
# Commit and push changes # Commit and push changes
git add README.md git commit -am "chore(docs): sync readme section"
git commit -m "chore(docs): sync readme section"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ matrix.repository }}.git" $BRANCH
# Create PR using the GitHub CLI # Create PR using the GitHub CLI

View File

@@ -1,6 +1,6 @@
# Phosphor Icons # Phosphor Icons
<!-- BEGIN_LOGO --> <!-- BEGIN_LOGO -->
<img src="/.github/logo.png" width="96" align="right" /> <img src="/.github/logo.png" width="128" align="right" />
<!-- END_LOGO --> <!-- END_LOGO -->

View File

@@ -1,26 +1,53 @@
import fs from "node:fs"; import fs from "node:fs";
import path from "node:path"; import path from "node:path";
const SYNC_SECTIONS = ["LINKS"]; const README_PATH = "README.md";
const FUNDING_PATH = ".github/FUNDING.yaml";
const LOGO_PATH = ".github/logo.png";
const SYNC_SECTIONS = ["LOGO", "OVERVIEW", "LINKS"];
const SYNC_FILES: Array<string | Array<string>> = [
[FUNDING_PATH, ".github/FUNDING.yml"],
LOGO_PATH,
]; // These files will be replaced in the target repository
(function main() { (function main() {
const targetRepo = process.argv[process.argv.length - 1]; const targetRepo = process.argv[process.argv.length - 1];
if (!targetRepo) throw new Error("Target repository not provided"); if (!targetRepo) throw new Error("Target repository not provided");
const targetReadmePath = path.resolve(__dirname, `../../${targetRepo}/README.md`);
if (!fs.existsSync(targetReadmePath)) throw new Error(`README.md not found in ${targetRepo}`);
const readmePath = path.resolve(__dirname, "../README.md"); const readmePath = path.resolve(__dirname, `../${README_PATH}`);
const readmeContent = fs.readFileSync(readmePath, "utf8"); const readmeContent = fs.readFileSync(readmePath, "utf8");
for (const section of SYNC_SECTIONS) { const targetReadmePath = path.resolve(__dirname, `../../${targetRepo}/${README_PATH}`);
const sectionContent = extractSection(readmeContent, section); if (!fs.existsSync(targetReadmePath)) throw new Error(`README.md not found in ${targetRepo}`);
if (!sectionContent) continue;
for (const section of SYNC_SECTIONS) {
const readmeSection = extractSection(readmeContent, section);
if (readmeSection) {
const targetReadmeContent = fs.readFileSync(targetReadmePath, "utf8"); const targetReadmeContent = fs.readFileSync(targetReadmePath, "utf8");
const updatedDocsContent = updateSection(targetReadmeContent, section, sectionContent); const updatedDocsContent = updateSection(targetReadmeContent, section, readmeSection);
fs.writeFileSync(targetReadmePath, updatedDocsContent); fs.writeFileSync(targetReadmePath, updatedDocsContent);
} }
}
for (const file of SYNC_FILES) {
const fileName = Array.isArray(file) ? file[0] : file;
const filePath = path.resolve(__dirname, `../${fileName}`);
const fileContent = fs.readFileSync(filePath, "utf8");
if (Array.isArray(file)) {
for (const alias of file) {
const targetPath = path.resolve(__dirname, `../../${targetRepo}/${alias}`);
if (fs.existsSync(targetPath)) {
fs.rmSync(targetPath);
}
}
}
const targetPath = path.resolve(__dirname, `../../${targetRepo}/${fileName}`);
fs.writeFileSync(targetPath, fileContent); // Overwrites the target file if it exists
}
})(); })();
function extractSection(content: string, section: string) { function extractSection(content: string, section: string) {