Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 53 additions & 11 deletions .github/workflows/report-workflow-failures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
issues: write
steps:
- name: Create or update issue
id: report
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
Expand Down Expand Up @@ -95,18 +96,34 @@ jobs:

const body = [
issueMarker,
`*Generated by the [${context.workflow} workflow](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}).*`,
'',
'The following jobs are failing in this workflow:',
'',
...failedJobListItems,
'',
'cc @github/primer-engineering to investigate and fix',
'',
'<details>',
'<summary>Agent instructions</summary>',
'',
'Investigate this workflow failure and determine whether it needs a change in this repository.',
'',
'- Review the failed jobs, their logs, and recent runs of the same workflow.',
'- Assess whether the failure is intermittent or caused by an external service disruption, outage, or other transient infrastructure issue.',
'- If the failure has an actionable cause in this repository, implement the smallest appropriate fix and verify it addresses the failure.',
'- Do not make speculative code changes when the evidence points to a transient or external cause.',
'- If you decide not to attempt a fix, leave a comment on this issue explaining the evidence and rationale for that decision.',
'',
'</details>',
].join('\n');

const issue = {
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
type: 'Bug',
};

let issueNumber;
Expand All @@ -133,18 +150,43 @@ jobs:
issueNumber = createdIssue.data.number;
}

try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
assignees: ['copilot'],
});
} catch (error) {
core.warning(
`Failed to assign @copilot to issue #${issueNumber}. This is expected if Copilot assignment is not enabled for this repository. Error: ${error?.message ?? String(error)}`,
);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['area: actions'],
});

core.setOutput('issue_number', issueNumber);

- name: Assign issue to Copilot
if: ${{ steps.report.outputs.issue_number }}
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GH_AW_AGENT_TOKEN }}
ISSUE_NUMBER: ${{ steps.report.outputs.issue_number }}
assigned="$(
gh api \
--method POST \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"/repos/${GITHUB_REPOSITORY}/issues/${ISSUE_NUMBER}/assignees" \
--input - \
--jq 'any(.assignees[]; .login == "copilot-swe-agent[bot]")' <<EOF
{
"assignees": ["copilot-swe-agent[bot]"],
"agent_assignment": {
"target_repo": "${GITHUB_REPOSITORY}",
"base_branch": "main"
}
}
EOF
)"

if [[ "$assigned" != 'true' ]]; then
echo '::error::GitHub did not assign Copilot to the workflow failure issue'
exit 1
fi

close-issue:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
Expand Down
Loading