Skip to content

Commit f648f68

Browse files
authored
Update main.yml
1 parent ba27490 commit f648f68

1 file changed

Lines changed: 38 additions & 39 deletions

File tree

.github/workflows/main.yml

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,105 +24,104 @@ on:
2424
options:
2525
- '单个'
2626
- '多个'
27+
create_release:
28+
description: '是否创建 GitHub Release'
29+
required: true
30+
default: 'true'
31+
type: choice
32+
options:
33+
- 'true'
34+
- 'false'
2735

2836
jobs:
2937
Make:
3038
runs-on: ubuntu-latest
3139
env:
3240
WORKSPACE: ${{ github.workspace }}
41+
BUILD_DATE: $(date +'%Y%m%d')
3342
steps:
3443
- name: 检出当前仓库
3544
uses: actions/checkout@v4
3645

3746
- name: 准备环境
3847
run: |
39-
# 创建工作区目录
40-
mkdir -p source_repo
41-
mkdir -p patches
48+
mkdir -p source_repo patches
4249
echo "工作区路径: $WORKSPACE"
43-
echo "准备完成"
4450
4551
- name: 克隆源仓库
4652
run: |
47-
echo "正在克隆源仓库到: $WORKSPACE/source_repo"
4853
cd "$WORKSPACE/source_repo"
49-
5054
if [ -n "${{ github.event.inputs.branch }}" ]; then
51-
echo "克隆分支: ${{ github.event.inputs.branch }}"
5255
git clone --depth 100 --single-branch --branch "${{ github.event.inputs.branch }}" "${{ github.event.inputs.repo_url }}" .
5356
else
54-
echo "克隆默认分支"
5557
git clone --depth 100 --single-branch "${{ github.event.inputs.repo_url }}" .
5658
fi
57-
58-
echo "当前分支: $(git branch --show-current)"
59-
echo "最近提交: $(git log -1 --oneline)"
6059
6160
- name: 生成补丁文件
6261
id: generate
6362
run: |
6463
cd "$WORKSPACE/source_repo"
6564
66-
# 获取提交哈希
6765
START_HASH=$(git rev-parse "${{ github.event.inputs.start_commit }}")
6866
END_HASH=$(git rev-parse "${{ github.event.inputs.end_commit }}")
6967
70-
echo "起始提交: $START_HASH"
71-
echo "结束提交: $END_HASH"
72-
73-
# 验证提交
74-
if ! git rev-parse --verify "$START_HASH" >/dev/null 2>&1; then
75-
echo "::error::起始提交不存在"
76-
exit 1
77-
fi
68+
OUTPUT_DIR="$WORKSPACE/patches"
69+
mkdir -p "$OUTPUT_DIR"
7870
79-
if ! git rev-parse --verify "$END_HASH" >/dev/null 2>&1; then
80-
echo "::error::结束提交不存在"
81-
exit 1
82-
fi
83-
84-
# 生成补丁
8571
if [ "${{ github.event.inputs.patch_type }}" = "单个" ]; then
86-
echo "生成单个补丁文件..."
87-
git diff "$START_HASH" "$END_HASH" > "$WORKSPACE/patches/combined.patch"
88-
echo "补丁文件路径: $WORKSPACE/patches/combined.patch"
72+
git diff "$START_HASH" "$END_HASH" > "$OUTPUT_DIR/combined.patch"
73+
echo "patch_file=combined.patch" >> $GITHUB_OUTPUT
8974
else
90-
echo "生成多个补丁文件..."
91-
git format-patch "$START_HASH..$END_HASH" -o "$WORKSPACE/patches"
92-
echo "生成的文件:"
93-
ls -l "$WORKSPACE/patches"
75+
git format-patch "$START_HASH..$END_HASH" -o "$OUTPUT_DIR"
9476
fi
9577
78+
echo "patch_dir=$OUTPUT_DIR" >> $GITHUB_OUTPUT
79+
9680
- name: 创建时间戳命名的 ZIP 文件
9781
id: create_zip
9882
run: |
99-
# 生成时间戳(年月日_时分秒)
10083
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
10184
ZIP_NAME="patch_$TIMESTAMP.zip"
10285
103-
# 创建 ZIP 文件
10486
cd "$WORKSPACE/patches"
10587
zip -r "$WORKSPACE/$ZIP_NAME" .
10688
107-
echo "ZIP文件路径: $WORKSPACE/$ZIP_NAME"
10889
echo "zip_name=$ZIP_NAME" >> $GITHUB_OUTPUT
10990
echo "zip_path=$WORKSPACE/$ZIP_NAME" >> $GITHUB_OUTPUT
91+
echo "zip_timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
11092
11193
- name: 清理环境
11294
run: |
11395
rm -rf "$WORKSPACE/source_repo"
11496
rm -rf "$WORKSPACE/patches"
115-
echo "已清理临时文件"
11697
117-
- name: 上传 ZIP 文件
98+
- name: 上传 ZIP 文件到工作流产物
11899
uses: actions/upload-artifact@v4
119100
with:
120101
name: ${{ steps.create_zip.outputs.zip_name }}
121102
path: ${{ steps.create_zip.outputs.zip_path }}
122103
if-no-files-found: error
123104

105+
- name: 创建 GitHub Release
106+
id: create_release
107+
if: ${{ github.event.inputs.create_release == 'true' }}
108+
uses: softprops/action-gh-release@v1
109+
with:
110+
tag_name: "patch-${{ steps.create_zip.outputs.zip_timestamp }}"
111+
name: "Patch Files - ${{ steps.create_zip.outputs.zip_timestamp }}"
112+
body: "自动生成的补丁文件"
113+
draft: false
114+
prerelease: false
115+
files: ${{ steps.create_zip.outputs.zip_path }}
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
124119
- name: 显示结果
125120
run: |
126121
echo "补丁生成完成"
127122
echo "ZIP文件: ${{ steps.create_zip.outputs.zip_name }}"
128-
echo "可在工作流产物中直接下载"
123+
if [ "${{ github.event.inputs.create_release }}" = "true" ]; then
124+
echo "GitHub Release 已创建: ${{ steps.create_release.outputs.url }}"
125+
else
126+
echo "可在工作流产物中下载补丁文件"
127+
fi

0 commit comments

Comments
 (0)