Skip to content

Commit 60046e1

Browse files
committed
Fix deploy workflow and create staging/main branches
- develop: auto-deploy to dev.shellmate.sh - staging: auto-deploy to staging.shellmate.sh - main: auto-deploy to production shellmate.sh Proper CI/CD flow: 1. Feature branch → PR to develop → CI tests → merge → deploy dev 2. develop → PR to staging → deploy staging 3. staging → PR to main → deploy production
1 parent f530484 commit 60046e1

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

.github/workflows/deploy.yml

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,62 @@ name: Deploy
22

33
on:
44
push:
5-
branches: [main, develop, staging]
6-
workflow_dispatch:
7-
inputs:
8-
environment:
9-
description: 'Environment to deploy to'
10-
required: true
11-
default: 'dev'
12-
type: choice
13-
options:
14-
- dev
15-
- staging
16-
- production
5+
branches: [main, staging, develop]
6+
7+
env:
8+
SERVER_IP: "46.225.26.166"
9+
SSH_PORT: "2222"
1710

1811
jobs:
1912
deploy:
2013
runs-on: ubuntu-latest
21-
needs: []
22-
environment:
23-
name: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/staging' && 'staging' || 'dev' }}
24-
url: ${{ github.ref == 'refs/heads/main' && 'https://shellmate.sh' || github.ref == 'refs/heads/staging' && 'https://staging.shellmate.sh' || 'https://dev.shellmate.sh' }}
14+
if: github.event_name == 'push'
2515

2616
steps:
2717
- uses: actions/checkout@v4
2818

29-
- name: Set environment variables
19+
- name: Determine environment
3020
id: env
3121
run: |
3222
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
33-
echo "env_name=production" >> $GITHUB_OUTPUT
34-
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
35-
echo "ssh_port=22" >> $GITHUB_OUTPUT
23+
echo "name=production" >> $GITHUB_OUTPUT
24+
echo "url=https://shellmate.sh" >> $GITHUB_OUTPUT
25+
echo "ssh_user=play" >> $GITHUB_OUTPUT
3626
elif [[ "${{ github.ref }}" == "refs/heads/staging" ]]; then
37-
echo "env_name=staging" >> $GITHUB_OUTPUT
38-
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
39-
echo "ssh_port=2223" >> $GITHUB_OUTPUT
27+
echo "name=staging" >> $GITHUB_OUTPUT
28+
echo "url=https://staging.shellmate.sh" >> $GITHUB_OUTPUT
29+
echo "ssh_user=play" >> $GITHUB_OUTPUT
4030
else
41-
echo "env_name=dev" >> $GITHUB_OUTPUT
42-
echo "ssh_host=shellmate.sh" >> $GITHUB_OUTPUT
43-
echo "ssh_port=2222" >> $GITHUB_OUTPUT
31+
echo "name=dev" >> $GITHUB_OUTPUT
32+
echo "url=https://dev.shellmate.sh" >> $GITHUB_OUTPUT
33+
echo "ssh_user=play" >> $GITHUB_OUTPUT
4434
fi
4535
46-
- name: Deploy to ${{ steps.env.outputs.env_name }}
47-
uses: appleboy/ssh-action@v1.0.3
48-
with:
49-
host: ${{ steps.env.outputs.ssh_host }}
50-
username: root
51-
key: ${{ secrets.DEPLOY_SSH_KEY }}
52-
port: ${{ steps.env.outputs.ssh_port }}
53-
script: |
36+
- name: Setup SSH
37+
run: |
38+
mkdir -p ~/.ssh
39+
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
40+
chmod 600 ~/.ssh/deploy_key
41+
ssh-keyscan -p ${{ env.SSH_PORT }} ${{ env.SERVER_IP }} >> ~/.ssh/known_hosts 2>/dev/null || true
42+
43+
- name: Deploy to ${{ steps.env.outputs.name }}
44+
run: |
45+
ssh -i ~/.ssh/deploy_key -p ${{ env.SSH_PORT }} -o StrictHostKeyChecking=no root@${{ env.SERVER_IP }} << 'ENDSSH'
5446
cd /opt/shellmate
5547
git fetch origin
5648
git checkout ${{ github.ref_name }}
5749
git pull origin ${{ github.ref_name }}
5850
docker compose up -d --build
59-
echo "Deployed ${{ github.ref_name }} to ${{ steps.env.outputs.env_name }}"
51+
echo "✅ Deployed ${{ github.ref_name }} to ${{ steps.env.outputs.name }}"
52+
ENDSSH
6053
61-
- name: Deployment summary
54+
- name: Summary
6255
run: |
63-
echo "## Deployment Complete 🚀" >> $GITHUB_STEP_SUMMARY
56+
echo "## 🚀 Deployment Complete" >> $GITHUB_STEP_SUMMARY
6457
echo "" >> $GITHUB_STEP_SUMMARY
65-
echo "- **Environment:** ${{ steps.env.outputs.env_name }}" >> $GITHUB_STEP_SUMMARY
66-
echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
67-
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
58+
echo "| | |" >> $GITHUB_STEP_SUMMARY
59+
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
60+
echo "| **Environment** | ${{ steps.env.outputs.name }} |" >> $GITHUB_STEP_SUMMARY
61+
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
62+
echo "| **URL** | ${{ steps.env.outputs.url }} |" >> $GITHUB_STEP_SUMMARY
63+
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)