Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
ci: 重新命名腳本
Browse files Browse the repository at this point in the history
  • Loading branch information
xMikux committed Aug 25, 2023
1 parent daf4887 commit 32324e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys

def insert_content(file_path, start_tag, end_tag, content_insert):
def insert_content(file_path: str, multiline_mode: bool, start_tag: str, end_tag: str, content_insert: str): # noqa: E501
with open(file_path, "r") as file:
file_contents = file.read()

Expand All @@ -12,26 +12,34 @@ def insert_content(file_path, start_tag, end_tag, content_insert):
print("未找到 Tags")
sys.exit(1)

updated_contents = (
file_contents[:start_index + len(start_tag)] +
"\n" +
content_insert +
"\n" +
file_contents[end_index:]
)
if multiline_mode:
updated_contents = (
file_contents[:start_index + len(start_tag)] +
"\n" +
content_insert +
"\n" +
file_contents[end_index:]
)
else:
updated_contents = (
file_contents[:start_index + len(start_tag)] +
content_insert +
file_contents[end_index:]
)

with open(file_path, "w") as file:
file.write(updated_contents)

def main():
file_path = os.environ.get("FILE_PATH")
multiline_mode = os.environ.get("MULTILINE_MODE", False)
start_tag = os.environ.get("START_TAG")
end_tag = os.environ.get("END_TAG")
content = os.environ.get("CONTENT")
envs = [file_path, start_tag, end_tag, content]

if all(envs):
insert_content(file_path, start_tag, end_tag, content)
insert_content(file_path, multiline_mode, start_tag, end_tag, content)
else:
print("錯誤,有環境變數未存在!")
sys.exit(1)
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/CI-Contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ jobs:

- name: Update Readme
run: |
python .github/scripts/readme_replacer.py
python .github/scripts/content_replacer.py
env:
FILE_PATH: "README.md"
MULTILINE_MODE: True
START_TAG: "<!-- CONTRIBUTORS_CI_START -->"
END_TAG: "<!-- CONTRIBUTORS_CI_END -->"
CONTENT: "${{steps.contributors.outputs.htmlTable}}"
Expand All @@ -48,7 +49,10 @@ jobs:
📃 文件
add-paths: README.md
body: |
此為自動化工作流程所建立的!
- 由 [create-pull-request][1] 自動產生
[1]: https://github.com/peter-evans/create-pull-request
自動化 [GitHub Action][github-action] 工作流程!
------
由 [create-pull-request][cpr] 自動產生
[cpr]: https://github.com/peter-evans/create-pull-request
[github-action]: https://github.com/features/actions

0 comments on commit 32324e9

Please sign in to comment.