Update deploy.yml #16
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: Build and Deploy Angular App | ||
| on: | ||
| push: | ||
| branches: | ||
| - Production | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '16' | ||
| cache: 'yarn' | ||
| - name: Install Yarn | ||
| run: npm install -g yarn | ||
| - name: Install dependencies with Yarn | ||
| run: yarn install | ||
| - name: Generate build timestamp | ||
| id: timestamp | ||
| run: echo "timestamp=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_OUTPUT | ||
| - name: Create logs directory | ||
| run: mkdir -p deployment_logs | ||
| - name: Check Angular output path in angular.json | ||
| id: check_config | ||
| run: | | ||
| if [ -f "angular.json" ]; then | ||
| DEFAULT_OUTPUT_PATH=$(grep -o '"outputPath": *"[^"]*"' angular.json | head -1 | cut -d'"' -f4) | ||
| if [ -n "$DEFAULT_OUTPUT_PATH" ]; then | ||
| echo "output_path=$DEFAULT_OUTPUT_PATH" >> $GITHUB_OUTPUT | ||
| echo "Using output path from angular.json: $DEFAULT_OUTPUT_PATH" | ||
| else | ||
| echo "output_path=dist" >> $GITHUB_OUTPUT | ||
| echo "No outputPath found in angular.json, using default: dist" | ||
| fi | ||
| else | ||
| echo "output_path=dist" >> $GITHUB_OUTPUT | ||
| echo "No angular.json found, using default: dist" | ||
| fi | ||
| - name: Build Angular app | ||
| id: build | ||
| run: | | ||
| yarn build --configuration production --base-href="/${{ github.event.repository.name }}/" 2>&1 | tee deployment_logs/build_log_${{ steps.timestamp.outputs.timestamp }}.txt | ||
| continue-on-error: true | ||
| - name: Check build status | ||
| id: check_build | ||
| run: | | ||
| if [ "${{ steps.build.outcome }}" == "success" ]; then | ||
| echo "build_status=success" >> $GITHUB_OUTPUT | ||
| echo "Build completed successfully" | ||
| else | ||
| echo "build_status=failure" >> $GITHUB_OUTPUT | ||
| echo "Build failed" | ||
| exit 1 | ||
| fi | ||
| - name: Ensure docs directory exists | ||
| if: steps.check_build.outputs.build_status == 'success' | ||
| run: | | ||
| if [ ! -d "docs" ]; then | ||
| if [ -d "${{ steps.check_config.outputs.output_path }}" ]; then | ||
| echo "Build directory found at ${{ steps.check_config.outputs.output_path }}, copying to docs/" | ||
| mkdir -p docs | ||
| cp -r ${{ steps.check_config.outputs.output_path }}/* docs/ | ||
| else | ||
| echo "Build directory not found at ${{ steps.check_config.outputs.output_path }}, listing contents of current directory:" | ||
| ls -la | ||
| echo "Creating empty docs directory" | ||
| mkdir -p docs | ||
| fi | ||
| fi | ||
| - name: Add .nojekyll file | ||
| if: steps.check_build.outputs.build_status == 'success' | ||
| run: touch docs/.nojekyll | ||
| - name: Deploy to GitHub Pages | ||
| if: steps.check_build.outputs.build_status == 'success' | ||
| id: deploy | ||
| uses: JamesIves/github-pages-deploy-action@v4 | ||
| with: | ||
| folder: docs | ||
| branch: gh-pages | ||
| clean: true | ||
| - name: Log deployment result | ||
| if: always() | ||
| run: | | ||
| echo "Deployment completed at $(date)" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt | ||
| echo "Commit: ${{ github.sha }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt | ||
| echo "Build status: ${{ steps.check_build.outputs.build_status }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt | ||
| if [ "${{ steps.check_build.outputs.build_status }}" == "success" ]; then | ||
| echo "Deployment status: ${{ steps.deploy.outcome }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt | ||
| fi | ||
| - name: Archive deployment logs | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: deployment-logs-${{ steps.timestamp.outputs.timestamp }} | ||
| path: deployment_logs/ | ||
| retention-days: 30 | ||
| - name: Send email notification on success | ||
| if: success() | ||
| uses: dawidd6/action-send-mail@v3 | ||
| with: | ||
| server_address: ${{ secrets.MAIL_SERVER }} | ||
| server_port: ${{ secrets.MAIL_PORT }} | ||
| secure: true | ||
| username: ${{ secrets.MAIL_USERNAME }} | ||
| password: ${{ secrets.MAIL_PASSWORD }} | ||
| subject: ✅ Successful Build and Deploy for ${{ github.repository }} | ||
| html_body: | | ||
| <h2>🚀 Build and deployment for ${{ github.repository }} completed successfully!</h2> | ||
| <b>📋 Details:</b> | ||
| <ul> | ||
| <li><b>Repository:</b> ${{ github.repository }}</li> | ||
| <li><b>Branch:</b> ${{ github.ref_name }}</li> | ||
| <li><b>Commit:</b> ${{ github.sha }}</li> | ||
| <li><b>Commit message:</b> ${{ github.event.head_commit.message }}</li> | ||
| <li><b>Workflow:</b> ${{ github.workflow }}</li> | ||
| <li><b>Timestamp:</b> ${{ format(github.event.repository.updated_at, 'dddd, MMMM Do YYYY, h:mm:ss a') }}</li> | ||
| <li><b>Author:</b> ${{ github.actor }}</li> | ||
| <li><b>Run ID:</b> ${{ github.run_id }}</li> | ||
| <li><b>Run Number:</b> ${{ github.run_number }}</li> | ||
| </ul> | ||
| <h3>📊 Deployment Information</h3> | ||
| <ul> | ||
| <li><b>Environment:</b> GitHub Pages</li> | ||
| <li><b>Status:</b> ${{ env.deployment_status || 'Completed' }}</li> | ||
| <li><b>Deployed URL:</b> <a href="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/">https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/</a></li> | ||
| </ul> | ||
| <h3>🔗 Quick Links</h3> | ||
| <p> | ||
| <a href="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/">📱 View the deployment</a><br> | ||
| <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">📋 View workflow run</a><br> | ||
| <a href="${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}">💻 View commit details</a> | ||
| </p> | ||
| <hr> | ||
| <p style="color:#666;font-size:12px">This is an automated message from GitHub Actions. Please do not reply to this email.</p> | ||
| from: GitHub Actions <${{ secrets.MAIL_USERNAME }}> | ||
| to: ${{ secrets.MAIL_RECIPIENT }} | ||
| name: Send email notification on failure | ||
| if: failure() | ||
| uses: dawidd6/action-send-mail@v3 | ||
| with: | ||
| server_address: ${{ secrets.MAIL_SERVER }} | ||
| server_port: 587 | ||
| secure: false | ||
| username: ${{ secrets.MAIL_USERNAME }} | ||
| password: ${{ secrets.MAIL_PASSWORD }} | ||
| subject: ❌ Failed Build for ${{ github.repository }} | ||
| html_body: | | ||
| <h2>⚠️ Build or deployment for ${{ github.repository }} failed!</h2> | ||
| <b>📋 Details:</b> | ||
| <ul> | ||
| <li><b>Repository:</b> ${{ github.repository }}</li> | ||
| <li><b>Branch:</b> ${{ github.ref_name }}</li> | ||
| <li><b>Commit:</b> ${{ github.sha }}</li> | ||
| <li><b>Commit message:</b> ${{ github.event.head_commit.message }}</li> | ||
| <li><b>Workflow:</b> ${{ github.workflow }}</li> | ||
| <li><b>Timestamp:</b> ${{ format(github.event.repository.updated_at, 'dddd, MMMM Do YYYY, h:mm:ss a') }}</li> | ||
| <li><b>Author:</b> ${{ github.actor }}</li> | ||
| <li><b>Run ID:</b> ${{ github.run_id }}</li> | ||
| <li><b>Run Number:</b> ${{ github.run_number }}</li> | ||
| </ul> | ||
| <h3>❌ Error Information</h3> | ||
| <p>Review the workflow logs for detailed error information.</p> | ||
| <h3>🔗 Quick Links</h3> | ||
| <p> | ||
| <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}">📋 View error logs and details</a><br> | ||
| <a href="${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}">💻 View commit details</a> | ||
| </p> | ||
| <hr> | ||
| <p style="color:#666;font-size:12px">This is an automated message from GitHub Actions. Please do not reply to this email.</p> | ||
| from: GitHub Actions <${{ secrets.MAIL_USERNAME }}> | ||
| to: ${{ secrets.MAIL_RECIPIENT }} | ||