78 lines
2.0 KiB
YAML
78 lines
2.0 KiB
YAML
name: 构建和部署Spring Boot应用程序
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
pull_request:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: 检出代码库
|
|
uses: actions/checkout@v3
|
|
|
|
- name: 设置JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: "17"
|
|
distribution: "temurin"
|
|
- name: 缓存Maven包
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.m2/repository
|
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-maven-
|
|
|
|
- name: 安装依赖
|
|
run: ./mvnw install -DskipTests
|
|
|
|
- name: 运行测试
|
|
run: ./mvnw test
|
|
|
|
- name: 打包应用程序
|
|
run: ./mvnw package -DskipTests
|
|
|
|
- name: 上传构件
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: spring-boot-app
|
|
path: |
|
|
target/jinduguanli-0.0.1-SNAPSHOT.jar
|
|
src/main/resources/application.yml
|
|
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: 下载构件
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: spring-boot-app
|
|
path: target/
|
|
|
|
- name: 通过scp复制文件
|
|
uses: appleboy/scp-action@v0.1.1
|
|
with:
|
|
host: ${{ secrets.REMOTE_HOST }}
|
|
username: ${{ secrets.REMOTE_USER }}
|
|
key: ${{ secrets.REMOTE_SSH_KEY }}
|
|
source: |
|
|
target/jinduguanli-0.0.1-SNAPSHOT.jar
|
|
src/main/resources/application.yml
|
|
target: "/huertian/"
|
|
|
|
- name: 通过ssh执行远程命令
|
|
uses: appleboy/ssh-action@v0.1.8
|
|
with:
|
|
host: ${{ secrets.REMOTE_HOST }}
|
|
username: ${{ secrets.REMOTE_USER }}
|
|
key: ${{ secrets.REMOTE_SSH_KEY }}
|
|
script: |
|
|
cd /huertian/
|
|
java -jar jinduguanli-0.0.1-SNAPSHOT.jar --spring.config.location=application.yml
|