add GitHub Actions workflow for building and releasing the project #1
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: Build and Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: 设置 Java 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| cache: 'gradle' | |
| - name: 授予 Gradle 执行权限 | |
| run: chmod +x gradlew | |
| - name: 构建项目并生成 ShadowJar | |
| run: ./gradlew :plugin-runner:shadowJar --no-daemon | |
| - name: 验证构建产物 | |
| run: | | |
| if [ -f plugin-runner/build/libs/nukkit-addon-bridge.jar ]; then | |
| echo "✓ 构建产物已生成" | |
| ls -lh plugin-runner/build/libs/nukkit-addon-bridge.jar | |
| else | |
| echo "✗ 构建产物未找到" | |
| exit 1 | |
| fi | |
| - name: 上传构建产物 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nukkit-addon-bridge | |
| path: plugin-runner/build/libs/nukkit-addon-bridge.jar | |
| if-no-files-found: error | |
| - name: 上传到 Release(仅标签推送) | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: plugin-runner/build/libs/nukkit-addon-bridge.jar | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |