@@ -109,3 +109,40 @@ jobs:
109109 if : matrix.os == 'windows-latest'
110110 run : |
111111 npm run test:cli-integration
112+
113+ report-failure :
114+ name : Report failure on the default branch
115+ runs-on : ubuntu-latest
116+ needs : [cli-test]
117+ if : failure() && github.ref == 'refs/heads/main'
118+ permissions :
119+ issues : write
120+ steps :
121+ - name : Create GitHub issue
122+ run : |
123+ # Set -eu so that we fail if the gh command fails.
124+ set -eu
125+
126+ # Try to find an existing open issue if there is one
127+ ISSUE="$(gh issue list --repo "$GITHUB_REPOSITORY" --label "cli-test-failure" --state "open" --limit 1 --json number -q '.[0].number')"
128+
129+ if [[ -n "$ISSUE" ]]; then
130+ echo "Found open issue number $ISSUE ($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/issues/$ISSUE)"
131+ else
132+ echo "Did not find an open tracking issue. Creating one."
133+
134+ ISSUE_BODY="issue-body.md"
135+ printf "CLI tests have failed on the default branch.\n\n@github/code-scanning-secexp-reviewers" > "$ISSUE_BODY"
136+
137+ ISSUE="$(gh issue create --repo "$GITHUB_REPOSITORY" --label "cli-test-failure" --title "CLI test failure" --body-file "$ISSUE_BODY")"
138+ # `gh issue create` returns the full issue URL, not just the number.
139+ echo "Created issue with URL $ISSUE"
140+ fi
141+
142+ COMMENT_FILE="comment.md"
143+ RUN_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
144+ printf 'CLI test [%s](%s) failed on ref `%s`' "$RUN_ID" "$RUN_URL" "$RUN_REF" > "$COMMENT_FILE"
145+
146+ # `gh issue create` returns an issue URL, and `gh issue list | cut -f 1` returns an issue number.
147+ # Both are accepted here.
148+ gh issue comment "$ISSUE" --repo "$GITHUB_REPOSITORY" --body-file "$COMMENT_FILE"
0 commit comments