Skip to content

[CI/CD] Retry release PRs #710

[CI/CD] Retry release PRs

[CI/CD] Retry release PRs #710

# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0
name: '[CI/CD] Retry release PRs'
on:
schedule:
# Every 2 hours
- cron: '0 */2 * * *'
# Remove all permissions by default
permissions: {}
jobs:
retry-failed-pr-releases:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Retry "CI Pipeline" failed runs in releases PRs
env:
WORKFLOW_ID: "35553382"
TEMP_FILE: "${{runner.temp}}/failed_runs.json"
ACTIONS_API_ENDPOINT: "${{ github.api_url }}/repos/${{ github.repository }}/actions"
run: |
# Obtain "CI Pipeline" failed runs and filter those from release PRs with less than 3 attempts
curl -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -Lkso ${{ env.TEMP_FILE }} ${{ env.ACTIONS_API_ENDPOINT }}/workflows/${{ env.WORKFLOW_ID }}/runs?status=failure
readarray -t failed_runs_ids < <(jq '.workflow_runs[] | select((.run_attempt < 3) and (.display_title | contains("Release")) and (.head_commit.author.email=="[email protected]")).id' ${{ env.TEMP_FILE }})
for run_id in "${failed_runs_ids[@]:0:15}"; do
echo "Retrying workflow $(jq --argjson id $run_id '.workflow_runs[] | select(.id==$id) | .html_url' ${{ env.TEMP_FILE }})"
curl -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X POST -Lks ${{ env.ACTIONS_API_ENDPOINT }}/workflows/runs/${run_id}/rerun
done