Skip to content

Commit 08a7ae4

Browse files
committed
deploy
1 parent e33764e commit 08a7ae4

4 files changed

Lines changed: 649 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Deploy to Oracle Cloud
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
types: [closed]
8+
branches: [main, master]
9+
release:
10+
types: [published]
11+
workflow_dispatch:
12+
13+
env:
14+
SSH_HOST: ${{ secrets.SSH_HOST }}
15+
SSH_USER: ${{ secrets.SSH_USER }}
16+
SSH_PORT: ${{ secrets.SSH_PORT }}
17+
REMOTE_PATH: ${{ secrets.REMOTE_PATH }}
18+
19+
jobs:
20+
deploy:
21+
runs-on: ubuntu-latest
22+
if: |
23+
github.event_name == 'workflow_dispatch' ||
24+
github.event_name == 'release' ||
25+
(github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) ||
26+
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Setup SSH
35+
env:
36+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
37+
run: |
38+
mkdir -p ~/.ssh
39+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy_key
40+
chmod 600 ~/.ssh/deploy_key
41+
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
42+
43+
- name: Verify SSH connection
44+
run: |
45+
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST "echo 'SSH connection successful'"
46+
47+
- name: Detect Python version on remote
48+
id: python-version
49+
run: |
50+
PYTHON_VERSION=$(ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST "python3 --version" 2>&1)
51+
echo "version=$PYTHON_VERSION" >> $GITHUB_OUTPUT
52+
echo "Python version on remote: $PYTHON_VERSION"
53+
54+
- name: Check if requirements.txt changed
55+
id: requirements-check
56+
run: |
57+
if [ "${{ github.event_name }}" == "push" ]; then
58+
git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q "^requirements.txt$" && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT
59+
echo "requirements.txt changed: ${{ steps.requirements-check.outputs.changed }}"
60+
else
61+
echo "changed=true" >> $GITHUB_OUTPUT
62+
echo "Forcing dependency install (not a push event)"
63+
fi
64+
65+
- name: Sync files to server
66+
run: |
67+
rsync -avz --delete \
68+
-e "ssh -i ~/.ssh/deploy_key -p $SSH_PORT" \
69+
--exclude='.git/' \
70+
--exclude='.github/' \
71+
--exclude='.gitignore' \
72+
--exclude='tests/' \
73+
--exclude='data/' \
74+
--exclude='saved_data/' \
75+
--exclude='saved_pages/' \
76+
--exclude='csv_downloads/' \
77+
--exclude='__pycache__/' \
78+
--exclude='*.pyc' \
79+
--exclude='*.pyo' \
80+
--exclude='*.pyd' \
81+
--exclude='*.egg-info/' \
82+
--exclude='dist/' \
83+
--exclude='build/' \
84+
--exclude='.pytest_cache/' \
85+
--exclude='.mypy_cache/' \
86+
--exclude='.DS_Store' \
87+
--exclude='venv/' \
88+
--exclude='*.db' \
89+
--exclude='*.json' \
90+
--exclude='src/__pycache__/' \
91+
--exclude='src/csv_downloads/' \
92+
--exclude='src/plombery/config/config.ini' \
93+
./ $SSH_USER@$SSH_HOST:$REMOTE_PATH/
94+
95+
- name: Verify file sync
96+
run: |
97+
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST "cd $REMOTE_PATH && ls -la src/ | head -20"
98+
99+
- name: Install dependencies (if requirements.txt changed)
100+
if: steps.requirements-check.outputs.changed == 'true'
101+
run: |
102+
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST \
103+
"cd $REMOTE_PATH && \
104+
if [ -d venv ]; then \
105+
source venv/bin/activate && \
106+
echo 'Upgrading pip...' && \
107+
pip install --upgrade pip && \
108+
echo 'Installing dependencies...' && \
109+
pip install -r requirements.txt && \
110+
echo 'Dependencies installed successfully'; \
111+
else \
112+
echo 'ERROR: Virtual environment not found at $REMOTE_PATH/venv'; \
113+
exit 1; \
114+
fi"
115+
116+
- name: Verify Python environment
117+
run: |
118+
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST \
119+
"cd $REMOTE_PATH && \
120+
source venv/bin/activate && \
121+
echo 'Python: \$(python3 --version)' && \
122+
echo 'Pip: \$(pip --version)' && \
123+
echo 'Installed packages: \$(pip list | wc -l)'"
124+
125+
- name: Check plombery status
126+
run: |
127+
ssh -i ~/.ssh/deploy_key -p $SSH_PORT $SSH_USER@$SSH_HOST \
128+
"cd $REMOTE_PATH && \
129+
source venv/bin/activate && \
130+
echo 'Plombery version:' && \
131+
plombery --version || echo 'Plombery not found in PATH'"
132+
133+
- name: Deployment summary
134+
run: |
135+
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
136+
echo "" >> $GITHUB_STEP_SUMMARY
137+
echo "**Target Server:** \`$SSH_USER@$SSH_HOST:$REMOTE_PATH\`" >> $GITHUB_STEP_SUMMARY
138+
echo "**Python Version:** ${{ steps.python-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
139+
echo "**Dependencies Updated:** ${{ steps.requirements-check.outputs.changed }}" >> $GITHUB_STEP_SUMMARY
140+
echo "**Files Synced:** Completed" >> $GITHUB_STEP_SUMMARY
141+
echo "" >> $GITHUB_STEP_SUMMARY
142+
echo "### Deployment successful!" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)