mirror of
https://github.com/SpaceTimee/Cealing-Host.git
synced 2025-09-14 13:56:47 +08:00
add gh actions
This commit is contained in:
parent
77b75dedca
commit
894aa96fef
29
.github/workflows/generate-toml-and-release.yaml
vendored
Normal file
29
.github/workflows/generate-toml-and-release.yaml
vendored
Normal 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
39
.github/workflows/generate.py
vendored
Normal 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")
|
Loading…
Reference in New Issue
Block a user