Merge remote-tracking branch 'origin/main' #46
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: Java CI/CD with Docker Compose | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Set up JDK 22 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'adopt' | |
| java-version: '22' | |
| - name: Cache Maven packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Build with Maven | |
| run: mvn -B package --file pom.xml | |
| env: | |
| BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| - name: Run tests | |
| run: mvn test | |
| env: | |
| BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| - name: Verify target directory exists after build | |
| run: ls -la target/ | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: build-artifacts | |
| path: target/ | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Set up SSH | |
| uses: webfactory/[email protected] | |
| with: | |
| ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| - name: Add known hosts | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.SERVER_IP }} $(ssh-keyscan -H ${{ secrets.SERVER_IP }} 2>/dev/null)" >> ~/.ssh/known_hosts | |
| - name: Deploy to server | |
| env: | |
| BOT_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| GPT_TOKEN: ${{ secrets.GPT_TOKEN }} | |
| SERVER_IP: ${{ secrets.SERVER_IP }} | |
| SERVER_USER: ${{ secrets.SERVER_USER }} | |
| run: | | |
| ssh $SERVER_USER@$SERVER_IP << 'EOF' | |
| if [ -d "Automating-route-selection" ]; then | |
| cd Automating-route-selection | |
| git pull origin main | |
| else | |
| git clone https://github.com/Dema-koder/Automating-route-selection.git | |
| cd Automating-route-selection | |
| fi | |
| # Создаем .env файл с секретами | |
| echo "BOT_TOKEN=$BOT_TOKEN" > .env | |
| echo "GPT_TOKEN=$GPT_TOKEN" >> .env | |
| # Запускаем приложение | |
| docker-compose down | |
| docker-compose up -d --build | |
| EOF |