73 lines
2.2 KiB
YAML
73 lines
2.2 KiB
YAML
name: Deploy Portfolio
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
rm -rf * .git
|
|
git clone "https://code.chagarlamudi.net/raghu-ch/rc-portfolio.git" .
|
|
|
|
- name: Build Docker image
|
|
run: docker build -t rc-portfolio:latest .
|
|
|
|
- name: Stop old container
|
|
run: docker stop rc-portfolio || true
|
|
|
|
- name: Remove old container
|
|
run: docker rm rc-portfolio || true
|
|
|
|
- name: Run new container
|
|
run: |
|
|
docker run -d \
|
|
--name rc-portfolio \
|
|
--restart unless-stopped \
|
|
-p 8080:80 \
|
|
rc-portfolio:latest
|
|
|
|
- name: Clean up old images
|
|
run: docker image prune -f
|
|
|
|
- name: Install curl
|
|
run: |
|
|
if ! command -v curl >/dev/null 2>&1; then
|
|
if command -v apt >/dev/null 2>&1; then
|
|
sudo apt update && sudo apt install -y curl
|
|
elif command -v apk >/dev/null 2>&1; then
|
|
sudo apk add curl
|
|
elif command -v yum >/dev/null 2>&1; then
|
|
sudo yum install -y curl
|
|
fi
|
|
fi
|
|
|
|
- name: Set Discord mention
|
|
id: discord
|
|
run: |
|
|
echo "mention=<@${{ secrets.DISCORD_ID_RAGHU }}>" >> $GITEA_OUTPUT
|
|
|
|
# ✅ Success notification
|
|
- name: Discord Success Notification
|
|
if: success()
|
|
run: |
|
|
curl -X POST -H "Content-Type: application/json" \
|
|
-d "{
|
|
\"content\": \"✅ **Deployment SUCCESS**\n👤 ${{ steps.discord.outputs.mention }}\n📦 Repo: ${{ gitea.repository }}\n🌿 Branch: ${{ gitea.ref_name }}\"
|
|
}" \
|
|
${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
|
|
# ❌ Failure notification
|
|
- name: Discord Failure Notification
|
|
if: failure()
|
|
run: |
|
|
curl -X POST -H "Content-Type: application/json" \
|
|
-d "{
|
|
\"content\": \"❌ **Deployment FAILED**\n👤 ${{ steps.discord.outputs.mention }}\n📦 Repo: ${{ gitea.repository }}\n🌿 Branch: ${{ gitea.ref_name }}\n🔍 Check Gitea Actions logs\"
|
|
}" \
|
|
${{ secrets.DISCORD_WEBHOOK_URL }}
|