74 lines
1.8 KiB
YAML
74 lines
1.8 KiB
YAML
name: Build and Deploy Spring Boot Application
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
pull_request:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Check out the repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: "17"
|
|
|
|
- name: Cache Maven packages
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.m2/repository
|
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-maven-
|
|
|
|
- name: Install dependencies
|
|
run: mvn install -DskipTests
|
|
|
|
- name: Run tests
|
|
run: mvn test
|
|
|
|
- name: Package application
|
|
run: mvn package -DskipTests
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: spring-boot-app
|
|
path: target/*.jar
|
|
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Download artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: spring-boot-app
|
|
path: target/
|
|
|
|
- name: Copy file via scp
|
|
uses: appleboy/scp-action@v0.1.1
|
|
with:
|
|
host: ${{ secrets.REMOTE_HOST }}
|
|
username: ${{ secrets.REMOTE_USER }}
|
|
key: ${{ secrets.REMOTE_SSH_KEY }}
|
|
source: "target/*.jar"
|
|
target: "/path/to/deploy/directory/"
|
|
|
|
- name: Execute remote command via ssh
|
|
uses: appleboy/ssh-action@v0.1.8
|
|
with:
|
|
host: ${{ secrets.REMOTE_HOST }}
|
|
username: ${{ secrets.REMOTE_USER }}
|
|
key: ${{ secrets.REMOTE_SSH_KEY }}
|
|
script: |
|
|
cd /path/to/deploy/directory/
|
|
java -jar your-spring-boot-app.jar
|