-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
88 lines (76 loc) · 3.01 KB
/
action.yml
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
name: 'PR Agent Wiki Configuration Loader'
description: 'Load .pr_agent.toml.md in Wiki page and set to environment'
branding:
icon: 'award'
color: 'green'
inputs:
page-name:
description: 'toml page name'
required: false
default: '.pr_agent.toml.md'
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install modules
shell: bash
run: pip install toml
- uses: actions/checkout@v4
continue-on-error: true # Continue even if repo is not existed
with:
repository: ${{ github.repository }}.wiki
sparse-checkout: |
${{ inputs.page-name }}
sparse-checkout-cone-mode: false
path: wiki_temp
- name: Load configuraions and set to environment
shell: python
run: |
import os
import toml
import json
ei_key = 'extra_instructions'
ei_sections = ['pr_reviewer', 'pr_description', 'pr_code_suggestions', 'pr_add_docs', 'pr_update_changelog', 'pr_test', 'pr_improve_component']
repository_name = os.getenv('GITHUB_REPOSITORY')
def get_conf():
try:
# Load Config file
with open("wiki_temp/${{ inputs.page-name }}", encoding="UTF-8") as f:
toml_content = f.read()
# Parse TOML content
start = toml_content.find("```") + 3
end = toml_content.rfind("```")
toml_content = toml_content[start:end]
parsed_toml = toml.loads(toml_content)
return parsed_toml
except Exception as e:
print(f"Error: {e}")
return {}
def concat_env_value(parsed_toml):
common_instructions = os.getenv('common_instructions', '')
for key in ei_sections:
additional_instructions = (os.getenv(f"{key}.{ei_key}", '').strip() + '\n' + (common_instructions).strip()).strip()
if key in parsed_toml:
if ei_key in parsed_toml[key]:
parsed_toml[key][ei_key] = (parsed_toml[key][ei_key]).strip() + '\n' + additional_instructions
else:
parsed_toml[key][ei_key] = additional_instructions
else:
parsed_toml[key] = {ei_key: additional_instructions}
return parsed_toml
def set_to_env(parsed_toml):
github_env = os.getenv('GITHUB_ENV')
with open(github_env, "a") as outputfile:
for key in ei_sections:
value = parsed_toml.get(key, {}).get(ei_key)
if value not in ('', None):
print(f"{key}.{ei_key}<<EOF", file=outputfile)
print(f"{value}", file=outputfile)
print(f"EOF", file=outputfile)
if __name__ == "__main__":
toml_conf = get_conf()
added_toml_conf = concat_env_value(toml_conf)
set_to_env(added_toml_conf)