Update snippet tool to generate documentation layout for tables #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Snippets Registry | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'snippets/**' | |
| - 'package.json' | |
| - 'scripts/snippet-tool.ts' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-registry: | |
| name: Collapse and Update Registry | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Collapse Snippets to Registry | |
| run: npm run snippet:collapse -- --output snippets.json | |
| - name: Check for Changes | |
| id: check_changes | |
| run: | | |
| if git diff --quiet snippets.json; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Configure Git | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Create Registry Update Branch | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| BRANCH_NAME="registry/update-$(date +%s)" | |
| git switch -c "$BRANCH_NAME" | |
| git add snippets.json | |
| git commit -m "Update snippets registry" | |
| git push -u origin "$BRANCH_NAME" | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| - name: Create Pull Request | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| gh pr create \ | |
| --title "Update snippets registry" \ | |
| --body "Automated registry update from snippets directory collapse." \ | |
| --base main \ | |
| --head "${{ env.BRANCH_NAME }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Auto-merge Pull Request | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| # Get the PR number | |
| PR_NUMBER=$(gh pr list --head "${{ env.BRANCH_NAME }}" --state open --json number -q '.[0].number') | |
| gh pr merge "$PR_NUMBER" --auto --merge | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Registry Update Complete | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: echo "✅ Registry pushed and merged." | |
| - name: No Changes to Registry | |
| if: steps.check_changes.outputs.has_changes == 'false' | |
| run: echo "ℹ️ No changes to snippets registry." |