-
Notifications
You must be signed in to change notification settings - Fork 6
172 lines (149 loc) · 6.88 KB
/
Copy pathupdate-modelscope-docs.yml
File metadata and controls
172 lines (149 loc) · 6.88 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Update ModelScope Documentation
on:
# Scheduled trigger (daily at 18:00 UTC, which is 02:00 Beijing Time next day)
schedule:
- cron: '0 3 * * *'
# Manual trigger (run via GitHub web interface)
workflow_dispatch:
# Trigger when model_list.txt or workflow files change
push:
paths:
- 'docs/flagrelease_en/model_list.txt'
- '.github/workflows/update-modelscope-docs.yml'
- 'docs/scripts/download_readmes.py'
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository code
uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch full history for proper git diff
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: 'requirements.txt'
- name: Install Python dependencies
run: |
pip install -r requirements.txt
- name: Generate model list
run: |
cd "$GITHUB_WORKSPACE"
python docs/scripts/generate_model_list.py
continue-on-error: true
- name: Download ModelScope documentation
id: download
run: |
cd "$GITHUB_WORKSPACE"
python docs/scripts/download_readmes.py
continue-on-error: true # Continue even if some downloads fail
- name: Generate download report
id: generate-report
run: |
# Create a detailed download report file with success and failure information
# Store the report file in a tem directory to prevent it from pusing to the repo
REPORT_FILE="/tmp/download_report_$(TZ='Asia/Shanghai' date +'%Y%m%d_%H%M%S').txt"
echo "# ModelScope Documentation Update Report" > $REPORT_FILE
echo "## Generated on: $(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S %Z')" >> $REPORT_FILE
echo "## Workflow Run: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $REPORT_FILE
echo "" >> $REPORT_FILE
# Add all changes to the staging area to detect new files
git add -N .
# Count the number of updated files and get detailed information
if [ -d "docs/flagrelease_en/model_readmes/" ]; then
# Get the list of all changed files (both modified and added)
CHANGED_FILES=$(git diff --name-status docs/flagrelease_en/model_readmes/ 2>/dev/null || echo "")
if [ -z "$CHANGED_FILES" ]; then
CHANGED_COUNT=0
else
CHANGED_COUNT=$(echo "$CHANGED_FILES" | wc -l)
fi
echo "## Summary" >> $REPORT_FILE
echo "- **Total changes detected:** $CHANGED_COUNT files" >> $REPORT_FILE
echo "" >> $REPORT_FILE
if [ "$CHANGED_COUNT" -gt 0 ]; then
echo "## Detailed Changes" >> $REPORT_FILE
# Count added and modified files separately
ADDED_FILES=$(echo "$CHANGED_FILES" | grep -c '^A' || echo "0")
MODIFIED_FILES=$(echo "$CHANGED_FILES" | grep -c '^M' || echo "0")
echo "- **Added files:** $ADDED_FILES" >> $REPORT_FILE
echo "- **Modified files:** $MODIFIED_FILES" >> $REPORT_FILE
echo "" >> $REPORT_FILE
# List added files
if [ "$ADDED_FILES" -gt 0 ]; then
echo "### Added Files" >> $REPORT_FILE
echo "$CHANGED_FILES" | grep '^A' | cut -f2 | while read file; do
echo "- \`$file\`" >> $REPORT_FILE
done
echo "" >> $REPORT_FILE
fi
# List modified files
if [ "$MODIFIED_FILES" -gt 0 ]; then
echo "### Modified Files" >> $REPORT_FILE
echo "$CHANGED_FILES" | grep '^M' | cut -f2 | while read file; do
echo "- \`$file\`" >> $REPORT_FILE
done
echo "" >> $REPORT_FILE
fi
fi
fi
# Extract statistics from script output if available
echo "## Model Download Statistics" >> $REPORT_FILE
echo "- **Last run status:** ${{ job.status }}" >> $REPORT_FILE
echo "- **Trigger type:** ${{ github.event_name }}" >> $REPORT_FILE
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "- **Schedule:** Daily at 03:00 UTC (11:00 Beijing Time)" >> $REPORT_FILE
fi
echo "" >> $REPORT_FILE
echo "## Next Steps" >> $REPORT_FILE
echo "Please review the changes in the model documentation files above." >> $REPORT_FILE
echo "After merging this PR, the documentation will be updated on the main branch." >> $REPORT_FILE
echo "report_file=$REPORT_FILE" >> $GITHUB_OUTPUT
- name: Check for file changes
id: check-changes
run: |
# Check if any files have been modified or added
git add -N .
# Exclude the report file
if git diff --quiet docs/flagrelease_en/model_readmes/ 2>/dev/null; then
echo "No file changes detected"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "File changes detected"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Reset git configuration before creating PR
if: steps.check-changes.outputs.has_changes == 'true'
run: |
# clear
git config --local --unset-all http.https://github.com/.extraheader 2>/dev/null || true
git config --global --unset-all http.https://github.com/.extraheader 2>/dev/null || true
- name: Generate branch name and title
id: branch-name
if: steps.check-changes.outputs.has_changes == 'true'
run: |
BRANCH_NAME="update/modelscope-docs-$(TZ='Asia/Shanghai' date +'%Y%m%d-%H%M%S')"
PR_TITLE="ModelScope Documentation Update - $(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M')"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT
echo "Generated branch name: $BRANCH_NAME"
echo "Generated PR title: $PR_TITLE"
- name: Create Pull Request
if: steps.check-changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Auto-update ModelScope documentation [$(TZ=''Asia/Shanghai'' date +''%Y-%m-%d %H:%M'')]'
branch: ${{ steps.branch-name.outputs.branch_name }}
delete-branch: true
title: ${{ steps.branch-name.outputs.pr_title }}
body-path: ${{ steps.generate-report.outputs.report_file }}
base: 'main'
labels: 'documentation, auto-update, modelscope'
draft: false
# Remove the invalid 'paths' parameter and use 'add-paths' instead to specify which files to include
add-paths: |
docs/flagrelease_en/model_readmes/
docs/flagrelease_en/model_list.txt