|
| 1 | +# Auto-Issue on Failure Workflow |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This workflow automatically creates GitHub issues when the CI Pipeline fails, making it easy to track and fix problems. |
| 6 | + |
| 7 | +## How It Works |
| 8 | + |
| 9 | +### Trigger |
| 10 | +```yaml |
| 11 | +on: |
| 12 | + workflow_run: |
| 13 | + workflows: ["CI Pipeline"] |
| 14 | + types: [completed] |
| 15 | +``` |
| 16 | +
|
| 17 | +The workflow triggers when the "CI Pipeline" workflow completes. It only runs if the conclusion is 'failure'. |
| 18 | +
|
| 19 | +### Process |
| 20 | +
|
| 21 | +1. **Failure Detection** |
| 22 | + - Checks if `workflow_run.conclusion == 'failure'` |
| 23 | + - Extracts failure metadata (workflow name, run number, branch, commit, actor) |
| 24 | + |
| 25 | +2. **Duplicate Prevention** |
| 26 | + - Searches for existing open issues with the `ci-failure` label |
| 27 | + - Checks if an issue already exists for the same workflow and branch |
| 28 | + - If found, adds a comment instead of creating a new issue |
| 29 | + |
| 30 | +3. **Issue Creation** |
| 31 | + - **Title Format**: `🔴 CI Failure: [Workflow Name] #[Run Number] on [Branch]` |
| 32 | + - **Labels**: `ci-failure`, `bug`, `automated` |
| 33 | + - **Body Includes**: |
| 34 | + - Failure details table |
| 35 | + - Direct link to failed run |
| 36 | + - Investigation steps |
| 37 | + - Common failure points checklist |
| 38 | + - Reproduction instructions |
| 39 | + - Action items checklist |
| 40 | + |
| 41 | +## Example Issue |
| 42 | + |
| 43 | +### Title |
| 44 | +``` |
| 45 | +🔴 CI Failure: CI Pipeline #42 on main |
| 46 | +``` |
| 47 | +
|
| 48 | +### Content Includes |
| 49 | +
|
| 50 | +- **Details Table**: Workflow name, run number, branch, commit SHA, actor |
| 51 | +- **Investigation Steps**: |
| 52 | + - Review logs |
| 53 | + - Check recent changes |
| 54 | + - Reproduce locally |
| 55 | + - Common failure points |
| 56 | +
|
| 57 | +- **Next Steps Checklist**: |
| 58 | + - [ ] Identify root cause |
| 59 | + - [ ] Fix the issue |
| 60 | + - [ ] Run health checks locally |
| 61 | + - [ ] Push fix and verify CI passes |
| 62 | + - [ ] Close this issue |
| 63 | +
|
| 64 | +## Benefits |
| 65 | +
|
| 66 | +✅ **Automatic Tracking**: No manual issue creation needed |
| 67 | +✅ **No Duplicates**: Smart detection of existing issues |
| 68 | +✅ **Rich Context**: All relevant information in one place |
| 69 | +✅ **Actionable**: Clear steps to investigate and resolve |
| 70 | +✅ **Linked**: Direct links to failed runs and commits |
| 71 | +
|
| 72 | +## Permissions Required |
| 73 | +
|
| 74 | +The workflow requires: |
| 75 | +- `issues: write` - To create and comment on issues |
| 76 | +- `actions: read` - To read workflow run information |
| 77 | +- `contents: read` - To checkout code |
| 78 | +
|
| 79 | +## Labels Used |
| 80 | +
|
| 81 | +- **ci-failure**: Identifies CI-related issues |
| 82 | +- **bug**: Marks it as a bug |
| 83 | +- **automated**: Indicates auto-generated content |
| 84 | +
|
| 85 | +## Customization |
| 86 | +
|
| 87 | +### Change Workflow Trigger |
| 88 | +Edit line 4 to monitor different workflows: |
| 89 | +```yaml |
| 90 | +workflows: ["Your Workflow Name"] |
| 91 | +``` |
| 92 | + |
| 93 | +### Modify Issue Content |
| 94 | +Edit the `issue_body.md` section in the "Extract failure information" step. |
| 95 | + |
| 96 | +### Add More Labels |
| 97 | +Edit the labels array in the "Create or update issue" step: |
| 98 | +```javascript |
| 99 | +labels: ['ci-failure', 'bug', 'automated', 'your-label'] |
| 100 | +``` |
| 101 | + |
| 102 | +## Testing |
| 103 | + |
| 104 | +To test this workflow: |
| 105 | + |
| 106 | +1. Push code that will cause CI to fail |
| 107 | +2. Wait for CI Pipeline to complete with failure |
| 108 | +3. Check the Issues tab for a new issue |
| 109 | +4. Push another failure to the same branch |
| 110 | +5. Verify a comment is added instead of creating a new issue |
| 111 | + |
| 112 | +## Workflow Dependencies |
| 113 | + |
| 114 | +This workflow depends on: |
| 115 | +- **CI Pipeline** workflow being named exactly "CI Pipeline" |
| 116 | +- GitHub Actions being enabled |
| 117 | +- Issue creation permissions in the repository |
| 118 | + |
| 119 | +## Troubleshooting |
| 120 | + |
| 121 | +### Issue Not Created |
| 122 | + |
| 123 | +**Check**: |
| 124 | +- Workflow run conclusion is "failure" (not "cancelled" or "skipped") |
| 125 | +- Repository has issues enabled |
| 126 | +- Workflow has proper permissions |
| 127 | + |
| 128 | +### Duplicate Issues Created |
| 129 | + |
| 130 | +**Check**: |
| 131 | +- Label `ci-failure` is applied correctly |
| 132 | +- Issue title matching logic in `check_existing` step |
| 133 | + |
| 134 | +### Missing Information |
| 135 | + |
| 136 | +**Check**: |
| 137 | +- Workflow run event data is available |
| 138 | +- All environment variables are properly set |
0 commit comments