75 lines
2.3 KiB
YAML
75 lines
2.3 KiB
YAML
name: Generate Rules
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
github-server-url: https://git.halonice.com
|
|
|
|
- name: Bootstrap Python runtime
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
py_bin="python3"
|
|
elif command -v python >/dev/null 2>&1; then
|
|
py_bin="python"
|
|
else
|
|
if command -v apt-get >/dev/null 2>&1; then
|
|
apt-get update
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y python3 python3-pip
|
|
elif command -v apk >/dev/null 2>&1; then
|
|
apk add --no-cache python3 py3-pip
|
|
elif command -v dnf >/dev/null 2>&1; then
|
|
dnf install -y python3 python3-pip
|
|
elif command -v yum >/dev/null 2>&1; then
|
|
yum install -y python3 python3-pip
|
|
else
|
|
echo "python is not available and no supported package manager was found" >&2
|
|
exit 1
|
|
fi
|
|
py_bin="python3"
|
|
fi
|
|
"${py_bin}" --version
|
|
echo "PYTHON_BIN=${py_bin}" >> "$GITHUB_ENV"
|
|
|
|
- name: Prepare config
|
|
shell: bash
|
|
run: |
|
|
if [ -f configs/config.toml ]; then
|
|
echo "Use existing configs/config.toml"
|
|
elif [ -f configs/config.json ]; then
|
|
echo "Use existing configs/config.json"
|
|
elif [ -f configs/examples/config.example.toml ]; then
|
|
cp configs/examples/config.example.toml configs/config.toml
|
|
echo "Generated configs/config.toml from example"
|
|
else
|
|
echo "No config file found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: Generate rules
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
UPSTREAM_REF: ${{ vars.UPSTREAM_REF }}
|
|
run: |
|
|
UPSTREAM_REF="${UPSTREAM_REF:-master}"
|
|
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
bash tools/sync_surge_full.sh
|
|
if [ -f configs/config.toml ]; then
|
|
"${PYTHON_BIN}" src/rulegen.py --config configs/config.toml
|
|
else
|
|
"${PYTHON_BIN}" src/rulegen.py --config configs/config.json
|
|
fi
|