Check proto updates #137
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: Check proto updates | |
| on: | |
| schedule: | |
| # Run at midnight UTC every day | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| check-proto-updates: | |
| name: Check for ESPHome Proto Updates | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Download latest proto files from ESPHome | |
| run: | | |
| echo "Downloading latest proto files from ESPHome dev branch..." | |
| mkdir -p temp_proto | |
| curl -o temp_proto/api.proto https://raw.githubusercontent.com/esphome/esphome/dev/esphome/components/api/api.proto | |
| curl -o temp_proto/api_options.proto https://raw.githubusercontent.com/esphome/esphome/dev/esphome/components/api/api_options.proto | |
| - name: Compare proto files | |
| id: compare | |
| run: | | |
| echo "Comparing proto files..." | |
| # Initialize variable | |
| CHANGES_DETECTED=false | |
| # Compare api.proto | |
| if ! diff -q proto/api.proto temp_proto/api.proto > /dev/null 2>&1; then | |
| echo "api.proto has changes" | |
| CHANGES_DETECTED=true | |
| else | |
| echo "api.proto is up to date" | |
| fi | |
| # Compare api_options.proto | |
| if ! diff -q proto/api_options.proto temp_proto/api_options.proto > /dev/null 2>&1; then | |
| echo "api_options.proto has changes" | |
| CHANGES_DETECTED=true | |
| else | |
| echo "api_options.proto is up to date" | |
| fi | |
| # Save result for next step | |
| echo "changes_detected=${CHANGES_DETECTED}" >> $GITHUB_OUTPUT | |
| - name: Setup Node.js | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| run: npm ci | |
| - name: Update proto files | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| run: | | |
| # Copy new proto files | |
| cp temp_proto/api.proto proto/ | |
| cp temp_proto/api_options.proto proto/ | |
| # Regenerate code | |
| npm run proto:generate | |
| - name: Run tests | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| run: npm test | |
| - name: Run linter | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| run: npm run lint | |
| - name: Build project | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| run: npm run build | |
| - name: Create PR if changes detected | |
| if: steps.compare.outputs.changes_detected == 'true' | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: 'chore: update ESPHome proto files' | |
| title: 'Update ESPHome Proto Files' | |
| body: | | |
| ## ESPHome Proto Files Update | |
| This PR updates the proto files to match the latest version from ESPHome's `dev` branch. | |
| ### What's Been Done | |
| - Downloaded latest proto files from ESPHome | |
| - Regenerated TypeScript/JavaScript code | |
| - Updated proto definitions | |
| - Ran tests, linting, and build checks | |
| All automated checks have passed. | |
| --- | |
| *This PR was automatically created by the [Check Proto Updates](.github/workflows/check-proto-updates.yml) workflow.* | |
| branch: proto-update-${{ github.run_number }} | |
| delete-branch: true | |
| labels: | | |
| proto-update | |
| dependencies | |
| automated | |
| - name: Close Issue if no changes detected | |
| if: steps.compare.outputs.changes_detected == 'false' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| // Check if there's an open issue about proto updates | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'proto-update' | |
| }); | |
| const existingIssue = issues.data.find(issue => | |
| issue.title.includes('ESPHome Proto Files Update Available') | |
| ); | |
| if (existingIssue) { | |
| // Close the issue with a comment | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existingIssue.number, | |
| body: `## ✅ Proto Files Up to Date | |
| The automated check has confirmed that the proto files are now up to date with ESPHome. | |
| Closing this issue automatically. | |
| --- | |
| *Checked on ${new Date().toISOString().split('T')[0]} by the [Check Proto Updates](.github/workflows/check-proto-updates.yml) workflow.* | |
| ` | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existingIssue.number, | |
| state: 'closed' | |
| }); | |
| console.log(`Closed issue #${existingIssue.number} - proto files are up to date`); | |
| } else { | |
| console.log('No open proto-update issues found'); | |
| } | |
| - name: Cleanup | |
| if: always() | |
| run: | | |
| rm -rf temp_proto | |
| - name: Summary | |
| if: always() | |
| run: | | |
| if [ "${{ steps.compare.outputs.changes_detected }}" = "true" ]; then | |
| echo "⚠️ Proto files are out of date! A pull request has been created." | |
| else | |
| echo "✅ Proto files are up to date!" | |
| fi |