retry-failed-releases.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright Broadcom, Inc. All Rights Reserved.
  2. # SPDX-License-Identifier: APACHE-2.0
  3. name: '[CI/CD] Retry release PRs'
  4. on:
  5. schedule:
  6. # Every 2 hours
  7. - cron: '0 */2 * * *'
  8. # Remove all permissions by default
  9. permissions: {}
  10. jobs:
  11. retry-failed-pr-releases:
  12. runs-on: ubuntu-latest
  13. permissions:
  14. actions: write
  15. if: ${{ github.repository_owner == 'bitnami' }}
  16. steps:
  17. - name: Retry "CI Pipeline" failed runs in releases PRs
  18. env:
  19. MAX_RETRY_SLOTS: 15
  20. MAX_RUNS_ATTEMPTS: ${{vars.MAX_RUNS_ATTEMPTS}}
  21. TEMP_FILE: "${{runner.temp}}/failed_runs.json"
  22. WORKFLOW_RUNS_URL: "${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/35553382/runs"
  23. TOKEN: ${{ secrets.GITHUB_TOKEN }}
  24. run: |
  25. # Obtain "CI Pipeline" failed runs executed by the bitnami-bot and filter those from release PRs with $MAX_RUNS_ATTEMPTS or more attempts
  26. curl -X GET -GLkso "${TEMP_FILE}" "${WORKFLOW_RUNS_URL}" \
  27. -d "status=failure" -d "actor=bitnami-bot" -d "created=>$(date -d '-3 day' '+%Y-%m-%d')" -d "per_page=100"
  28. readarray -t retriable_runs_ids < <(jq --argjson runs ${MAX_RUNS_ATTEMPTS} \
  29. '.workflow_runs[] | select((.run_attempt < $runs) and (.display_title | contains("Update dependency references"))).id' "${TEMP_FILE}")
  30. echo "Found ${#retriable_runs_ids[@]} failed runs that need to be retried"
  31. if [[ ${#retriable_runs_ids[@]} -gt ${MAX_RETRY_SLOTS} ]]; then
  32. echo "To avoid potential overload issues in CP, only ${MAX_RETRY_SLOTS} runs will be retried in this cron execution"
  33. fi
  34. for run_id in "${retriable_runs_ids[@]:0:${MAX_RETRY_SLOTS}}"; do
  35. echo "Retrying workflow $(jq --argjson id $run_id '.workflow_runs[] | select(.id==$id) | .html_url' ${TEMP_FILE})"
  36. rerun_url=$(jq -r --argjson id $run_id '.workflow_runs[] | select(.id==$id) | .rerun_url' "${TEMP_FILE}")
  37. curl -H "Authorization: Bearer ${TOKEN}" -X POST -Lks ${rerun_url}
  38. done