This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Backend CI/CD | |
| on: | |
| push: | |
| branches: [main, develop] | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/backend-ci.yml" | |
| pull_request: | |
| branches: [main, develop] | |
| paths: | |
| - "backend/**" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| - name: Build with Gradle | |
| working-directory: backend | |
| run: ./gradlew build -x test | |
| - name: Run tests | |
| working-directory: backend | |
| run: ./gradlew test --info | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: backend-test-results | |
| path: backend/build/reports/tests/ | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/deploy_key | |
| chmod 600 ~/.ssh/deploy_key | |
| ssh-keyscan -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy to VPS | |
| run: | | |
| ssh -i ~/.ssh/deploy_key ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF' | |
| cd ${{ secrets.VPS_DEPLOY_PATH }}/backend | |
| git pull origin main | |
| ./gradlew build -x test | |
| docker-compose -f ../docker-compose.yml up -d backend | |
| EOF |