Skip to content

Build and Deploy

Build and Deploy #111

Workflow file for this run

name: Build and Deploy
on:
schedule:
- cron: '0 5 * * 0' # 仅周日凌晨5点触发
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write # 发布所需的权限
steps:
# 克隆上游仓库(保持与上游同步的关键修改)
- name: Clone Upstream Repository
run: git clone --branch master https://github.com/PlayPro/CoreProtect ./external-coreprotect
# 修改上游的 pom.xml
- name: Patch pom.xml
working-directory: ./external-coreprotect
run: |
# 修改版本号和分支参数
sed -i '5s|<version>[^<]*</version>|<version>23.4-dev</version>|' pom.xml
sed -i '7s|<project.branch></project.branch>|<project.branch>development</project.branch>|' pom.xml
cat pom.xml # 验证修改
# 设置 Java 环境
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
# Maven 依赖缓存(路径与上游统一)
- name: Cache Maven packages
uses: actions/cache@v4 # 升级到 v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('external-coreprotect/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-
# Maven 构建
- name: Build with Maven
run: mvn -B verify
working-directory: ./external-coreprotect
# 设置日期和短 SHA 作为标签名
- name: Set date and short sha as tag name
id: set_tag
run: |
DATE=$(date +'%y%m%d-%H%M') # 修改日期格式为 yyMMdd-HHmm
echo "TAG_NAME=build-$DATE" >> $GITHUB_ENV # 添加前缀 build-
echo "Generated Tag: ${{ env.TAG_NAME }}"
# 构建后的验证步骤(精确检查两个文件)
- name: Verify Artifacts
run: |
ls -la ./external-coreprotect/target/
# 检查核心文件是否存在(泛匹配 CoreProtect-x.x.jar)
if ! ls ./external-coreprotect/target/CoreProtect-*.jar; then
echo "::error::CoreProtect-*.jar not found"
exit 1
fi
echo "Required JAR files exist"
# 发布文件
- name: Auto Release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: ${{ env.TAG_NAME }}
prerelease: false
files: ./external-coreprotect/target/*.jar