XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

MyDimension

【Java】我的维度模组

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/MyDimension

优化构建并新增手动发布流程

a817fcb
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

2 个文件 +134 -19
Modified .github/workflows/build.yml +31 -19
@@ -1,30 +1,42 @@
1 # Automatically build the project and run any configured tests for every push
2 # and submitted pull request. This can help catch issues that only occur on
3 # certain platforms or Java versions, and provides a first line of defence
4 # against bad commits.
1 name: 推送编译校验
5 2
6 name: build
7 on: [pull_request, push]
3 on:
4 push:
5
6 permissions:
7 contents: read
8
9 concurrency:
10 group: build-${{ github.ref }}
11 cancel-in-progress: true
8 12
9 13 jobs:
10 14 build:
11 runs-on: ubuntu-24.04
15 name: Windows / Java 17
16 runs-on: windows-latest
17 timeout-minutes: 45
18
12 19 steps:
13 - name: checkout repository
20 - name: 检出代码
14 21 uses: actions/checkout@v6
15 - name: validate gradle wrapper
16 uses: gradle/actions/wrapper-validation@v6
17 - name: setup jdk
22
23 - name: 配置 Java 17
18 24 uses: actions/setup-java@v5
19 25 with:
26 distribution: microsoft
20 27 java-version: '17'
21 distribution: 'microsoft'
22 - name: make gradle wrapper executable
23 run: chmod +x ./gradlew
24 - name: build
25 run: ./gradlew build
26 - name: capture build artifacts
28
29 - name: 配置 Gradle
30 uses: gradle/actions/setup-gradle@v6
31
32 - name: 编译并校验
33 shell: pwsh
34 run: .\gradlew.bat --no-daemon "-Dorg.gradle.java.home=$env:JAVA_HOME" build
35
36 - name: 保存构建产物
27 37 uses: actions/upload-artifact@v7
28 38 with:
29 name: Artifacts
30 path: build/libs/
39 name: mydimension-${{ github.sha }}
40 path: build/libs/*.jar
41 if-no-files-found: error
42 retention-days: 7
Added .github/workflows/release.yml +103 -0
@@ -0,0 +1,103 @@
1 name: 手动发布
2
3 on:
4 workflow_dispatch:
5 inputs:
6 prerelease:
7 description: 标记为预发布版本
8 required: true
9 default: false
10 type: boolean
11
12 permissions:
13 contents: write
14
15 concurrency:
16 group: release
17 cancel-in-progress: false
18
19 jobs:
20 release:
21 name: Windows / Java 17
22 runs-on: windows-latest
23 timeout-minutes: 45
24
25 steps:
26 - name: 检出代码和标签
27 uses: actions/checkout@v6
28 with:
29 fetch-depth: 0
30
31 - name: 配置 Java 17
32 uses: actions/setup-java@v5
33 with:
34 distribution: microsoft
35 java-version: '17'
36
37 - name: 配置 Gradle
38 uses: gradle/actions/setup-gradle@v6
39
40 - name: 读取并校验版本号
41 id: version
42 shell: pwsh
43 run: |
44 $versionLine = Get-Content gradle.properties |
45 Where-Object { $_ -match '^mod_version=' } |
46 Select-Object -First 1
47
48 if (-not $versionLine) {
49 throw 'gradle.properties 中缺少 mod_version'
50 }
51
52 $version = ($versionLine -split '=', 2)[1].Trim()
53 if ([string]::IsNullOrWhiteSpace($version)) {
54 throw 'gradle.properties 中的 mod_version 不能为空'
55 }
56
57 $tag = "v$version"
58 if (git tag --list $tag) {
59 throw "标签 $tag 已存在,请先更新 mod_version"
60 }
61
62 "version=$version" >> $env:GITHUB_OUTPUT
63 "tag=$tag" >> $env:GITHUB_OUTPUT
64
65 - name: 构建发布 JAR
66 shell: pwsh
67 run: .\gradlew.bat --no-daemon "-Dorg.gradle.java.home=$env:JAVA_HOME" clean build
68
69 - name: 创建 GitHub Release
70 shell: pwsh
71 env:
72 GH_TOKEN: ${{ github.token }}
73 RELEASE_TAG: ${{ steps.version.outputs.tag }}
74 IS_PRERELEASE: ${{ inputs.prerelease }}
75 run: |
76 $artifacts = @(
77 Get-ChildItem build/libs/*.jar -File |
78 Where-Object { $_.Name -notmatch '-(sources|javadoc)\.jar$' }
79 )
80
81 if ($artifacts.Count -eq 0) {
82 throw 'build/libs 中没有可发布的 JAR'
83 }
84
85 $arguments = @(
86 'release', 'create', $env:RELEASE_TAG
87 )
88 $arguments += $artifacts.FullName
89 $arguments += @(
90 '--repo', $env:GITHUB_REPOSITORY,
91 '--target', $env:GITHUB_SHA,
92 '--title', "MyDimension $env:RELEASE_TAG",
93 '--generate-notes'
94 )
95
96 if ($env:IS_PRERELEASE -eq 'true') {
97 $arguments += '--prerelease'
98 }
99
100 & gh @arguments
101 if ($LASTEXITCODE -ne 0) {
102 throw "创建 GitHub Release 失败,gh 退出码为 $LASTEXITCODE"
103 }