diff --git a/.gitea/workflows/generate-rules.yml b/.gitea/workflows/generate-rules.yml index 647c06417..97814c656 100644 --- a/.gitea/workflows/generate-rules.yml +++ b/.gitea/workflows/generate-rules.yml @@ -17,11 +17,32 @@ jobs: fetch-depth: 0 github-server-url: https://git.halonice.com - - name: Check Python runtime + - name: Bootstrap Python runtime shell: bash run: | set -euo pipefail - python3 --version + 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 @@ -44,9 +65,10 @@ jobs: 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 - python3 src/rulegen.py --config configs/config.toml + "${PYTHON_BIN}" src/rulegen.py --config configs/config.toml else - python3 src/rulegen.py --config configs/config.json + "${PYTHON_BIN}" src/rulegen.py --config configs/config.json fi diff --git a/.gitea/workflows/repo-manage-daily.yml b/.gitea/workflows/repo-manage-daily.yml index f262276aa..9a90b301a 100644 --- a/.gitea/workflows/repo-manage-daily.yml +++ b/.gitea/workflows/repo-manage-daily.yml @@ -22,11 +22,32 @@ jobs: fetch-depth: 0 github-server-url: https://git.halonice.com - - name: Check Python runtime + - name: Bootstrap Python runtime shell: bash run: | set -euo pipefail - python3 --version + 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 @@ -50,11 +71,12 @@ jobs: run: | set -euo pipefail UPSTREAM_REF="${UPSTREAM_REF:-master}" + PYTHON_BIN="${PYTHON_BIN:-python3}" bash tools/sync_surge_full.sh if [ -f configs/config.toml ]; then - python3 src/rulegen.py --config configs/config.toml + "${PYTHON_BIN}" src/rulegen.py --config configs/config.toml else - python3 src/rulegen.py --config configs/config.json + "${PYTHON_BIN}" src/rulegen.py --config configs/config.json fi - name: Commit and push builder updates