From af71d8af24833adf0d96dd1298d603b5135aaf7e Mon Sep 17 00:00:00 2001 From: Alter-xyz <88554920+alterxyz@users.noreply.github.com> Date: Sat, 17 May 2025 23:14:41 +0800 Subject: [PATCH] feat: action --- .github/workflows/docs_contribute_button.yml | 65 +++++++++++++++++ .github/workflows/docs_plugin_dev_bundle.yml | 63 ++++++++++++++++ .github/workflows/process-mdx.yml | 40 ---------- .gitignore | 5 +- tools/main_docs_lite.py | 77 ++++++++++++++++++++ tools/main_docs_plugin_dev.py | 77 ++++++++++++++++++++ 6 files changed, 283 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/docs_contribute_button.yml create mode 100644 .github/workflows/docs_plugin_dev_bundle.yml delete mode 100644 .github/workflows/process-mdx.yml create mode 100644 tools/main_docs_lite.py create mode 100644 tools/main_docs_plugin_dev.py diff --git a/.github/workflows/docs_contribute_button.yml b/.github/workflows/docs_contribute_button.yml new file mode 100644 index 00000000..2ca0613b --- /dev/null +++ b/.github/workflows/docs_contribute_button.yml @@ -0,0 +1,65 @@ +name: Process General Documentation + +on: + push: + branches: [test-action] + paths: + - 'plugin_dev_zh/**' + - 'plugin_dev_en/**' + - 'plugin_dev_ja/**' + - 'tools/**' + - '.github/**' # 避免工作流文件变更触发自身 + + workflow_dispatch: + +jobs: + process-docs: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pyyaml + + - name: Run documentation tools + id: doc-tools + run: python tools/main_docs_lite.py + + - name: Display results + run: | + echo "Execution results:" + echo "Successful operations: ${{ steps.doc-tools.outputs.success_count }}" + echo "Failed operations: ${{ steps.doc-tools.outputs.error_count }}" + if [ "${{ steps.doc-tools.outputs.detailed_message }}" != "" ]; then + echo "Details:" + echo "${{ steps.doc-tools.outputs.detailed_message }}" + fi + + - name: Commit changes + if: always() # Execute this step even if previous steps fail + run: | + # Check if there are file changes + if [[ -n "$(git status --porcelain)" ]]; then + # Use commit message from script output, or default if not available + COMMIT_MESSAGE="${{ steps.doc-tools.outputs.commit_message || 'Documentation tools automatic execution' }}" + + git config --local user.email "88554920+alterxyz@users.noreply.github.com" + git config --local user.name "alterxyz" + git add . + git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit" + git push + echo "Changes committed: $COMMIT_MESSAGE" + else + echo "No file changes, skipping commit" + fi diff --git a/.github/workflows/docs_plugin_dev_bundle.yml b/.github/workflows/docs_plugin_dev_bundle.yml new file mode 100644 index 00000000..4e72e44b --- /dev/null +++ b/.github/workflows/docs_plugin_dev_bundle.yml @@ -0,0 +1,63 @@ +name: Process Plugin Documentation + +on: + push: + branches: [test-action] + paths: + - 'plugin_dev_zh/**' + - 'plugin_dev_en/**' + - 'plugin_dev_ja/**' + - 'tools/**' + workflow_dispatch: + +jobs: + process-docs: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pyyaml + + - name: Run documentation tools + id: doc-tools + run: python tools/main_docs_plugin_dev.py + + - name: Display results + run: | + echo "Execution results:" + echo "Successful operations: ${{ steps.doc-tools.outputs.success_count }}" + echo "Failed operations: ${{ steps.doc-tools.outputs.error_count }}" + if [ "${{ steps.doc-tools.outputs.detailed_message }}" != "" ]; then + echo "Details:" + echo "${{ steps.doc-tools.outputs.detailed_message }}" + fi + + - name: Commit changes + if: always() # Execute this step even if previous steps fail + run: | + # Check if there are file changes + if [[ -n "$(git status --porcelain)" ]]; then + # Use commit message from script output, or default if not available + COMMIT_MESSAGE="${{ steps.doc-tools.outputs.commit_message || 'Documentation tools automatic execution' }}" + + git config --local user.email "88554920+alterxyz@users.noreply.github.com" + git config --local user.name "alterxyz" + git add . + git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit" + git push + echo "Changes committed: $COMMIT_MESSAGE" + else + echo "No file changes, skipping commit" + fi diff --git a/.github/workflows/process-mdx.yml b/.github/workflows/process-mdx.yml deleted file mode 100644 index 231b9619..00000000 --- a/.github/workflows/process-mdx.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Process MDX Files - -on: - push: - branches: [ test-action ] # 仅在test-action分支上触发 - paths: - - '**.mdx' # 只在MDX文件变更时触发 - - 'tools/**' # 或工具脚本变更时触发 - workflow_dispatch: # 允许手动触发 - -jobs: - process-mdx: - runs-on: ubuntu-latest - permissions: - contents: write # 允许脚本修改和提交文件 - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pyyaml - - - name: Run MDX processing script - run: python tools/1_rename_by_dimensions.py - - - name: Commit changes - run: | - git config --local user.email "88554920+alterxyz@users.noreply.github.com" - git config --local user.name "alterxyz" - git add . - git commit -m "Auto-process MDX files [skip ci]" || echo "No changes to commit" - git push \ No newline at end of file diff --git a/.gitignore b/.gitignore index ac98462b..bb796af5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ ._DS_Store .DS_Store .venv -plugin_dev_zh_* -plugin_dev_ja_* -plugin_dev_en_* -/tool \ No newline at end of file +__pycache__/ diff --git a/tools/main_docs_lite.py b/tools/main_docs_lite.py new file mode 100644 index 00000000..9c7a515b --- /dev/null +++ b/tools/main_docs_lite.py @@ -0,0 +1,77 @@ +import os +import sys + +# from rename_by_dimensions import main_rename_by_dimensions +from contributing_in_page import main_contributing_in_page +# from apply_docs_json import main_apply_docs_json + + +def set_github_output(name, value): + github_output = os.environ.get('GITHUB_OUTPUT') + if github_output: + with open(github_output, 'a') as f: + if '\n' in str(value): + f.write(f"{name}< 0: + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tools/main_docs_plugin_dev.py b/tools/main_docs_plugin_dev.py new file mode 100644 index 00000000..90ec06e7 --- /dev/null +++ b/tools/main_docs_plugin_dev.py @@ -0,0 +1,77 @@ +import os +import sys + +from rename_by_dimensions import main_rename_by_dimensions +from contributing_in_page import main_contributing_in_page +from apply_docs_json import main_apply_docs_json + + +def set_github_output(name, value): + github_output = os.environ.get('GITHUB_OUTPUT') + if github_output: + with open(github_output, 'a') as f: + if '\n' in str(value): + f.write(f"{name}< 0: + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file