Develop #69
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: Spring Boot CI/CD | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: ["main"] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| if: github.event.pull_request.merged == true | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Create configuration | |
| run: | | |
| mkdir -p src/main/resources | |
| echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application.yml | |
| echo "Configuration file created successfully" | |
| ls -la src/main/resources/ | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build | |
| run: ./gradlew clean build -x test | |
| - name: Copy to EC2 | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_KEY }} | |
| source: "build/libs/*.jar" | |
| target: "/home/ubuntu" | |
| - name: Restart App | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_KEY }} | |
| script: | | |
| sudo systemctl daemon-reload | |
| sudo systemctl restart mylog.service |