sync-chart-cloudflare-index.yml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. name: '[Index] Sync bitnami/charts index.yaml to Cloudflare'
  2. on:
  3. push:
  4. branches:
  5. - index
  6. workflow_call:
  7. secrets:
  8. CLOUDFLARE_CLIENT_ID:
  9. required: true
  10. CLOUDFLARE_CLIENT_SECRET:
  11. required: true
  12. CLOUDFLARE_USER_AUTH:
  13. required: true
  14. # Remove all permissions by default
  15. permissions: {}
  16. jobs:
  17. deploy:
  18. name: Sync bitnami/charts index.yaml to Cloudflare
  19. runs-on: ubuntu-latest
  20. permissions:
  21. contents: read
  22. outputs:
  23. result: ${{ steps.upload.outputs.result }}
  24. steps:
  25. - uses: actions/checkout@master
  26. with:
  27. ref: 'index'
  28. - name: Upload to Cloudflare using a BCOM upload proxy
  29. id: upload
  30. env:
  31. CLOUDFLARE_CLIENT_ID: ${{ secrets.CLOUDFLARE_CLIENT_ID }}
  32. CLOUDFLARE_CLIENT_SECRET: ${{ secrets.CLOUDFLARE_CLIENT_SECRET }}
  33. CLOUDFLARE_USER_AUTH: ${{ secrets.CLOUDFLARE_USER_AUTH }}
  34. run: |
  35. status="fail"
  36. retries=0
  37. while [[ "${status}" != "ok" && "$retries" -lt 3 ]]; do
  38. export TOKEN=$(curl -s --location 'https://api-esp.broadcom.com/auth/oauth/v2/token' \
  39. --data-urlencode "client_id=${CLOUDFLARE_CLIENT_ID}" \
  40. --data-urlencode "client_secret=${CLOUDFLARE_CLIENT_SECRET}" \
  41. --data-urlencode 'grant_type=client_credentials' | jq .access_token -r )
  42. curl_args=(
  43. "--location" "--request" "PUT"
  44. "--fail" "--max-time" "10"
  45. "--header" "userAuth: Basic ${CLOUDFLARE_USER_AUTH}"
  46. "--header" "filePath: /index.yaml"
  47. "--header" "Content-Type: text/yaml"
  48. "--header" "Authorization: Bearer $TOKEN"
  49. "--upload-file" "bitnami/index.yaml"
  50. )
  51. echo "Uploading index.yaml to Cloudflare"
  52. # To avoid the action from failing, we run the request inside a conditional so we can retry
  53. if curl "${curl_args[@]}" 'https://api-esp.broadcom.com/crushftp/fileUpload'; then
  54. echo "Index upload request succeeded, waiting 20 seconds before integrity check..."
  55. # Wait for 20 seconds to ensure the new index.yaml is available
  56. sleep 20
  57. # Compare the index.yaml checksums remote and locally
  58. REMOTE_MD5=($(curl -Ls https://charts.bitnami.com/bitnami/index.yaml | md5sum))
  59. REPOSITORY_MD5=($(md5sum bitnami/index.yaml))
  60. if [[ "${REPOSITORY_MD5[0]}" == "${REMOTE_MD5[0]}" ]]; then
  61. status='ok'
  62. else
  63. echo "Integrity check failed. Uploading index.yaml again.";
  64. fi
  65. else
  66. echo "Index upload request failed or timed out. Retrying again in 20 seconds...";
  67. sleep 20
  68. fi
  69. retries=$((retries+1))
  70. done
  71. echo "result=${status}" >> $GITHUB_OUTPUT
  72. - name: Show messages
  73. uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
  74. with:
  75. script: |
  76. if ("${{ steps.upload.outputs.result }}" != "ok" ) {
  77. core.setFailed("Index upload failed");
  78. } else {
  79. core.info("Index upload succeeded")
  80. }
  81. notify:
  82. name: Send notification
  83. needs: [deploy]
  84. if: ${{ always() && needs.deploy.outputs.result != 'ok' }}
  85. uses: bitnami/support/.github/workflows/gchat-notification.yml@main
  86. with:
  87. workflow: ${{ github.workflow }}
  88. job-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  89. secrets:
  90. webhook-url: ${{ secrets.GCHAT_WEBHOOK_URL }}