add gh actions

This commit is contained in:
Sving1024 2025-05-03 16:40:58 +08:00
parent 77b75dedca
commit 894aa96fef
No known key found for this signature in database
GPG Key ID: 2BCE145890082742
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,29 @@
name: Generate toml config and release
on:
push:
tags:
- *.*.*.*
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: generate toml file
run: ./.github/workflows/generate.py
- uses: actions/upload-artifact@v4
with:
name: config
path: |
./*.json
./*.toml
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: config/
- uses: ncipollo/release-action@v1
with:
artifacts: "config/*.json,config/*.toml"

39
.github/workflows/generate.py vendored Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python
import json
import toml
def convert_json_to_toml(json_file_path, toml_file_path):
# 读取JSON文件
with open(json_file_path, "r", encoding="utf-8") as f:
data = json.load(f)
# 初始化TOML数据结构
toml_data = {"alter_hostname": {}, "hosts": {}}
# 处理每个条目
for entry in data:
domains, alter_host, ip = entry
# 处理alter_hostname部分
for domain in domains:
toml_data["alter_hostname"][domain] = alter_host
# 处理hosts部分
for domain in domains:
toml_data["hosts"][domain] = ip
# 写入TOML文件
with open(toml_file_path, "w", encoding="utf-8") as f:
toml.dump(toml_data, f)
# 使用示例
if __name__ == "__main__":
for filename_base in [
"Cealing-Host-A",
"Cealing-Host-P",
"Cealing-Host-R",
"Cealing-Host",
]:
convert_json_to_toml(filename_base + ".json", filename_base + ".toml")