forked from mihomo-party-org/override-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (60 loc) · 2.22 KB
/
main.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
name: Convert Icon URL to Base64
on:
push:
paths:
- yaml/ACL4SSR_Online_Full_WithIcon.yaml
jobs:
convert-icons:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Check if the YAML file exists
id: check_file
run: |
if [ ! -f "yaml/ACL4SSR_Online_Full_WithIcon.yaml" ]; then
echo "File does not exist."
exit 0
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml requests
- name: Convert icon URLs to Base64 and modify YAML
run: |
python - <<EOF
import yaml
import requests
import base64
input_file = 'yaml/ACL4SSR_Online_Full_WithIcon.yaml'
output_file = 'yaml/ACL4SSR_Online_Full_WithBase64Icon.yaml'
with open(input_file, 'r', encoding='utf-8') as file:
data = yaml.safe_load(file)
def url_to_base64(url):
response = requests.get(url)
if response.status_code == 200:
img_type = url.split('.')[-1]
base64_str = base64.b64encode(response.content).decode('utf-8')
return f"data:image/{img_type};base64,{base64_str}"
else:
return url
for group in data.get('proxy-groups', []):
if 'icon' in group:
group['icon'] = repr(url_to_base64(group['icon']))
with open(output_file, 'w', encoding='utf-8') as file:
yaml.dump(data, file, allow_unicode=True)
print(f"Conversion completed: {output_file}")
EOF
- name: Commit and Push changes
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add yaml/ACL4SSR_Online_Full_WithBase64Icon.yaml
git commit -m "Converted image URL to base64 in ACL4SSR_Online_Full_WithBase64Icon.yaml"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}