This file contains 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: Build project and publish to server | ||
on: | ||
push: | ||
branches: [ "master" ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
- name: Build project with Maven | ||
run: mvn clean package -DskipTests | ||
- name: List target directory with artifacts | ||
run: ls -la target/ | ||
- name: Copy modules to remote server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USER }} | ||
key: ${{ secrets.SSH_KEY }} | ||
port: 22 | ||
script: | | ||
ls -la target/*.jar # Verify the jar file exists | ||
scp target/*.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/deploy/artifacts/app.jar | ||
- name: Restart service | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USER }} | ||
key: ${{ secrets.SSH_KEY }} | ||
port: 22 | ||
script: | | ||
docker-compose -f /deploy/docker-compose.yml restart app |