|
| 1 | +name: Create workflow failure issue |
| 2 | +description: Create or update a GitHub issue in docs-engineering when a workflow fails, for automated diagnosis by an agentic workflow. |
| 3 | + |
| 4 | +inputs: |
| 5 | + token: |
| 6 | + description: A token with issues write permission on the target repo |
| 7 | + required: true |
| 8 | + repo: |
| 9 | + description: The repository to create the issue in |
| 10 | + default: github/docs-engineering |
| 11 | + required: false |
| 12 | + |
| 13 | +runs: |
| 14 | + using: composite |
| 15 | + steps: |
| 16 | + - name: Check for existing open issue |
| 17 | + id: check-existing |
| 18 | + shell: bash |
| 19 | + env: |
| 20 | + GH_TOKEN: ${{ inputs.token }} |
| 21 | + ISSUE_REPO: ${{ inputs.repo }} |
| 22 | + WORKFLOW_NAME: ${{ github.workflow }} |
| 23 | + run: | |
| 24 | + existing=$(gh issue list \ |
| 25 | + --repo "$ISSUE_REPO" \ |
| 26 | + --label "workflow-failure" \ |
| 27 | + --search "in:title [Workflow Failure] $WORKFLOW_NAME" \ |
| 28 | + --state open \ |
| 29 | + --json number \ |
| 30 | + --jq '.[0].number // empty' 2>/dev/null || true) |
| 31 | + echo "existing_issue=$existing" >> "$GITHUB_OUTPUT" |
| 32 | +
|
| 33 | + - name: Comment on existing issue |
| 34 | + if: steps.check-existing.outputs.existing_issue != '' |
| 35 | + shell: bash |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ inputs.token }} |
| 38 | + ISSUE_REPO: ${{ inputs.repo }} |
| 39 | + ISSUE_NUMBER: ${{ steps.check-existing.outputs.existing_issue }} |
| 40 | + WORKFLOW_NAME: ${{ github.workflow }} |
| 41 | + SOURCE_REPO: ${{ github.repository }} |
| 42 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 43 | + EVENT_NAME: ${{ github.event_name }} |
| 44 | + GIT_REF: ${{ github.ref }} |
| 45 | + run: | |
| 46 | + body=$(cat <<EOF |
| 47 | + ### Repeat failure |
| 48 | +
|
| 49 | + **Workflow:** \`$WORKFLOW_NAME\` |
| 50 | + **Repository:** \`$SOURCE_REPO\` |
| 51 | + **Run:** $RUN_URL |
| 52 | + **Event:** \`$EVENT_NAME\` |
| 53 | + **Ref:** \`$GIT_REF\` |
| 54 | + **Timestamp:** $(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 55 | + EOF |
| 56 | + ) |
| 57 | + gh issue comment "$ISSUE_NUMBER" \ |
| 58 | + --repo "$ISSUE_REPO" \ |
| 59 | + --body "$body" |
| 60 | +
|
| 61 | + - name: Create workflow failure issue |
| 62 | + if: steps.check-existing.outputs.existing_issue == '' |
| 63 | + shell: bash |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ inputs.token }} |
| 66 | + ISSUE_REPO: ${{ inputs.repo }} |
| 67 | + WORKFLOW_NAME: ${{ github.workflow }} |
| 68 | + SOURCE_REPO: ${{ github.repository }} |
| 69 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 70 | + EVENT_NAME: ${{ github.event_name }} |
| 71 | + GIT_REF: ${{ github.ref }} |
| 72 | + ACTOR: ${{ github.actor }} |
| 73 | + run: | |
| 74 | + body=$(cat <<EOF |
| 75 | + ### Workflow failure |
| 76 | +
|
| 77 | + **Workflow:** \`$WORKFLOW_NAME\` |
| 78 | + **Repository:** \`$SOURCE_REPO\` |
| 79 | + **Run:** $RUN_URL |
| 80 | + **Event:** \`$EVENT_NAME\` |
| 81 | + **Ref:** \`$GIT_REF\` |
| 82 | + **Triggered by:** \`$ACTOR\` |
| 83 | + **Timestamp:** $(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 84 | +
|
| 85 | + --- |
| 86 | + This issue was automatically created by the create-workflow-failure-issue action to enable automated diagnosis. |
| 87 | + EOF |
| 88 | + ) |
| 89 | + gh issue create \ |
| 90 | + --repo "$ISSUE_REPO" \ |
| 91 | + --label "workflow-failure" \ |
| 92 | + --title "[Workflow Failure] $WORKFLOW_NAME" \ |
| 93 | + --body "$body" |
0 commit comments