-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (55 loc) · 1.89 KB
/
pr-changed-files.yml
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
name: PR File Changes Comment
on:
pull_request:
types: [opened, synchronize]
jobs:
comment-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
- name: Process changed files with Python
run: |
python << EOF
import os
import json
# 从环境变量读取更改的文件列表
changed_files = os.environ['CHANGED_FILES']
# 将字符串转换为列表
changed_files_list = json.loads(changed_files)
print("Changed files:")
for file in changed_files_list:
print(f"- {file}")
# 计算更改的文件数量
file_count = len(changed_files_list)
# 将文件数量设置为输出变量
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"file_count={file_count}", file=fh)
EOF
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- name: Create file list
id: file-list
run: |
FILE_LIST=""
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
FILE_LIST="${FILE_LIST}- ${file}\n"
done
echo "file_list<<EOF" >> $GITHUB_OUTPUT
echo -e "$FILE_LIST" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `修改的文件列表:\n\n${{ steps.file-list.outputs.file_list }}`
})