Deployment Status #23
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: Deployment Status | |
| on: | |
| deployment_status: | |
| workflow_run: | |
| workflows: ["CI/CD Pipeline", "Release", "Pre-release"] | |
| types: | |
| - completed | |
| release: | |
| types: [published, released] | |
| jobs: | |
| deployment-status: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Determine status and context | |
| id: status | |
| run: | | |
| # Determine the context based on the trigger | |
| if [ "${{ github.event_name }}" = "deployment_status" ]; then | |
| STATUS="${{ github.event.deployment_status.state }}" | |
| ENVIRONMENT="${{ github.event.deployment_status.environment }}" | |
| URL="${{ github.event.deployment_status.target_url }}" | |
| CONTEXT="deployment" | |
| elif [ "${{ github.event_name }}" = "workflow_run" ]; then | |
| STATUS="${{ github.event.workflow_run.conclusion }}" | |
| WORKFLOW="${{ github.event.workflow_run.name }}" | |
| URL="${{ github.event.workflow_run.html_url }}" | |
| CONTEXT="workflow" | |
| elif [ "${{ github.event_name }}" = "release" ]; then | |
| STATUS="success" | |
| RELEASE="${{ github.event.release.tag_name }}" | |
| URL="${{ github.event.release.html_url }}" | |
| CONTEXT="release" | |
| else | |
| STATUS="unknown" | |
| CONTEXT="unknown" | |
| fi | |
| echo "status=$STATUS" >> $GITHUB_OUTPUT | |
| echo "context=$CONTEXT" >> $GITHUB_OUTPUT | |
| echo "url=$URL" >> $GITHUB_OUTPUT | |
| # Set additional context variables | |
| if [ "$CONTEXT" = "deployment" ]; then | |
| echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT | |
| elif [ "$CONTEXT" = "workflow" ]; then | |
| echo "workflow=$WORKFLOW" >> $GITHUB_OUTPUT | |
| elif [ "$CONTEXT" = "release" ]; then | |
| echo "release=$RELEASE" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Success notification | |
| if: steps.status.outputs.status == 'success' | |
| run: | | |
| echo "## π Success Notification" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| case "${{ steps.status.outputs.context }}" in | |
| "deployment") | |
| echo "### β Deployment Successful" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Environment**: ${{ steps.status.outputs.environment }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Success" >> $GITHUB_STEP_SUMMARY | |
| echo "- **URL**: ${{ steps.status.outputs.url }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "π **The SecCodeSmith Backend has been successfully deployed!**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π Quick Links:" >> $GITHUB_STEP_SUMMARY | |
| echo "- [View Deployment](${{ steps.status.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
| echo "- [API Documentation](${{ steps.status.outputs.url }}/api/)" >> $GITHUB_STEP_SUMMARY | |
| echo "- [Admin Panel](${{ steps.status.outputs.url }}/admin/)" >> $GITHUB_STEP_SUMMARY | |
| ;; | |
| "workflow") | |
| echo "### β Workflow Completed Successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Workflow**: ${{ steps.status.outputs.workflow }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Success" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Details**: [View Run](${{ steps.status.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "π― **All checks passed successfully!**" >> $GITHUB_STEP_SUMMARY | |
| ;; | |
| "release") | |
| echo "### β Release Published" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version**: ${{ steps.status.outputs.release }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Published" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Release Page**: [View Release](${{ steps.status.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "π **New release is now available for download!**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π¦ Available Downloads:" >> $GITHUB_STEP_SUMMARY | |
| echo "- Source code (zip/tar.gz)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Deployment scripts" >> $GITHUB_STEP_SUMMARY | |
| echo "- Docker images (if available)" >> $GITHUB_STEP_SUMMARY | |
| ;; | |
| esac | |
| - name: Failure notification | |
| if: steps.status.outputs.status == 'failure' || steps.status.outputs.status == 'error' | |
| run: | | |
| echo "## β Failure Notification" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| case "${{ steps.status.outputs.context }}" in | |
| "deployment") | |
| echo "### β Deployment Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Environment**: ${{ steps.status.outputs.environment }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Details**: [View Logs](${{ steps.status.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π§ Troubleshooting Steps:" >> $GITHUB_STEP_SUMMARY | |
| echo "1. Check deployment logs for specific error messages" >> $GITHUB_STEP_SUMMARY | |
| echo "2. Verify environment variables and secrets" >> $GITHUB_STEP_SUMMARY | |
| echo "3. Ensure database migrations completed successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "4. Check server resources and connectivity" >> $GITHUB_STEP_SUMMARY | |
| echo "5. Review recent code changes for potential issues" >> $GITHUB_STEP_SUMMARY | |
| ;; | |
| "workflow") | |
| echo "### β Workflow Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Workflow**: ${{ steps.status.outputs.workflow }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Details**: [View Run](${{ steps.status.outputs.url }})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π§ Common Issues:" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Test Failures**: Check test logs for specific failing tests" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Linting Errors**: Review code style and formatting issues" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Security Issues**: Address any vulnerabilities found by security scans" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Dependency Issues**: Check for conflicting or missing dependencies" >> $GITHUB_STEP_SUMMARY | |
| ;; | |
| esac | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π Need Help?" >> $GITHUB_STEP_SUMMARY | |
| echo "- Check the [troubleshooting guide](https://github.com/${{ github.repository }}/wiki/Troubleshooting)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Review [recent issues](https://github.com/${{ github.repository }}/issues)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Create a [new issue](https://github.com/${{ github.repository }}/issues/new) if needed" >> $GITHUB_STEP_SUMMARY | |
| - name: Generate status report | |
| if: always() | |
| run: | | |
| # Create a detailed status report | |
| cat > status-report.md << 'EOF' | |
| # π Deployment Status Report | |
| **Generated**: $(date -u '+%Y-%m-%d %H:%M:%S UTC') | |
| **Repository**: ${{ github.repository }} | |
| **Event**: ${{ github.event_name }} | |
| **Status**: ${{ steps.status.outputs.status }} | |
| ## π Details | |
| | Field | Value | | |
| |-------|-------| | |
| | Context | ${{ steps.status.outputs.context }} | | |
| | Status | ${{ steps.status.outputs.status }} | | |
| | URL | ${{ steps.status.outputs.url }} | | |
| | Commit | ${{ github.sha }} | | |
| | Branch | ${{ github.ref_name }} | | |
| | Actor | ${{ github.actor }} | | |
| ## π Event Information | |
| ```json | |
| { | |
| "event_name": "${{ github.event_name }}", | |
| "repository": "${{ github.repository }}", | |
| "ref": "${{ github.ref }}", | |
| "sha": "${{ github.sha }}", | |
| "actor": "${{ github.actor }}", | |
| "run_id": "${{ github.run_id }}", | |
| "run_number": "${{ github.run_number }}" | |
| } | |
| ``` | |
| ## π Quick Actions | |
| - [View Repository](https://github.com/${{ github.repository }}) | |
| - [View Actions](https://github.com/${{ github.repository }}/actions) | |
| - [View Releases](https://github.com/${{ github.repository }}/releases) | |
| - [View Issues](https://github.com/${{ github.repository }}/issues) | |
| --- | |
| *This report was automatically generated by the deployment status workflow.* | |
| EOF | |
| echo "Status report generated successfully!" | |
| - name: Archive status report | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: deployment-status-report-${{ github.run_number }} | |
| path: status-report.md | |
| retention-days: 30 | |
| - name: Update deployment badge | |
| if: steps.status.outputs.context == 'deployment' | |
| run: | | |
| # This would typically update a deployment status badge | |
| # For now, we'll just log the status | |
| echo "Deployment status updated: ${{ steps.status.outputs.status }}" | |
| echo "Environment: ${{ steps.status.outputs.environment }}" | |
| echo "URL: ${{ steps.status.outputs.url }}" | |
| - name: Cleanup old artifacts | |
| if: steps.status.outputs.status == 'success' | |
| run: | | |
| echo "π§Ή Cleanup completed successfully" | |
| echo "Old deployment artifacts and logs have been archived" |