forked from jsdizkcksv/commit_make_patch
-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (123 loc) · 4.14 KB
/
Copy pathmain.yml
File metadata and controls
142 lines (123 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Make commit on patch
on:
workflow_dispatch:
inputs:
repo_url:
description: 'Git 仓库 URL'
required: true
branch:
description: '仓库分支 (默认使用默认分支)'
required: false
default: ''
start_commit:
description: '起始提交'
required: true
end_commit:
description: '结束提交'
required: true
patch_type:
description: '补丁文件类型'
required: true
default: '多个'
type: choice
options:
- '单个'
- '多个'
create_release:
description: '是否创建 GitHub Release'
required: true
default: 'true'
type: choice
options:
- 'true'
- 'false'
# 添加工作流级别的权限
permissions:
contents: write
jobs:
Make:
runs-on: ubuntu-latest
# 添加作业级别的权限(双重保障)
permissions:
contents: write
actions: read
id-token: write
env:
WORKSPACE: ${{ github.workspace }}
BUILD_DATE: $(date +'%Y%m%d')
steps:
- name: 检出当前仓库
uses: actions/checkout@v4
- name: 准备环境
run: |
mkdir -p source_repo patches
echo "工作区路径: $WORKSPACE"
- name: 克隆源仓库
run: |
cd "$WORKSPACE/source_repo"
if [ -n "${{ github.event.inputs.branch }}" ]; then
git clone --branch "${{ github.event.inputs.branch }}" "${{ github.event.inputs.repo_url }}" .
else
git clone "${{ github.event.inputs.repo_url }}" .
fi
- name: 生成补丁文件
id: generate
run: |
cd "$WORKSPACE/source_repo"
START_HASH=$(git rev-parse "${{ github.event.inputs.start_commit }}")
END_HASH=$(git rev-parse "${{ github.event.inputs.end_commit }}")
OUTPUT_DIR="$WORKSPACE/patches"
mkdir -p "$OUTPUT_DIR"
if [ "${{ github.event.inputs.patch_type }}" = "单个" ]; then
git diff "$START_HASH" "$END_HASH" > "$OUTPUT_DIR/combined.patch"
echo "patch_file=combined.patch" >> $GITHUB_OUTPUT
else
git format-patch "$START_HASH..$END_HASH" -o "$OUTPUT_DIR"
fi
echo "patch_dir=$OUTPUT_DIR" >> $GITHUB_OUTPUT
- name: 创建时间戳命名的 ZIP 文件
id: create_zip
run: |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
ZIP_NAME="patch_$TIMESTAMP.zip"
cd "$WORKSPACE/patches"
zip -r "$WORKSPACE/$ZIP_NAME" .
echo "zip_name=$ZIP_NAME" >> $GITHUB_OUTPUT
echo "zip_path=$WORKSPACE/$ZIP_NAME" >> $GITHUB_OUTPUT
echo "zip_timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
- name: 清理环境
run: |
rm -rf "$WORKSPACE/source_repo"
rm -rf "$WORKSPACE/patches"
- name: 上传 ZIP 文件到工作流产物
uses: actions/upload-artifact@v4
with:
name: ${{ steps.create_zip.outputs.zip_name }}
path: ${{ steps.create_zip.outputs.zip_path }}
if-no-files-found: error
- name: 创建 GitHub Release
id: create_release
if: ${{ github.event.inputs.create_release == 'true' }}
uses: softprops/action-gh-release@v1
with:
tag_name: "patch-${{ steps.create_zip.outputs.zip_timestamp }}"
name: "Patch Files - ${{ steps.create_zip.outputs.zip_timestamp }}"
body: "自动生成的补丁文件"
draft: false
prerelease: false
files: ${{ steps.create_zip.outputs.zip_path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 显示结果
run: |
echo "补丁生成完成"
echo "ZIP文件: ${{ steps.create_zip.outputs.zip_name }}"
if [ "${{ github.event.inputs.create_release }}" = "true" ]; then
if [ "${{ steps.create_release.conclusion }}" = "success" ]; then
echo "GitHub Release 已创建: ${{ steps.create_release.outputs.url }}"
else
echo "GitHub Release 创建失败,请检查权限设置"
fi
else
echo "可在工作流产物中下载补丁文件"
fi