diff --git a/.github/workflows/convert_host_to_toml.py b/.github/workflows/convert_host_to_toml.py new file mode 100644 index 0000000..e570253 --- /dev/null +++ b/.github/workflows/convert_host_to_toml.py @@ -0,0 +1,24 @@ +import json +import toml +from collections import defaultdict + + +def convert_host_to_toml(host_path, toml_path): + with open(host_path) as host_file: + host_rules = json.load(host_file) + + toml_rules = defaultdict(dict) + + for host_rule in host_rules: + domains, sni, ip = host_rule + + for domain in domains: + toml_rules["alter_hostname"][domain] = sni + toml_rules["hosts"][domain] = ip + + with open(toml_path, "w") as toml_file: + toml.dump(toml_rules, toml_file) + + +if __name__ == "__main__": + convert_host_to_toml("Cealing-Host.json", "Cealing-Host.toml") diff --git a/.github/workflows/convert_host_to_toml.yaml b/.github/workflows/convert_host_to_toml.yaml new file mode 100644 index 0000000..44480a0 --- /dev/null +++ b/.github/workflows/convert_host_to_toml.yaml @@ -0,0 +1,38 @@ +name: Convert Host To Toml + +on: + release: + types: [published] + +jobs: + convert_host_to_toml: + name: Convert Host To Toml + runs-on: ubuntu-latest + steps: + - name: Fetch Github Folder & Host + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github + Cealing-Host.json + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + check-latest: true + + - name: Install Toml + run: pip install "toml" + + - name: Convert Host To Toml + run: | + cp "Cealing-Host.json" ".github/workflows/Cealing-Host.json" + cd ".github/workflows" + python "convert_host_to_toml.py" + + - name: Release Toml + uses: softprops/action-gh-release@v2 + with: + files: Cealing-Host.toml + token: ${{ secrets.GH_TOKEN }}