green_master.yaml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. steps:
  24. - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
  25. with:
  26. ref: ${{ matrix.ref }}
  27. - name: run script
  28. shell: bash
  29. env:
  30. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  31. GITHUB_REPO: ${{ github.repository }}
  32. run: |
  33. 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
  34. for id in $(jq -r '.workflow_runs[] | select((."conclusion" == "failure") and (."name" != "Keep master green") and .run_attempt < 3) | .id' runs.json); do
  35. echo "rerun https://github.com/${GITHUB_REPO}/actions/runs/$id"
  36. gh api --method POST /repos/${GITHUB_REPO}/actions/runs/$id/rerun-failed-jobs || true
  37. done