Build and Deploy #58
This file contains hidden or 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: Daily Build and Deploy | |
| on: | |
| schedule: | |
| - cron: '0 5 * * 2,4,6' # 每周二、四、六凌晨5点触发 | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # 发布所需的权限 | |
| steps: | |
| # 克隆当前仓库(如果需要访问当前仓库内容) | |
| - name: Checkout Current Repository | |
| uses: actions/checkout@v4 | |
| # 克隆上游仓库(保持与上游同步的关键修改) | |
| - 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>22.4</version>|<version>23.0</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: | | |
| SHORT_SHA=${GITHUB_SHA::7} | |
| DATE=$(date +'%Y-%m-%d') | |
| echo "TAG_NAME=${DATE}-${SHORT_SHA}" >> $GITHUB_ENV | |
| echo "Generated Tag: ${{ env.TAG_NAME }}" | |
| # 构建后的验证步骤(精确检查两个文件) | |
| - name: Verify Artifacts | |
| run: | | |
| ls -la ./external-coreprotect/target/ | |
| # 检查核心文件是否存在 | |
| if [ ! -f ./external-coreprotect/target/CoreProtect-23.0.jar ]; then | |
| echo "::error::CoreProtect-23.0.jar not found" | |
| exit 1 | |
| fi | |
| # 检查原始文件是否存在 | |
| if [ ! -f ./external-coreprotect/target/original-CoreProtect-23.0.jar ]; then | |
| echo "::error::original-CoreProtect-23.0.jar not found" | |
| exit 1 | |
| fi | |
| echo "Both 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 |