jinduguanli/.gitea/workflows/deploy.yml
huertian 0e395fef32
Some checks failed
自动部署 Spring Boot 项目到 CentOS 🚀 / deploy (push) Failing after 24s
测试
2025-01-08 20:06:20 +08:00

65 lines
1.8 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 自动部署 Spring Boot 项目到 CentOS 🚀
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# 1⃣ 检出代码
- name: 🛠️ 检出代码
uses: actions/checkout@v3
# 2⃣ 设置 Java 环境
- name: ☕ 设置 Java 环境
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
# 3⃣ 构建 Spring Boot 项目
- name: 📦 构建 Spring Boot 项目
run: |
./mvnw clean package -DskipTests
ls -lh target/
# 4⃣ 获取 JAR 文件路径
- name: 获取 JAR 文件路径
id: jar_path
run: echo "JAR_FILE=$(ls target/*.jar)" >> $GITHUB_ENV
# 5⃣ 确保目标目录存在
- name: 🗂️ 确保远程路径
run: ssh root@8.137.89.177 "mkdir -p /huertian && chmod 755 /huertian"
# 6⃣ 上传和部署
- name: 🚀 部署到服务器
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
echo "$DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H 8.137.89.177 >> ~/.ssh/known_hosts
# 上传文件
scp ${{ env.JAR_FILE }} root@8.137.89.177:/huertian/app.jar
# 校验文件完整性
ssh root@8.137.89.177 "sha256sum /huertian/app.jar"
# 重启服务
ssh root@8.137.89.177 << 'EOF'
cd /huertian
pkill -f 'java -jar' || true
nohup java -jar app.jar --spring.config.location=/huertian/application.yml >> /huertian/log/app_$(date +%F).log 2>&1 &
exit
EOF
# 7⃣ 检查启动日志
- name: 检查启动日志
run: ssh root@8.137.89.177 "tail -n 20 /huertian/log/app_$(date +%F).log"