|
| 1 | +name: Analyze Deployment Logs |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Build and Deploy Angular App"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | + |
| 8 | +jobs: |
| 9 | + analyze-logs: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Download logs from previous workflow |
| 13 | + uses: dawidd6/action-download-artifact@v2 |
| 14 | + with: |
| 15 | + workflow: ${{ github.event.workflow_run.workflow_id }} |
| 16 | + run_id: ${{ github.event.workflow_run.id }} |
| 17 | + name: deployment-logs-* |
| 18 | + path: all_deployment_logs |
| 19 | + |
| 20 | + - name: Process logs |
| 21 | + run: | |
| 22 | + mkdir -p processed_logs |
| 23 | + find all_deployment_logs -type f -name "*.txt" | xargs cat > processed_logs/combined_logs.txt |
| 24 | + grep -i "error\|exception\|failed" processed_logs/combined_logs.txt > processed_logs/error_summary.txt || true |
| 25 | + grep -i "warning" processed_logs/combined_logs.txt > processed_logs/warnings_summary.txt || true |
| 26 | + echo "Deployment Status: ${{ github.event.workflow_run.conclusion }}" > processed_logs/status_report.txt |
| 27 | + echo "Total errors found: $(grep -i "error\|exception\|failed" processed_logs/combined_logs.txt | wc -l)" >> processed_logs/status_report.txt |
| 28 | + |
| 29 | + - name: Upload processed logs |
| 30 | + uses: actions/upload-artifact@v3 |
| 31 | + with: |
| 32 | + name: processed-logs-${{ github.run_id }} |
| 33 | + path: processed_logs/ |
| 34 | + retention-days: 30 |
| 35 | + |
| 36 | + - name: Send notification on failure |
| 37 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 38 | + uses: actions/github-script@v6 |
| 39 | + with: |
| 40 | + script: | |
| 41 | + const issueBody = `## Deployment Failed |
| 42 | + Workflow run: [#${{ github.event.workflow_run.run_number }}](${{ github.event.workflow_run.html_url }}) |
| 43 | + Commit: ${{ github.event.workflow_run.head_commit.message }} |
| 44 | + |
| 45 | + Check the logs for more details.`; |
| 46 | + |
| 47 | + github.rest.issues.create({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + title: `Deployment failed on ${new Date().toISOString().split('T')[0]}`, |
| 51 | + body: issueBody, |
| 52 | + labels: ['deployment-failure'] |
| 53 | + }); |
0 commit comments