-
Notifications
You must be signed in to change notification settings - Fork 123
136 lines (116 loc) · 5.76 KB
/
sync_schema_files.yml
File metadata and controls
136 lines (116 loc) · 5.76 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
name: Sync JSON Schema Files from MaaFramework
on:
schedule:
- cron: '10 0 * * *' # UTC 00:10 每天运行
workflow_dispatch:
permissions:
contents: write
jobs:
check-repository:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- id: check
run: |
if [[ "${{ github.repository }}" == "MaaXYZ/MaaPracticeBoilerplate" ]]; then
echo "Repository is MaaXYZ/MaaPracticeBoilerplate, proceeding with sync"
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "Repository is not MaaXYZ/MaaPracticeBoilerplate, skipping sync"
echo "should_run=false" >> $GITHUB_OUTPUT
fi
sync-schema-files:
needs: check-repository
if: needs.check-repository.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Check Out Repository
uses: actions/checkout@v3
- name: Download JSON schema files from MaaFramework
run: |
echo "Current Date and Time (UTC): $(date -u '+%Y-%m-%d %H:%M:%S')"
# 确保目标目录存在
mkdir -p deps/tools
# 下载四个JSON schema文件
curl -s -o deps/tools/interface.schema.json https://raw.githubusercontent.com/MaaXYZ/MaaFramework/main/tools/interface.schema.json || echo "Failed to download interface.schema.json"
curl -s -o deps/tools/interface_config.schema.json https://raw.githubusercontent.com/MaaXYZ/MaaFramework/main/tools/interface_config.schema.json || echo "Failed to download interface_config.schema.json"
curl -s -o deps/tools/interface_import.schema.json https://raw.githubusercontent.com/MaaXYZ/MaaFramework/main/tools/interface_import.schema.json || echo "Failed to download interface_import.schema.json"
curl -s -o deps/tools/pipeline.schema.json https://raw.githubusercontent.com/MaaXYZ/MaaFramework/main/tools/pipeline.schema.json || echo "Failed to download pipeline.schema.json"
# 检查文件是否成功下载
echo "Checking downloaded files:"
ls -la deps/tools/*.schema.json
- name: Check for changes with git status
id: check_status
run: |
# 确保git能看到未跟踪的文件
git add -N deps/tools/
# 检查是否有任何更改(修改、新增、删除)
if [[ -n "$(git status --porcelain deps/tools/*.schema.json)" ]]; then
echo "Changes detected in JSON schema files"
git status --porcelain deps/tools/*.schema.json
echo "changes_detected=true" >> $GITHUB_OUTPUT
# 检查哪些文件发生了变化
if [[ -n "$(git status --porcelain deps/tools/interface.schema.json)" ]]; then
echo "interface_changed=true" >> $GITHUB_OUTPUT
else
echo "interface_changed=false" >> $GITHUB_OUTPUT
fi
if [[ -n "$(git status --porcelain deps/tools/interface_config.schema.json)" ]]; then
echo "interface_config_changed=true" >> $GITHUB_OUTPUT
else
echo "interface_config_changed=false" >> $GITHUB_OUTPUT
fi
if [[ -n "$(git status --porcelain deps/tools/interface_import.schema.json)" ]]; then
echo "interface_import_changed=true" >> $GITHUB_OUTPUT
else
echo "interface_import_changed=false" >> $GITHUB_OUTPUT
fi
if [[ -n "$(git status --porcelain deps/tools/pipeline.schema.json)" ]]; then
echo "pipeline_changed=true" >> $GITHUB_OUTPUT
else
echo "pipeline_changed=false" >> $GITHUB_OUTPUT
fi
else
echo "No changes detected in JSON schema files"
echo "changes_detected=false" >> $GITHUB_OUTPUT
echo "interface_changed=false" >> $GITHUB_OUTPUT
echo "interface_config_changed=false" >> $GITHUB_OUTPUT
echo "interface_import_changed=false" >> $GITHUB_OUTPUT
echo "pipeline_changed=false" >> $GITHUB_OUTPUT
fi
- name: Commit and Push Changes
id: commit_changes
if: steps.check_status.outputs.changes_detected == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add deps/tools/*.schema.json
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
# 创建定制的提交消息
changed_files=""
if [[ "${{ steps.check_status.outputs.interface_changed }}" == "true" ]]; then
changed_files+="interface "
fi
if [[ "${{ steps.check_status.outputs.interface_config_changed }}" == "true" ]]; then
changed_files+="interface_config "
fi
if [[ "${{ steps.check_status.outputs.interface_import_changed }}" == "true" ]]; then
changed_files+="interface_import "
fi
if [[ "${{ steps.check_status.outputs.pipeline_changed }}" == "true" ]]; then
changed_files+="pipeline "
fi
# 去除末尾空格
changed_files=$(echo "$changed_files" | xargs)
git commit -m "chore: update $changed_files schema files from MaaFramework" -m "Triggered by ${{github.sha}}" -m "[skip changelog]"
git pull origin $(git rev-parse --abbrev-ref HEAD) --unshallow --rebase
git push
echo "have_commits=True" >> $GITHUB_OUTPUT
echo "JSON schema files successfully synchronized"
fi
- name: No changes detected
if: steps.check_status.outputs.changes_detected != 'true'
run: echo "No changes detected in JSON schema files"