2525 ACTOR : ${{ github.event.workflow_run.actor.login }}
2626 RUN_URL : ${{ github.event.workflow_run.html_url }}
2727 run : |
28+ reported_at="$(TZ=Asia/Shanghai date '+%Y-%m-%d %H:%M:%S %z')"
29+ issue_title_prefix="[CI failed] $REPOSITORY / $WORKFLOW_NAME at "
2830 body_file="$(mktemp)"
2931 cat > "$body_file" <<EOF
3032 @sunnylqm CI run failed.
@@ -35,10 +37,59 @@ jobs:
3537 Branch: $HEAD_BRANCH
3638 Commit: $HEAD_SHA
3739 Actor: $ACTOR
40+ Reported at: $reported_at
3841 Run: $RUN_URL
3942 EOF
4043
4144 gh issue create \
4245 --repo "$REPOSITORY" \
43- --title "[CI failed] $REPOSITORY / $WORKFLOW_NAME " \
46+ --title "$issue_title_prefix$reported_at " \
4447 --body-file "$body_file"
48+
49+ close :
50+ if : github.event.workflow_run.conclusion == 'success'
51+ permissions :
52+ issues : write
53+ runs-on : ubuntu-latest
54+ steps :
55+ - name : Close recovered failure issues
56+ env :
57+ GH_TOKEN : ${{ github.token }}
58+ REPOSITORY : ${{ github.repository }}
59+ WORKFLOW_NAME : ${{ github.event.workflow_run.name }}
60+ HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
61+ HEAD_SHA : ${{ github.event.workflow_run.head_sha }}
62+ RUN_URL : ${{ github.event.workflow_run.html_url }}
63+ run : |
64+ issue_title_prefix="[CI failed] $REPOSITORY / $WORKFLOW_NAME at "
65+ fixed_at="$(TZ=Asia/Shanghai date '+%Y-%m-%d %H:%M:%S %z')"
66+ issue_numbers="$(
67+ gh issue list \
68+ --repo "$REPOSITORY" \
69+ --state open \
70+ --limit 1000 \
71+ --json number,title |
72+ jq -r --arg prefix "$issue_title_prefix" '.[] | select(.title | startswith($prefix)) | .number'
73+ )"
74+
75+ if [ -z "$issue_numbers" ]; then
76+ exit 0
77+ fi
78+
79+ comment_body="$(cat <<EOF
80+ CI recovered at $fixed_at.
81+
82+ Repository: $REPOSITORY
83+ Workflow: $WORKFLOW_NAME
84+ Branch: $HEAD_BRANCH
85+ Commit: $HEAD_SHA
86+ Run: $RUN_URL
87+ EOF
88+ )"
89+
90+ while IFS= read -r issue_number; do
91+ [ -n "$issue_number" ] || continue
92+ gh issue close "$issue_number" \
93+ --repo "$REPOSITORY" \
94+ --comment "$comment_body"
95+ done <<< "$issue_numbers"
0 commit comments