Skip to content

Commit d0acd8a

Browse files
Update deploy.yml
1 parent b882d56 commit d0acd8a

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ on:
44
branches:
55
- Production
66
workflow_dispatch:
7-
87
permissions:
98
contents: write
10-
119
jobs:
1210
build:
1311
runs-on: ubuntu-latest
@@ -52,10 +50,25 @@ jobs:
5250
fi
5351
5452
- name: Build Angular app
53+
id: build
5554
run: |
5655
yarn build --configuration production --base-href="/${{ github.event.repository.name }}/" 2>&1 | tee deployment_logs/build_log_${{ steps.timestamp.outputs.timestamp }}.txt
56+
continue-on-error: true
57+
58+
- name: Check build status
59+
id: check_build
60+
run: |
61+
if [ "${{ steps.build.outcome }}" == "success" ]; then
62+
echo "build_status=success" >> $GITHUB_OUTPUT
63+
echo "Build completed successfully"
64+
else
65+
echo "build_status=failure" >> $GITHUB_OUTPUT
66+
echo "Build failed"
67+
exit 1
68+
fi
5769
5870
- name: Ensure docs directory exists
71+
if: steps.check_build.outputs.build_status == 'success'
5972
run: |
6073
if [ ! -d "docs" ]; then
6174
if [ -d "${{ steps.check_config.outputs.output_path }}" ]; then
@@ -71,9 +84,11 @@ jobs:
7184
fi
7285
7386
- name: Add .nojekyll file
87+
if: steps.check_build.outputs.build_status == 'success'
7488
run: touch docs/.nojekyll
7589

7690
- name: Deploy to GitHub Pages
91+
if: steps.check_build.outputs.build_status == 'success'
7792
id: deploy
7893
uses: JamesIves/github-pages-deploy-action@v4
7994
with:
@@ -82,14 +97,68 @@ jobs:
8297
clean: true
8398

8499
- name: Log deployment result
100+
if: always()
85101
run: |
86102
echo "Deployment completed at $(date)" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt
87103
echo "Commit: ${{ github.sha }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt
88-
echo "Deployment status: ${{ steps.deploy.outcome }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt
104+
echo "Build status: ${{ steps.check_build.outputs.build_status }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt
105+
if [ "${{ steps.check_build.outputs.build_status }}" == "success" ]; then
106+
echo "Deployment status: ${{ steps.deploy.outcome }}" >> deployment_logs/deploy_summary_${{ steps.timestamp.outputs.timestamp }}.txt
107+
fi
89108
90109
- name: Archive deployment logs
110+
if: always()
91111
uses: actions/upload-artifact@v4
92112
with:
93113
name: deployment-logs-${{ steps.timestamp.outputs.timestamp }}
94114
path: deployment_logs/
95115
retention-days: 30
116+
117+
- name: Send email notification on success
118+
if: success()
119+
uses: dawidd6/action-send-mail@v3
120+
with:
121+
server_address: ${{ secrets.MAIL_SERVER }}
122+
server_port: ${{ secrets.MAIL_PORT }}
123+
username: ${{ secrets.MAIL_USERNAME }}
124+
password: ${{ secrets.MAIL_PASSWORD }}
125+
subject: ✅ Successful Build and Deploy for ${{ github.repository }}
126+
body: |
127+
Build and deployment for ${{ github.repository }} completed successfully.
128+
129+
**Details:**
130+
- Repository: ${{ github.repository }}
131+
- Commit: ${{ github.sha }}
132+
- Commit message: ${{ github.event.head_commit.message }}
133+
- Workflow: ${{ github.workflow }}
134+
- Timestamp: $(date)
135+
136+
View the deployment: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/
137+
View workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
138+
from: GitHub Actions <${{ secrets.MAIL_USERNAME }}>
139+
to: ${{ secrets.MAIL_RECIPIENT }}
140+
content_type: text/html
141+
142+
- name: Send email notification on failure
143+
if: failure()
144+
uses: dawidd6/action-send-mail@v3
145+
with:
146+
server_address: ${{ secrets.MAIL_SERVER }}
147+
server_port: ${{ secrets.MAIL_PORT }}
148+
username: ${{ secrets.MAIL_USERNAME }}
149+
password: ${{ secrets.MAIL_PASSWORD }}
150+
subject: ❌ Failed Build for ${{ github.repository }}
151+
body: |
152+
Build or deployment for ${{ github.repository }} failed.
153+
154+
**Details:**
155+
- Repository: ${{ github.repository }}
156+
- Commit: ${{ github.sha }}
157+
- Commit message: ${{ github.event.head_commit.message }}
158+
- Workflow: ${{ github.workflow }}
159+
- Timestamp: $(date)
160+
161+
View logs and details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
162+
from: GitHub Actions <${{ secrets.MAIL_USERNAME }}>
163+
to: ${{ secrets.MAIL_RECIPIENT }}
164+
content_type: text/html

0 commit comments

Comments
 (0)