Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
KhunHtetzNaing committed Dec 22, 2024
0 parents commit 7b14b9e
Show file tree
Hide file tree
Showing 21 changed files with 1,178 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOT_TOKEN=7672104553:AAH_RwwDpuJlMu9smaFjXQid7xJQVmfxVNs
50 changes: 50 additions & 0 deletions .github/workflows/backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Database Backup

on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
workflow_dispatch: # Allow manual trigger

env:
WORKING_DIRECTORY: backup

jobs:
backup:
runs-on: ubuntu-22.04

steps:
- name: Setup SSH
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: '${{ secrets.SSH_PRIVATE_KEY }}'

- name: Add SSH known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Download database file
run: |
# Create directory with timestamp
timestamp=$(date +%Y%m%d_%H%M%S)
target_directory=$WORKING_DIRECTORY
mkdir -p "$target_directory" || {
echo "Failed to create directory $target_directory"
exit 1
}
timestamp=$(date +%Y%m%d_%H%M%S)
echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV
mkdir -p "${{ env.WORKING_DIRECTORY }}" || {
echo "Failed to create directory ${{ env.WORKING_DIRECTORY }}"
exit 1
}
# Download db files directly to timestamped directory
rsync -avz ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:~/bot/*.db "${{ env.WORKING_DIRECTORY }}"
- name: Upload backup
uses: actions/upload-artifact@v4
with:
name: database-backup-${{ env.TIMESTAMP }}
path: ${{ env.WORKING_DIRECTORY }}
75 changes: 75 additions & 0 deletions .github/workflows/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Deploy Bot On Server

on:
release:
types:
- published
workflow_dispatch: # Allow manual trigger

jobs:
deploy:
runs-on: ubuntu-latest
environment: production # Added for better secrets management

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup SSH
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: '${{ secrets.SSH_PRIVATE_KEY }}'

- name: Add SSH known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Create env file
run: |
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > .env
- name: Create backup directory
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} '
timestamp=$(date +%Y%m%d_%H%M%S)
if [ -d ~/bot ]; then
rsync -av --progress --exclude="__pycache__/" \
--exclude="env/" \
~/bot/ ~/bot_backup_$timestamp && echo "Backup done" || echo "Backup failed"
else
echo "No need to backup!"
fi
'
- name: Transfer files to server
run: |
rsync -avz --exclude '.git*' \
--exclude '.idea/' \
./ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:~/bot/
- name: Deploy and verify
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} '
cd ~/bot || exit 1
# Ensure deploy.sh exists and is executable
if [ ! -f "deploy.sh" ]; then
echo "Error: deploy.sh not found!"
exit 1
fi
# Set permissions
chmod +x deploy.sh
# Run deploy script with error handling
if sudo ./deploy.sh; then
echo "Deployment completed successfully at $(date)"
else
echo "Deployment failed"
# Optional: Restore from backup
# latest_backup=$(ls -td ~/bot_backup_* | head -n1)
# cp -r $latest_backup/* ~/bot/
exit 1
fi
'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alerts.db
.env
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/crypto_alert_dca.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b14b9e

Please sign in to comment.