green_master.yaml 1.1 KB

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