/ fetchx / .github / workflows / ci-issue-handler.yml
Swadhin Biswas feat: add multi-platform packaging and CI automation · 3/7/2026
492a637
71 lines · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: CI Issue Handler

on:
  workflow_run:
    workflows: [CI]
    types: [completed]

jobs:
  handle-ci-failure:
    name: Handle CI Failure
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - name: Find related PR
        id: find-pr
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          result-variables: pr_number
          script: |
            const owner = context.repo.owner;
            const repo = context.repo.repo;
            const sha = context.payload.workflow_run.head_sha;
            
            const { data: prs } = await github.rest.search.issuesAndPullRequests({
              q: sha + ' is:pr repo:' + owner + '/' + repo
            });
            
            if (prs.items.length > 0) {
              return prs.items[0].number;
            }
            return null;

      - name: Create issue
        if: steps.find-pr.outputs.result != ''
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const owner = context.repo.owner;
            const repo = context.repo.repo;
            const prNumber = '${{ steps.find-pr.outputs.result }}';
            
            const issueTitle = '[CI Failure] PR #' + prNumber + ' Failed';
            const issueBody = '## CI Failure Detected\n\n' +
              '**Pull Request:** #' + prNumber + '\n' +
              '**Workflow:** ' + context.payload.workflow_run.name + '\n' +
              '**Commit:** `' + context.payload.workflow_run.head_sha.substring(0, 7) + '`\n\n' +
              '### Action Required:\n' +
              'Please fix the failing checks and push the fixes to this PR.\n\n' +
              '---\n*This issue was automatically created by the CI Issue Handler.*';
            
            const { data: newIssue } = await github.rest.issues.create({
              owner,
              repo,
              title: issueTitle,
              body: issueBody,
              labels: ['ci-failure', 'automated']
            });
            
            await github.rest.issues.createComment({
              owner,
              repo,
              issue_number: parseInt(prNumber),
              body: '⚠️ **CI Failure Detected!**\n\nAn issue has been created: #' + newIssue.number
            });