green_master.yaml 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ---
  2. name: Keep master green
  3. on:
  4. schedule:
  5. # run hourly
  6. - cron: "0 * * * *"
  7. workflow_dispatch:
  8. permissions:
  9. contents: read
  10. jobs:
  11. rerun-failed-jobs:
  12. if: github.repository_owner == 'emqx'
  13. runs-on: ubuntu-latest
  14. permissions:
  15. checks: read
  16. actions: write
  17. strategy:
  18. fail-fast: false
  19. matrix:
  20. ref:
  21. - master
  22. - release-57
  23. - release-58
  24. steps:
  25. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  26. with:
  27. ref: ${{ matrix.ref }}
  28. - name: run script
  29. shell: bash
  30. env:
  31. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  32. GITHUB_REPO: ${{ github.repository }}
  33. run: |
  34. gh api --method GET -f head_sha=$(git rev-parse HEAD) -f status=completed -f exclude_pull_requests=true /repos/${GITHUB_REPO}/actions/runs > runs.json
  35. for id in $(jq -r '.workflow_runs[] | select((."conclusion" == "failure") and (."name" != "Keep master green") and .run_attempt < 3) | .id' runs.json); do
  36. echo "rerun https://github.com/${GITHUB_REPO}/actions/runs/$id"
  37. gh api --method POST /repos/${GITHUB_REPO}/actions/runs/$id/rerun-failed-jobs || true
  38. done