|
| 1 | +name: Generate and Sync OpenAPI |
| 2 | + |
| 3 | +on: |
| 4 | + # Se ejecuta cuando hay cambios en los routers de la API |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - canary |
| 8 | + paths: |
| 9 | + - 'apps/dokploy/server/api/routers/**' |
| 10 | + - 'packages/server/src/services/**' |
| 11 | + - 'packages/server/src/db/schema/**' |
| 12 | + |
| 13 | + # Permite ejecución manual |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + generate-and-commit: |
| 18 | + name: Generate OpenAPI and commit to Dokploy repo |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout Dokploy repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '20' |
| 30 | + |
| 31 | + - name: Setup pnpm |
| 32 | + uses: pnpm/action-setup@v2 |
| 33 | + with: |
| 34 | + version: 8 |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: pnpm install --frozen-lockfile |
| 38 | + |
| 39 | + - name: Generate OpenAPI specification |
| 40 | + run: pnpm generate:openapi |
| 41 | + |
| 42 | + - name: Commit OpenAPI spec |
| 43 | + run: | |
| 44 | + git config user.name "Dokploy Bot" |
| 45 | + git config user.email "bot@dokploy.com" |
| 46 | + |
| 47 | + # Verifica si el archivo existe |
| 48 | + if [ ! -f openapi.json ]; then |
| 49 | + echo "❌ openapi.json not found" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + # Usa -f para forzar el add de archivos en .gitignore |
| 54 | + git add -f openapi.json |
| 55 | + |
| 56 | + # Verifica si hay cambios para commitear |
| 57 | + if git diff --cached --quiet; then |
| 58 | + echo "📝 No changes detected in OpenAPI spec" |
| 59 | + echo "HAS_CHANGES=false" >> $GITHUB_ENV |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | + |
| 63 | + echo "HAS_CHANGES=true" >> $GITHUB_ENV |
| 64 | + |
| 65 | + # Commit los cambios |
| 66 | + git commit -m "chore: update OpenAPI specification [skip ci] |
| 67 | +
|
| 68 | +Generated from commit: ${{ github.sha }} |
| 69 | +Triggered by: ${{ github.event_name }}" |
| 70 | + |
| 71 | + git push |
| 72 | + |
| 73 | + echo "✅ OpenAPI spec committed successfully" |
| 74 | + |
| 75 | + - name: Trigger website sync |
| 76 | + if: env.HAS_CHANGES == 'true' |
| 77 | + uses: peter-evans/repository-dispatch@v2 |
| 78 | + with: |
| 79 | + token: ${{ secrets.DOCS_SYNC_TOKEN }} |
| 80 | + repository: dokploy/website # Cambia por tu repo de docs |
| 81 | + event-type: openapi-updated |
| 82 | + client-payload: '{"commit": "${{ github.sha }}", "timestamp": "${{ github.event.head_commit.timestamp }}"}' |
| 83 | + |
| 84 | + - name: Create summary |
| 85 | + run: | |
| 86 | + echo "## 📊 OpenAPI Generation Summary" >> $GITHUB_STEP_SUMMARY |
| 87 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 88 | + echo "- **Repository:** \`${{ github.repository }}\`" >> $GITHUB_STEP_SUMMARY |
| 89 | + echo "- **Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "- **Trigger:** \`${{ github.event_name }}\`" >> $GITHUB_STEP_SUMMARY |
| 91 | + echo "- **Changes:** \`${{ env.HAS_CHANGES }}\`" >> $GITHUB_STEP_SUMMARY |
| 92 | + echo "- **Status:** ✅ Success" >> $GITHUB_STEP_SUMMARY |
| 93 | +
|
0 commit comments