From a4421c82b27a70c7bcf547bec828544847611c76 Mon Sep 17 00:00:00 2001 From: rektdeckard Date: Sat, 28 Dec 2024 21:50:33 -0700 Subject: [PATCH] feat(ci): create doc PRs, maybe? --- .../workflows/dreamhost-preview-static.yaml | 5 ++ .github/workflows/dreamhost-static.yaml | 5 ++ .github/workflows/sync-docs.yaml | 88 +++++++++++++++++++ README.md | 6 +- package.json | 3 +- scripts/sync-docs.ts | 41 +++++++++ 6 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/sync-docs.yaml create mode 100644 scripts/sync-docs.ts diff --git a/.github/workflows/dreamhost-preview-static.yaml b/.github/workflows/dreamhost-preview-static.yaml index 7a405fb..2bf1602 100644 --- a/.github/workflows/dreamhost-preview-static.yaml +++ b/.github/workflows/dreamhost-preview-static.yaml @@ -3,6 +3,10 @@ name: Build and deploy to preview on: push +concurrency: + group: 'preview' + cancel-in-progress: true + jobs: deploy: runs-on: ubuntu-latest @@ -13,6 +17,7 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v4 with: + version: 9 run_install: false - name: Install Node.js diff --git a/.github/workflows/dreamhost-static.yaml b/.github/workflows/dreamhost-static.yaml index 060ed30..2af756c 100644 --- a/.github/workflows/dreamhost-static.yaml +++ b/.github/workflows/dreamhost-static.yaml @@ -5,6 +5,10 @@ on: branches: - master +concurrency: + group: 'prod' + cancel-in-progress: true + jobs: deploy: runs-on: ubuntu-latest @@ -15,6 +19,7 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v4 with: + version: 9 run_install: false - name: Install Node.js diff --git a/.github/workflows/sync-docs.yaml b/.github/workflows/sync-docs.yaml new file mode 100644 index 0000000..d1a070d --- /dev/null +++ b/.github/workflows/sync-docs.yaml @@ -0,0 +1,88 @@ +name: Sync README links section + +on: + push: + paths: + - 'README.md' + # branches: + # - main + # - master + workflow_dispatch: # Allows manual triggering + +concurrency: + group: 'docs' + cancel-in-progress: true + +env: + # List of target repositories to sync to + TARGET_REPOS: >- + phosphor-icons/core + phosphor-icons/figma + phosphor-icons/flutter + phosphor-icons/penpot + phosphor-icons/phosphor-elm + phosphor-icons/play + phosphor-icons/react + phosphor-icons/sketch + phosphor-icons/swift + phosphor-icons/theme + phosphor-icons/unplugin + phosphor-icons/vue + phosphor-icons/web + phosphor-icons/webcomponents + +jobs: + sync-docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + run_install: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + + - name: Sync to target repositories + env: + GH_TOKEN: ${{ github.token }} + run: | + echo "$TARGET_REPOS" | while read repo; do + echo "Syncing to $repo" + # Clone target repository + gh repo clone $repo target-repo + + # Run sync script + pnpm run sync-docs -- "$repo" + + # Create PR if there are changes + cd target-repo + if [[ -n "$(git status --porcelain)" ]]; then + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + # Create branch + BRANCH="sync-readme-$(date +%Y%m%d-%H%M%S)" + git checkout -b $BRANCH + + # Commit and push changes + git add README.md + git commit -m "Sync README section from master repository" + git push origin $BRANCH + + # Create PR + gh pr create \ + --title "Sync README section" \ + --body "Automated PR to sync README section from master repository" \ + --base main + fi + cd .. + rm -rf target-repo + done diff --git a/README.md b/README.md index a64da98..476e444 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ ReactDOM.render(, document.getElementById("root")); > [!NOTE] > Due to possible namespace collisions with built-in HTML elements, compononent names in the Vue library are prefixed with `Ph`, but otherwise follow the same naming conventions. Both Pascal and kebab-case conventions can be used in templates. -## Our Related Projects + +## Our Projects - [@phosphor-icons/homepage](https://github.com/phosphor-icons/homepage) ▲ Phosphor homepage and general info - [@phosphor-icons/core](https://github.com/phosphor-icons/core) ▲ Phosphor icon assets and catalog @@ -104,6 +105,7 @@ ReactDOM.render(, document.getElementById("root")); - [@phosphor-icons/sketch](https://github.com/phosphor-icons/sketch) ▲ Phosphor icons Sketch plugin - [@phosphor-icons/pack](https://github.com/phosphor-icons/pack) ▲ Phosphor web font stripper to generate minimal icon bundles - [@phosphor-icons/theme](https://github.com/phosphor-icons/theme) ▲ A VS Code (and other IDE) theme with the Phosphor color palette +- [@phosphor-icons/unplugin](https://github.com/phosphor-icons/theme) ▲ A framework-agnostic bundler plugin for generating Phosphor scripte sheets in web apps ## Community Projects @@ -127,4 +129,4 @@ If you've made a port of Phosphor and you want to see it here, just open a PR [h ## License MIT © [Phosphor Icons](https://github.com/phosphor-icons) - + diff --git a/package.json b/package.json index 7792636..0d2976d 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "build": "tsc && vite build", "preview": "vite preview", "format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,vue}\"", - "generate": "tsx scripts/generate.ts" + "generate": "tsx scripts/generate.ts", + "sync-docs": "tsx scripts/sync-docs.ts" }, "dependencies": { "@phosphor-icons/core": "^2.1.1", diff --git a/scripts/sync-docs.ts b/scripts/sync-docs.ts new file mode 100644 index 0000000..9fe84ee --- /dev/null +++ b/scripts/sync-docs.ts @@ -0,0 +1,41 @@ +import fs from "node:fs"; +import path from "node:path"; + +const SYNC_SECTIONS = ["LINKS"]; + +(function main() { + const targetRepo = process.argv[process.argv.length - 1]; + 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 readmeContent = fs.readFileSync(readmePath, "utf8"); + + for (const section of SYNC_SECTIONS) { + const sectionContent = extractSection(readmeContent, section); + if (!sectionContent) throw new Error(`Section ${section} not found in README.md`); + + const targetReadmeContent = fs.readFileSync(targetReadmePath, "utf8"); + const updatedDocsContent = updateSection(targetReadmeContent, section, sectionContent); + fs.writeFileSync(targetReadmePath, updatedDocsContent); + } +})(); + +function extractSection(content: string, section: string) { + const pattern = new RegExp( + `\n([\\s\\S]*)\n`, + "g", + ); + const match = pattern.exec(content); + return match?.[1]; +} + +function updateSection(content: string, section: string, newContent: string) { + const pattern = new RegExp( + `\n([\\s\\S]*)\n`, + "g", + ); + return content.replace(pattern, `\n${newContent}\n`); +}