🎬 Lesson 11 Recording Demo: API Documentation with Cost Tracking #17
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: Auto-Generate API Docs with Cost Tracking | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| paths: | |
| - 'lesson-11-cost-controls/api/**' | |
| workflow_dispatch: # Allow manual triggering for demo | |
| jobs: | |
| generate-docs-with-costs: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| defaults: | |
| run: | |
| working-directory: lesson-11-cost-controls | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| ref: ${{ github.head_ref }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Documentation generation with cost tracking | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| run: | | |
| echo "📚 Generating API documentation with cost tracking..." | |
| # Run documentation writer on API files - cost tracking happens automatically | |
| for file in api/*.js; do | |
| if [ -f "$file" ]; then | |
| echo "📝 Generating docs for $file with cost tracking..." | |
| node doc-writer.js "$file" | |
| fi | |
| done | |
| echo "✅ Documentation generation and cost tracking complete!" | |
| - name: Commit generated documentation | |
| run: | | |
| git config user.name "API Doc Bot" | |
| git config user.email "action@github.com" | |
| # Only add docs if they exist | |
| if [ -d "docs" ]; then | |
| git add docs/ | |
| if ! git diff --staged --quiet; then | |
| git commit -m "📚 Auto-generated API documentation with cost tracking" | |
| git push | |
| echo "📝 Documentation committed and pushed!" | |
| else | |
| echo "📝 Documentation up to date" | |
| fi | |
| else | |
| echo "📝 No documentation directory created" | |
| fi | |
| - name: Summary | |
| run: | | |
| echo "🎯 Documentation Generation Complete!" | |
| echo "" | |
| echo "📊 What happened:" | |
| echo " • AI generated comprehensive API documentation" | |
| echo " • Costs automatically tracked in GitHub Issues" | |
| echo " • Monthly budget monitoring active" | |
| echo " • Team visibility into AI spending" | |
| echo "" | |
| echo "🔍 View cost tracking: https://github.com/${{ github.repository }}/issues?q=label:ai-usage" |