Update ModelScope Documentation #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |