update-cpp-sdk-on-release.yml 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Whenever a new Firebase iOS SDK is released, this workflow triggers *another*
  2. # workflow on the Firebase C++ SDK, which will check for the iOS version update
  3. # and create a PR updating its iOS dependencies if the version number has
  4. # changed.
  5. name: update-cpp-sdk-on-release
  6. on:
  7. workflow_dispatch:
  8. release:
  9. types: [ published ]
  10. concurrency:
  11. group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  12. cancel-in-progress: true
  13. jobs:
  14. trigger_cpp_sdk_update:
  15. # Only when a new release (not just the CocoaPods-* tag) is published.
  16. if: ${{ (github.event_name == 'release' && !contains(github.ref, 'CocoaPods')) }}
  17. # Fetch an authentication token for firebase-workflow-trigger, then use that
  18. # token to trigger the update-dependencies workflow in firebase-cpp-sdk.
  19. name: Trigger C++ SDK update
  20. runs-on: ubuntu-latest
  21. steps:
  22. - name: Setup python
  23. uses: actions/setup-python@v5
  24. with:
  25. python-version: 3.11
  26. - name: Check out firebase-cpp-sdk
  27. uses: actions/checkout@v4
  28. with:
  29. repository: firebase/firebase-cpp-sdk
  30. ref: main
  31. - name: Get firebase-workflow-trigger token
  32. uses: tibdex/github-app-token@32691ba7c9e7063bd457bd8f2a5703138591fa58 # v1
  33. id: generate-token
  34. with:
  35. app_id: ${{ secrets.CPP_WORKFLOW_TRIGGER_APP_ID }}
  36. private_key: ${{ secrets.CPP_WORKFLOW_TRIGGER_APP_PRIVATE_KEY }}
  37. repository: firebase/firebase-cpp-sdk
  38. - name: Ensure Cocoapods repo has been updated
  39. run: |
  40. # If the new version is simply vX.Y.Z or X.Y.Z, wait up to an hour each for its podspec and prebuilt zip file to be present.
  41. if [[ "$GITHUB_REF" =~ ^(refs/tags/)?v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  42. version=$(echo "$GITHUB_REF" | sed 's|^refs/tags/||' | sed s/^v//) # remove leading refs/tags and v if present
  43. echo "Checking Cocoapods repo for associated Firebase ${version} podspec."
  44. podspec_url="https://github.com/CocoaPods/Specs/blob/master/Specs/0/3/5/Firebase/${version}/Firebase.podspec.json"
  45. for retry in {1..12} error; do
  46. # Check every 5 minutes, up to an hour, for the new podspec to be present.
  47. # If it's still not present, trigger the update anyway.
  48. if [[ $retry == "error" ]]; then
  49. echo "::warning ::Firebase ${version} podspec not found, updating anyway."
  50. exit 0
  51. fi
  52. echo -n "Check ${podspec_url} (attempt ${retry}) ..."
  53. curl -H 'Authorization: token ${{ github.token }}' -L -f -o /dev/null "${podspec_url}" 2> /dev/null && echo " success!" && break
  54. echo " failed."
  55. sleep 300
  56. done
  57. echo "Checking firebase-ios-sdk repo for ${version} prebuilt zip."
  58. # Check for the zip file on this actual release URL (which might include the leading v)
  59. zipfile_url="https://github.com/firebase/firebase-ios-sdk/releases/download/${GITHUB_REF}/Firebase.zip"
  60. for retry in {1..12} error; do
  61. # Check every 5 minutes, up to an hour, for the new zip file to be present.
  62. # If it's still not present, trigger the update anyway.
  63. if [[ $retry == "error" ]]; then
  64. echo "::warning ::Firebase ${version} zip file not found, updating anyway."
  65. exit 0
  66. fi
  67. echo -n "Check ${zipfile_url} (attempt ${retry}) ..."
  68. # curl's "-r 0-0" option means only download the first byte, this prevents us from downloading 300+ MB.
  69. curl -H 'Authorization: token ${{ github.token }}' -L -f -o /dev/null -r 0-0 "${zipfile_url}" 2> /dev/null && echo " success!" && break
  70. echo " failed."
  71. sleep 300
  72. done
  73. else
  74. echo "Tag '$GITHUB_REF' doesn't match the 'vX.Y.Z' or 'X.Y.Z' format, skipping Cocoapods repo and release zip check."
  75. fi
  76. - name: Trigger firebase-cpp-sdk update
  77. run: |
  78. pip install -r scripts/gha/python_requirements.txt
  79. python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} -w update-dependencies.yml -p updateAndroid 0 -p updateiOS 1 -p comment "[Triggered]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) by [firebase-ios-sdk $GITHUB_REF release]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$GITHUB_REF)." -s 10 -A