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

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