Skip to content

Commit c14ab2c

Browse files
committed
feat: overhaul helper scripts and tooling
* move api works to python and restructure python helpers: - use uv for the python env and package management - use ruff and basedpyright for python checks - match release assets with glob patterns * general changes: - add dependency checks - introduce tri-state (auto / true / false) option - add support for python scripts checking in workflows - merge some small files together to reduce scripts fragementation Signed-off-by: bachnxuan <bachnxuan@gmail.com>
1 parent d064ae8 commit c14ab2c

29 files changed

Lines changed: 978 additions & 464 deletions

.github/workflows/build.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919
type: boolean
2020
required: true
2121
STOCK_CONFIG:
22-
type: boolean
22+
type: string
2323
required: true
2424
TG_NOTIFY:
2525
type: boolean
@@ -56,8 +56,12 @@ on:
5656

5757
STOCK_CONFIG:
5858
description: "Spoof stock config?"
59-
default: true
60-
type: boolean
59+
default: auto
60+
type: choice
61+
options:
62+
- auto
63+
- true
64+
- false
6165

6266
TG_NOTIFY:
6367
description: "Telegram Notify"
@@ -89,7 +93,13 @@ jobs:
8993
run: |
9094
sudo apt-get update -qq
9195
sudo apt-get install -qq \
92-
bc bison ccache curl flex git tar wget aria2 jq zip zstd upx build-essential python3-requests libfaketime lz4 just
96+
bc bison ccache curl flex git tar wget aria2 jq zip zstd upx build-essential libfaketime lz4 just
97+
98+
- name: Setup uv
99+
uses: astral-sh/setup-uv@v6
100+
101+
- name: Install Python 3.14
102+
run: uv python install 3.14
93103

94104
- name: Compute ccache key
95105
run: |

.github/workflows/check.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
name: Bash Check
1+
name: Check
22

33
on:
44
pull_request:
55
paths:
66
- "**/*.sh"
7+
- "py/**/*.py"
8+
- "py/pyproject.toml"
9+
- "py/uv.lock"
710
- "justfile"
811
- ".github/workflows/check.yml"
912
push:
1013
paths:
1114
- "**/*.sh"
15+
- "py/**/*.py"
16+
- "py/pyproject.toml"
17+
- "py/uv.lock"
1218
- "justfile"
1319
- ".github/workflows/check.yml"
1420
workflow_dispatch:
1521

1622
jobs:
17-
check:
23+
bash:
1824
runs-on: ubuntu-latest
1925

2026
steps:
@@ -26,5 +32,24 @@ jobs:
2632
sudo apt-get update
2733
sudo apt-get install -y just shellcheck shfmt
2834
29-
- name: Run checks
30-
run: just check
35+
- name: Run bash checks
36+
run: just fmt-check bash-check lint
37+
38+
python:
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v6.0.1
44+
45+
- name: Setup uv
46+
uses: astral-sh/setup-uv@v6
47+
48+
- name: Install Python 3.14
49+
run: uv python install 3.14
50+
51+
- name: Sync Python dev dependencies
52+
run: uv sync --project py --group dev
53+
54+
- name: Run Python checks
55+
run: just py-lint py-check

.github/workflows/release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
KSU: ${{ matrix.variant.KSU }}
5858
SUSFS: ${{ matrix.variant.SUSFS }}
5959
LXC: ${{ matrix.variant.LXC }}
60-
STOCK_CONFIG: true
60+
STOCK_CONFIG: auto
6161
TG_NOTIFY: false
6262

6363
release:
@@ -77,6 +77,12 @@ jobs:
7777
with:
7878
path: release_files
7979

80+
- name: Setup uv
81+
uses: astral-sh/setup-uv@v6
82+
83+
- name: Install Python 3.14
84+
run: uv python install 3.14
85+
8086
- name: Import build metadata
8187
run: |
8288
metadata_file="release_files/github-metadata-VNL/github.json"
@@ -103,9 +109,9 @@ jobs:
103109
GH_TOKEN: ${{ secrets.GH_TOKEN }}
104110
RELEASE_REPO: ${{ env.RELEASE_REPO }}
105111
run: |
106-
TAG_PY="$GITHUB_WORKSPACE/py/tag.py"
112+
UV_PROJECT="$GITHUB_WORKSPACE/py"
107113
108-
RELEASE_TAG=$(python3 "$TAG_PY" "$RELEASE_REPO")
114+
RELEASE_TAG=$(uv run --project "$UV_PROJECT" tools release next-tag "$RELEASE_REPO")
109115
110116
echo "New tag: $RELEASE_TAG"
111117
echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_ENV"
@@ -153,7 +159,7 @@ jobs:
153159
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
154160
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
155161
run: |
156-
TG_PY="$GITHUB_WORKSPACE/py/tg.py"
162+
UV_PROJECT="$GITHUB_WORKSPACE/py"
157163
158164
escape_md_v2() {
159165
python3 - "$*" <<'PY'
@@ -173,4 +179,4 @@ jobs:
173179
EOF
174180
)
175181
176-
printf '%s' "$message" | python3 "$TG_PY" msg
182+
printf '%s' "$message" | uv run --project "$UV_PROJECT" tools tg msg

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build outputs
22
/out/
3+
/work/
34
/boot_image/
45
/clang/
56
/kernel/
@@ -8,11 +9,23 @@
89
/mkbootimg/
910
/susfs/
1011
/staged/
11-
*.log
12+
/build.log
1213
/github.env
1314
/github.json
1415
/.ccache/
1516
/libfakestat/
17+
18+
# Editor state
1619
/.vscode/
20+
*.swp
21+
*.swo
22+
*~
23+
24+
# Python
1725
/modules/flatten/
1826
/modules/staging/
27+
/py/.venv/
28+
/py/.python-version
29+
/py/**/__pycache__/
30+
/py/.mypy_cache/
31+
/py/.ruff_cache/

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pulls sources and tools, applies optional patches, then builds and packages the
1010
- config.sh: defaults, repos, paths, and target settings
1111
- build/: setup, patching, and compile kernel
1212
- ci/: packaging, metadata, modules, and telegram helpers
13-
- py/: small python helpers
13+
- py/: uv-managed python helpers
1414
- modules/: modules.load for xaga modules packaging
1515
- kernel_patches/: kernel patches
1616
- .github/workflows/: ci and release workflows
@@ -20,13 +20,13 @@ pulls sources and tools, applies optional patches, then builds and packages the
2020
ubuntu/debian:
2121

2222
```bash
23-
sudo apt install bc bison ccache curl flex git tar wget aria2 jq zip zstd upx build-essential python3-requests libfaketime lz4 just
23+
sudo apt install bc bison ccache curl flex git tar wget aria2 jq zip zstd upx build-essential libfaketime lz4 just shellcheck shfmt uv
2424
````
2525

2626
fedora:
2727

2828
```bash
29-
sudo dnf install bc bison ccache curl flex git tar wget aria2 jq zip zstd upx make python3-requests libfaketime lz4 just
29+
sudo dnf install bc bison ccache curl flex git tar wget aria2 jq zip zstd upx make libfaketime lz4 just ShellCheck shfmt uv
3030
```
3131

3232
## run
@@ -53,6 +53,12 @@ run checks:
5353
just check
5454
```
5555

56+
python type check:
57+
58+
```bash
59+
just py-check
60+
```
61+
5662
clean build:
5763

5864
```bash
@@ -67,7 +73,7 @@ just clean
6773
| KSU | enable kernelsu | bool |
6874
| SUSFS | enable susfs | bool |
6975
| LXC | apply the lxc patch, xaga only | bool |
70-
| STOCK_CONFIG | apply the stock config patch | bool |
76+
| STOCK_CONFIG | stock config mode | str |
7177
| BRANCH_OVERRIDE | use a different kernel branch | str |
7278
| JOBS | set make job count | int |
7379
| RESET_SOURCES | re-clone sources and tools before building | bool |
@@ -79,6 +85,8 @@ just clean
7985
notes:
8086

8187
- bool accepts true/false, t/f, yes/no, y/n, on/off, 1/0
88+
- STOCK_CONFIG accepts `auto`, `true`, or `false`
89+
- `auto` means off for xaga and on for generic
8290
- SUSFS needs KSU=true
8391
- LXC only works with BUILD_TARGET=xaga
8492
- TG_NOTIFY=true needs TG_BOT_TOKEN and TG_CHAT_ID
@@ -89,7 +97,6 @@ notes:
8997
| ----------------------------- | ----------------------- |
9098
| work/ | kernel out |
9199
| out/\<package>-AnyKernel3.zip | flashable package |
92-
| out/\<package>-boot.img | xaga boot image |
93100
| out/\<package>-boot-raw.img | generic raw boot image |
94101
| out/\<package>-boot-gz.img | generic gzip boot image |
95102
| out/\<package>-boot-lz4.img | generic lz4 boot image |

build.sh

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,72 @@ count() {
2727
}
2828

2929
validate_env() {
30-
info "Validating environment variables..."
31-
if [[ -z ${GH_TOKEN:-} ]]; then
32-
if [[ -x "$CLANG_BIN/clang" ]]; then
33-
:
34-
elif is_ci; then
35-
error "Required Github PAT missing: GH_TOKEN"
36-
else
37-
warn "GH_TOKEN isn't set, requests may be rate-limited."
38-
fi
39-
fi
40-
41-
# Telegram checks
42-
if is_true "$TG_NOTIFY"; then
43-
: "${TG_BOT_TOKEN:?Required Telegram Bot Token missing: TG_BOT_TOKEN}"
44-
: "${TG_CHAT_ID:?Required chat ID missing: TG_CHAT_ID}"
45-
export TG_BOT_TOKEN
46-
export TG_CHAT_ID
47-
fi
48-
49-
# Config checks
50-
if is_true "$SUSFS" && ! is_true "$KSU"; then
51-
error "Cannot use SUSFS without KernelSU"
52-
fi
30+
local stage="$1"
31+
32+
case "$stage" in
33+
github)
34+
# before fetching github release assets
35+
if [[ -z ${GH_TOKEN:-} ]]; then
36+
if [[ -x "$CLANG_BIN/clang" && -f "$LIBFAKESTAT" ]]; then
37+
:
38+
elif is_ci; then
39+
error "Required Github PAT missing: GH_TOKEN"
40+
else
41+
warn "GH_TOKEN isn't set, requests may be rate-limited."
42+
fi
43+
fi
44+
;;
45+
telegram)
46+
# before sending telegram updates
47+
if is_true "$TG_NOTIFY"; then
48+
: "${TG_BOT_TOKEN:?Required Telegram Bot Token missing: TG_BOT_TOKEN}"
49+
: "${TG_CHAT_ID:?Required chat ID missing: TG_CHAT_ID}"
50+
export TG_BOT_TOKEN
51+
export TG_CHAT_ID
52+
fi
53+
;;
54+
config)
55+
# before build prep
56+
if is_true "$SUSFS" && ! is_true "$KSU"; then
57+
error "Cannot use SUSFS without KernelSU"
58+
fi
59+
60+
if is_true "$LXC" && [[ $BUILD_TARGET != "xaga" ]]; then
61+
error "LXC is not supported for $BUILD_TARGET target"
62+
fi
63+
;;
64+
*)
65+
fatal "Unknown environment validation stage: $stage"
66+
;;
67+
esac
68+
}
5369

54-
if is_true "$LXC" && [[ $BUILD_TARGET != "xaga" ]]; then
55-
error "LXC is not supported for $BUILD_TARGET target"
56-
fi
70+
validate_deps() {
71+
local stage="$1"
72+
73+
case "$stage" in
74+
base)
75+
# before the build starts
76+
require_cmds \
77+
aria2c bash ccache chmod cp curl date find git head hexdump make mkdir \
78+
python3 rm sed sha256sum sort tar tee uv zip zstd
79+
;;
80+
patching)
81+
# before applying patches
82+
require_cmds patch
83+
;;
84+
modules)
85+
# before xaga module packaging
86+
require_cmds depmod llvm-strip xz
87+
;;
88+
bootimg)
89+
# before generic boot image packaging
90+
require_cmds gzip lz4 unzip
91+
;;
92+
*)
93+
fatal "Unknown dependency validation stage: $stage"
94+
;;
95+
esac
5796
}
5897

5998
main() {
@@ -62,7 +101,6 @@ main() {
62101

63102
count init_build
64103
count init_logging
65-
count validate_env
66104
count send_start_msg
67105
count prepare_dirs
68106
count fetch_sources

build/all.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
source "$WORKSPACE/build/utils.sh"
55
source "$WORKSPACE/build/setup.sh"
6-
source "$WORKSPACE/build/patch.sh"
76
source "$WORKSPACE/build/compile.sh"

0 commit comments

Comments
 (0)