3838 run : |
3939 # 创建工作区目录
4040 mkdir -p source_repo
41- mkdir -p "$WORKSPACE/ patches"
41+ mkdir -p patches
4242 echo "工作区路径: $WORKSPACE"
4343 echo "准备完成"
4444
6767 START_HASH=$(git rev-parse "${{ github.event.inputs.start_commit }}")
6868 END_HASH=$(git rev-parse "${{ github.event.inputs.end_commit }}")
6969
70- echo "起始提交: $START_HASH ($(git show -s --format='%s' $START_HASH)) "
71- echo "结束提交: $END_HASH ($(git show -s --format='%s' $END_HASH)) "
70+ echo "起始提交: $START_HASH"
71+ echo "结束提交: $END_HASH"
7272
7373 # 验证提交
7474 if ! git rev-parse --verify "$START_HASH" >/dev/null 2>&1; then
@@ -81,63 +81,26 @@ jobs:
8181 exit 1
8282 fi
8383
84- # 创建输出目录
85- OUTPUT_DIR="$WORKSPACE/patches"
86- mkdir -p "$OUTPUT_DIR"
87- echo "补丁输出目录: $OUTPUT_DIR"
88-
8984 # 生成补丁
9085 if [ "${{ github.event.inputs.patch_type }}" = "单个" ]; then
9186 echo "生成单个补丁文件..."
92- git diff "$START_HASH" "$END_HASH" > "$OUTPUT_DIR/combined.patch"
93-
94- # 验证文件
95- if [ -s "$OUTPUT_DIR/combined.patch" ]; then
96- echo "补丁文件大小: $(wc -c < "$OUTPUT_DIR/combined.patch") 字节"
97- echo "文件路径: $OUTPUT_DIR/combined.patch"
98- else
99- echo "::warning::生成的补丁文件为空"
100- fi
87+ git diff "$START_HASH" "$END_HASH" > "$WORKSPACE/patches/combined.patch"
88+ echo "补丁文件路径: $WORKSPACE/patches/combined.patch"
10189 else
10290 echo "生成多个补丁文件..."
103- git format-patch "$START_HASH..$END_HASH" -o "$OUTPUT_DIR "
91+ git format-patch "$START_HASH..$END_HASH" -o "$WORKSPACE/patches "
10492 echo "生成的文件:"
105- ls -l "$OUTPUT_DIR"
106- fi
107-
108- # 设置输出变量
109- echo "patch_dir=$OUTPUT_DIR" >> $GITHUB_OUTPUT
110- echo "patch_type=${{ github.event.inputs.patch_type }}" >> $GITHUB_OUTPUT
111-
112- - name : 验证补丁文件
113- run : |
114- echo "检查补丁目录: $WORKSPACE/patches"
115- ls -la "$WORKSPACE/patches"
116-
117- if [ "${{ github.event.inputs.patch_type }}" = "单个" ]; then
118- if [ -f "$WORKSPACE/patches/combined.patch" ]; then
119- echo "找到单个补丁文件"
120- echo "文件大小: $(wc -c < "$WORKSPACE/patches/combined.patch") 字节"
121- else
122- echo "::error::未找到补丁文件"
123- exit 1
124- fi
125- else
126- PATCH_COUNT=$(ls -1 "$WORKSPACE/patches"/*.patch 2>/dev/null | wc -l)
127- if [ "$PATCH_COUNT" -gt 0 ]; then
128- echo "找到 $PATCH_COUNT 个补丁文件"
129- else
130- echo "::error::未找到任何补丁文件"
131- exit 1
132- fi
93+ ls -l "$WORKSPACE/patches"
13394 fi
13495
13596 - name : 创建时间戳命名的 ZIP 文件
13697 id : create_zip
13798 run : |
99+ # 生成时间戳(年月日_时分秒)
138100 TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
139101 ZIP_NAME="patch_$TIMESTAMP.zip"
140102
103+ # 创建 ZIP 文件
141104 cd "$WORKSPACE/patches"
142105 zip -r "$WORKSPACE/$ZIP_NAME" .
143106
@@ -148,17 +111,18 @@ jobs:
148111 - name : 清理环境
149112 run : |
150113 rm -rf "$WORKSPACE/source_repo"
151- echo "已清理源仓库"
114+ rm -rf "$WORKSPACE/patches"
115+ echo "已清理临时文件"
152116
153117 - name : 上传 ZIP 文件
154118 uses : actions/upload-artifact@v4
155119 with :
156- name : git-patches
120+ name : ${{ steps.create_zip.outputs.zip_name }}
157121 path : ${{ steps.create_zip.outputs.zip_path }}
158122 if-no-files-found : error
159123
160124 - name : 显示结果
161125 run : |
162126 echo "补丁生成完成"
163127 echo "ZIP文件: ${{ steps.create_zip.outputs.zip_name }}"
164- echo "可在工作流产物中下载 "
128+ echo "可在工作流产物中直接下载 "
0 commit comments