diff --git a/.gitea/workflows/sgeupdated.yml b/.gitea/workflows/sgeupdated.yml index 20252f0..bb340db 100644 --- a/.gitea/workflows/sgeupdated.yml +++ b/.gitea/workflows/sgeupdated.yml @@ -1,106 +1,50 @@ +# .gitea/workflows/sgeupdated.yml name: sgeUpdated CI/CD on: push: branches: - main + workflow_dispatch: jobs: deploy: - # 'ubuntu-latest' is a common name for runners. - # Check with your Gitea admin if you have a different runner tag. runs-on: ubuntu-latest - + steps: - # Gitea automatically checks out your code, so we don't need 'actions/checkout' - - - name: Setup SSH - run: | - # Create the .ssh directory - mkdir -p ~/.ssh/ - - # Add your private key (from Gitea secrets) - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - - # Add your server's host key to known_hosts to avoid the 'yes/no' prompt - # This is a critical step for automation - ssh-keyscan ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts - - - name: Deploy to Server - # This command runs the entire script on your remote server - run: | - ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF' - # Start of remote script + - name: 🚀 Deploy to Bgreen Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | set -euo pipefail - - echo "✅ Connected to server. Navigating to project..." + + echo "🔄 Updating repository..." cd /home/ubuntu/Bgreen/sgeUpdated - - # 1. Fetch the latest code - git fetch origin main - - # 2. See what files changed between your current version (HEAD) and the new one (origin/main) - # We add '|| true' in case there are no diffs, which would stop 'set -e' - CHANGED_FILES=$(git diff --name-only HEAD origin/main) || true - - if [ -z "$CHANGED_FILES" ]; then - echo "No file changes detected between HEAD and origin/main." - else - echo "ðŸŠķ Changed files:" - echo "$CHANGED_FILES" - fi - - # 3. Update the local repository to the new version - git reset --hard origin/main - - BACKEND_CHANGED=false - FRONTEND_CHANGED=false - - # 4. Check for backend changes (Note the corrected path: no 'sgeUpdated/') - if echo "$CHANGED_FILES" | grep -q "^sge-backend/"; then - BACKEND_CHANGED=true - fi - - # 5. Check for frontend changes (Note the corrected path: no 'sgeUpdated/') - if echo "$CHANGED_FILES" | grep -q "^sge-frontend/"; then - FRONTEND_CHANGED=true - fi - - - # Backend section - if [ "$BACKEND_CHANGED" = true ]; then - echo "⚡ Backend changes detected. Rebuilding backend..." - cd sge-backend - echo "Running Maven build..." + git fetch myfork main + git reset --hard myfork/main + + echo "ðŸ“Ķ Installing backend dependencies..." + cd /home/ubuntu/Bgreen/sgeUpdated/sge-backend + if [ -f "pom.xml" ]; then /opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests - cd .. - echo "Rebuilding backend Docker container..." - docker compose up -d --build bgreen-backend else - echo "✅ No backend changes." + echo "⚠ïļ No pom.xml found, skipping Maven build" fi - - # Frontend section - if [ "$FRONTEND_CHANGED" = true ]; then - echo "⚡ Frontend changes detected. Rebuilding frontend..." - cd sge-frontend - echo "Running npm install and build..." + + echo "ðŸ“Ķ Installing frontend dependencies..." + cd /home/ubuntu/Bgreen/sgeUpdated/sge-frontend + if [ -f "package.json" ]; then npm install npm run build - cd .. - echo "Rebuilding frontend Docker container..." - docker compose up -d --build bgreen-frontend else - echo "✅ No frontend changes." + echo "⚠ïļ No package.json found, skipping frontend build" fi - - # This is your final 'build all' condition - # if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then - # echo "â™ŧïļ No source changes detected. Ensuring all containers are up." - # docker compose up -d - # fi - - echo "✅ Deployment script finished." - EOF - # End of remote script + + echo "ðŸģ Rebuilding backend container..." + cd /home/ubuntu/Bgreen + docker compose up -d --build bgreen-backend + + echo "✅ Deployment complete!"