|
| 1 | +name: Update Entity Badges |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'agents/library/**' |
| 9 | + - 'environments/library/**' |
| 10 | + - 'hooks/library/**' |
| 11 | + - 'slash-commands/library/**' |
| 12 | + - 'system-prompts/library/**' |
| 13 | + - 'output-styles/library/**' |
| 14 | + - 'scripts/count_entities.py' |
| 15 | + - '.github/workflows/update-badges.yml' |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + update-badges: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Setup Python with uv |
| 32 | + uses: astral-sh/setup-uv@v5 |
| 33 | + with: |
| 34 | + version: "latest" |
| 35 | + |
| 36 | + - name: Setup Python 3.12 |
| 37 | + run: | |
| 38 | + uv python install 3.12 |
| 39 | + uv python pin 3.12 |
| 40 | +
|
| 41 | + - name: Install dependencies |
| 42 | + run: | |
| 43 | + uv venv |
| 44 | + uv pip install pyyaml |
| 45 | +
|
| 46 | + - name: Count entities and generate badge data |
| 47 | + run: | |
| 48 | + uv run python scripts/count_entities.py |
| 49 | +
|
| 50 | + - name: Upload badge data to Gist |
| 51 | + id: gist |
| 52 | + uses: actions/github-script@v7 |
| 53 | + with: |
| 54 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + script: | |
| 56 | + const fs = require('fs'); |
| 57 | + const path = require('path'); |
| 58 | +
|
| 59 | + // Read the generated badge data |
| 60 | + const badgeDir = path.join(process.cwd(), '.github', 'badges'); |
| 61 | + const files = {}; |
| 62 | +
|
| 63 | + // Read all JSON files |
| 64 | + const fileNames = fs.readdirSync(badgeDir).filter(f => f.endsWith('.json')); |
| 65 | + for (const fileName of fileNames) { |
| 66 | + const content = fs.readFileSync(path.join(badgeDir, fileName), 'utf8'); |
| 67 | + files[fileName] = { content }; |
| 68 | + } |
| 69 | +
|
| 70 | + // Get or create gist |
| 71 | + const gistId = '${{ secrets.GIST_ID }}'; // Store gist ID as secret after first creation |
| 72 | +
|
| 73 | + if (gistId) { |
| 74 | + // Update existing gist |
| 75 | + await github.rest.gists.update({ |
| 76 | + gist_id: gistId, |
| 77 | + files: files |
| 78 | + }); |
| 79 | + console.log(`Updated gist: ${gistId}`); |
| 80 | + } else { |
| 81 | + // Create new gist (first run only) |
| 82 | + const result = await github.rest.gists.create({ |
| 83 | + description: 'Claude Code Toolbox Entity Counts', |
| 84 | + public: true, |
| 85 | + files: files |
| 86 | + }); |
| 87 | + console.log(`Created gist: ${result.data.id}`); |
| 88 | + console.log('Add this ID as GIST_ID secret in repository settings'); |
| 89 | + core.setOutput('gist_id', result.data.id); |
| 90 | + } |
| 91 | +
|
| 92 | + - name: Commit badge data (alternative approach) |
| 93 | + run: | |
| 94 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 95 | + git config --local user.name "github-actions[bot]" |
| 96 | +
|
| 97 | + # Check if there are changes |
| 98 | + if git diff --quiet .github/badges/; then |
| 99 | + echo "No changes to badge data" |
| 100 | + else |
| 101 | + git add .github/badges/ |
| 102 | + git commit -m "chore: update entity count badges [skip ci]" |
| 103 | + git push |
| 104 | + fi |
0 commit comments