瀏覽代碼

modify readme as a file

dinhlongnguyen 1 年之前
父節點
當前提交
4b475d95f2
共有 2 個文件被更改,包括 16 次插入12 次删除
  1. 2 12
      .github/workflows/release.yml
  2. 14 0
      tools/modify_readme.py

+ 2 - 12
.github/workflows/release.yml

@@ -49,18 +49,8 @@ jobs:
       
       - name: Modify README image file path
         run: |
-          echo """
-          import os, sys
-          branch_name = sys.argv[1]
-          img_list = os.listdir('readme_img')
-          with open(f'README.md') as readme_file:
-              readme_str = readme_file.read()
-              for img in img_list:
-                  readme_str = readme_str.replace(f'readme_img/{img}', f'https://raw.githubusercontent.com/Avaiga/taipy/{branch_name}/readme_img/{img}')
-          with open(f'README.md', 'w') as readme_file:
-              readme_file.write(readme_str)
-          """ > /tmp/modify_readme.py
-          python /tmp/modify_readme.py "${{ steps.extract_branch.outputs.branch }}"
+          cp tools/modify_readme.py /tmp
+          python /tmp/modify_readme.py "${{ github.event.repository.name }}" "${{ steps.extract_branch.outputs.branch }}"
 
       - name: Get taipy-gui version from setup.py
         id: taipy_gui_version

+ 14 - 0
tools/modify_readme.py

@@ -0,0 +1,14 @@
+import sys
+import re
+
+repo_name = sys.argv[1]
+branch_name = sys.argv[2]
+pattern = re.compile("<img\\s+([^>]*?)(?<![\'\"])(?<!\\/)src\\s*=\\s*([\'\"])(?!http|\\/)(.*?)\\2([^>]*?)>")
+replacement = r'<img \1src="https://raw.githubusercontent.com/Avaiga/{repo_name}/{branch_name}/\3"\4>'
+
+with open(f'README.md') as readme_file:
+    readme_str = readme_file.read()
+    modified_readme = re.sub(pattern, replacement.format(repo_name=repo_name, branch_name=branch_name), readme_str)
+
+with open(f'README.md', 'w') as readme_file:
+    readme_file.write(modified_readme)