argocd-sync-failed #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ArgoCD Deployment Failure Handler | |
| on: | |
| repository_dispatch: | |
| types: [argocd-sync-failed] | |
| permissions: | |
| issues: write | |
| contents: read | |
| jobs: | |
| create-issue: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create GitHub Issue | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const payload = context.payload.client_payload || {}; | |
| const appName = payload.app_name || 'unknown'; | |
| const clusterUrl = payload.cluster || 'unknown'; | |
| const namespace = payload.namespace || 'default'; | |
| const healthStatus = payload.health_status || 'unknown'; | |
| const syncStatus = payload.sync_status || 'unknown'; | |
| const message = payload.message || 'No error message available'; | |
| const revision = payload.revision || 'unknown'; | |
| const repoUrl = payload.repo_url || ''; | |
| const targetRevision = payload.target_revision || ''; | |
| const timestamp = payload.timestamp || new Date().toISOString(); | |
| // Extract cluster name from URL (e.g., https://kubernetes.default.svc -> "in-cluster") | |
| let clusterName = 'in-cluster'; | |
| if (clusterUrl && clusterUrl !== 'unknown' && !clusterUrl.includes('kubernetes.default.svc')) { | |
| clusterName = clusterUrl.replace(/^https?:\/\//, '').split(':')[0]; | |
| } | |
| const issueTitle = `🚨 ArgoCD Deployment Failed: ${appName}`; | |
| const issueBody = `## ArgoCD Deployment Failure | |
| **Application:** \`${appName}\` | |
| **Timestamp:** ${timestamp} | |
| ### Cluster Information | |
| | Field | Value | | |
| |-------|-------| | |
| | Cluster Name | \`${clusterName}\` | | |
| | Cluster URL | \`${clusterUrl}\` | | |
| | Namespace | \`${namespace}\` | | |
| ### Application Status | |
| | Field | Value | | |
| |-------|-------| | |
| | Health Status | \`${healthStatus}\` | | |
| | Sync Status | \`${syncStatus}\` | | |
| | Revision | \`${revision}\` | | |
| | Target Revision | \`${targetRevision}\` | | |
| | Repository | ${repoUrl} | | |
| ### Error Message | |
| \`\`\` | |
| ${message} | |
| \`\`\` | |
| ### Quick Links | |
| - [ArgoCD UI](https://localhost:8080/applications/${appName}) | |
| - [Source Repository](${repoUrl}) | |
| --- | |
| *This issue was automatically created by ArgoCD Notifications* | |
| `; | |
| // Check if similar issue already exists (open) | |
| const existingIssues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'argocd-deployment-failure', | |
| per_page: 100 | |
| }); | |
| const duplicateIssue = existingIssues.data.find(issue => | |
| issue.title.includes(appName) && issue.title.includes('Deployment Failed') | |
| ); | |
| if (duplicateIssue) { | |
| // Add comment to existing issue instead of creating new one | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: duplicateIssue.number, | |
| body: `### 🔄 Deployment Failed Again\n\n**Timestamp:** ${timestamp}\n**Revision:** \`${revision}\`\n\n${message ? '**Error:**\n```\n' + message + '\n```' : ''}` | |
| }); | |
| console.log(`Updated existing issue #${duplicateIssue.number}`); | |
| } else { | |
| // Create new issue | |
| const issue = await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: issueTitle, | |
| body: issueBody, | |
| labels: ['argocd-deployment-failure', 'automated', 'bug'] | |
| }); | |
| console.log(`Created issue #${issue.data.number}`); | |
| } |