update_protobuf.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. name: Update Protobuf and Abseil Submodules
  2. permissions:
  3. contents: write
  4. pull-requests: write
  5. on:
  6. schedule:
  7. # Every night at 2am UTC
  8. - cron: '0 2 * * *'
  9. workflow_dispatch:
  10. jobs:
  11. check-and-update:
  12. runs-on: ubuntu-latest
  13. steps:
  14. - name: Checkout
  15. uses: actions/checkout@v4
  16. with:
  17. submodules: true
  18. token: ${{ secrets.GITHUB_TOKEN }}
  19. - name: Check for new protobuf release
  20. id: check_release
  21. run: |
  22. # Get the latest protobuf release tag
  23. LATEST_TAG=$(curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/latest | jq -r '.tag_name')
  24. echo "Latest protobuf release: $LATEST_TAG"
  25. # Get current protobuf submodule commit
  26. cd Sources/protobuf/protobuf
  27. CURRENT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "none")
  28. echo "Current protobuf version: $CURRENT_TAG"
  29. cd ../../..
  30. # Check if update is needed
  31. if [ "$LATEST_TAG" != "$CURRENT_TAG" ] && [ "$LATEST_TAG" != "null" ]; then
  32. echo "needs_update=true" >> $GITHUB_OUTPUT
  33. echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
  34. echo "Update needed: $CURRENT_TAG -> $LATEST_TAG"
  35. else
  36. echo "needs_update=false" >> $GITHUB_OUTPUT
  37. echo "No update needed"
  38. fi
  39. - name: Update protobuf submodule
  40. if: steps.check_release.outputs.needs_update == 'true'
  41. run: |
  42. cd Sources/protobuf/protobuf
  43. git fetch --tags
  44. git checkout ${{ steps.check_release.outputs.latest_tag }}
  45. cd ../../..
  46. - name: Determine required abseil version
  47. if: steps.check_release.outputs.needs_update == 'true'
  48. id: check_abseil
  49. run: |
  50. # Extract abseil commit from protobuf_deps.bzl
  51. ABSEIL_COMMIT=$(grep -A 10 '"com_google_absl"' Sources/protobuf/protobuf/protobuf_deps.bzl | grep 'commit' | head -1 | sed 's/.*"\([a-f0-9]*\)".*/\1/')
  52. if [ -z "$ABSEIL_COMMIT" ]; then
  53. echo "Error: Could not determine abseil commit"
  54. exit 1
  55. fi
  56. echo "Required abseil commit: $ABSEIL_COMMIT"
  57. echo "abseil_commit=$ABSEIL_COMMIT" >> $GITHUB_OUTPUT
  58. - name: Update abseil submodule
  59. if: steps.check_release.outputs.needs_update == 'true'
  60. run: |
  61. cd Sources/protobuf/abseil
  62. git fetch
  63. git checkout ${{ steps.check_abseil.outputs.abseil_commit }}
  64. cd ../../..
  65. - name: Stage submodule updates
  66. if: steps.check_release.outputs.needs_update == 'true'
  67. run: |
  68. git add Sources/protobuf/protobuf
  69. git add Sources/protobuf/abseil
  70. - name: Get abseil version info
  71. if: steps.check_release.outputs.needs_update == 'true'
  72. id: abseil_info
  73. run: |
  74. cd Sources/protobuf/abseil
  75. ABSEIL_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "commit ${{ steps.check_abseil.outputs.abseil_commit }}")
  76. echo "abseil_version=$ABSEIL_TAG" >> $GITHUB_OUTPUT
  77. cd ../../..
  78. - name: Create Pull Request
  79. if: steps.check_release.outputs.needs_update == 'true'
  80. uses: peter-evans/create-pull-request@v6
  81. with:
  82. token: ${{ secrets.GITHUB_TOKEN }}
  83. commit-message: |
  84. Update protobuf to ${{ steps.check_release.outputs.latest_tag }} and abseil-cpp
  85. - Update protobuf submodule to ${{ steps.check_release.outputs.latest_tag }}
  86. - Update abseil-cpp submodule to ${{ steps.abseil_info.outputs.abseil_version }}
  87. branch: automated/update-protobuf-${{ steps.check_release.outputs.latest_tag }}
  88. delete-branch: true
  89. title: 'Update protobuf to ${{ steps.check_release.outputs.latest_tag }}'
  90. body: |
  91. ## Automated Protobuf Update
  92. This PR automatically updates the protobuf and abseil-cpp submodules to their latest versions.
  93. ### Changes
  94. - **Protobuf**: Updated to `${{ steps.check_release.outputs.latest_tag }}`
  95. - **Abseil-cpp**: Updated to `${{ steps.abseil_info.outputs.abseil_version }}`
  96. ### Release Notes
  97. See the [protobuf ${{ steps.check_release.outputs.latest_tag }} release notes](https://github.com/protocolbuffers/protobuf/releases/tag/${{ steps.check_release.outputs.latest_tag }}) for details.
  98. ---
  99. *This PR was automatically created by the [Update Protobuf workflow](https://github.com/${{ github.repository }}/actions/workflows/update_protobuf.yml)*