Skip to content

Update ACL4SSR_Online_Full_WithIcon.yaml #11

Update ACL4SSR_Online_Full_WithIcon.yaml

Update ACL4SSR_Online_Full_WithIcon.yaml #11

Workflow file for this run

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 re
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:
content = file.read()
url_pattern = re.compile(r"(icon:\s*)(http[s]?:\/\/[^\s]+)", re.IGNORECASE)
def url_to_base64(url):
try:
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
except Exception as e:
print(f"Failed to convert {url}: {str(e)}")
return url
def replace_icon(match):
original_url = match.group(2)
base64_data = url_to_base64(original_url)
return f"{match.group(1)}'{base64_data}'"
updated_content = url_pattern.sub(replace_icon, content)
with open(output_file, 'w', encoding='utf-8') as file:
file.write(updated_content)
print(f"Icon URLs converted to Base64 and saved to {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 }}