diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 52153b5..d94a83d 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,4 +1,5 @@ -# docs: every function documented (tools/doc_check.py). +# docs: every function documented (tools/doc_check.py), and the app's AT +# command reference D-Modem's (tools/at_reference.py). # build: the APK (all four ABIs), the unit tests and lint. # native: the native engine on the runner against a dmodemd over loopback # SIP (native-test). @@ -61,6 +62,9 @@ jobs: - name: Every function documented run: python3 tools/doc_check.py + - name: The AT command reference is D-Modem's + run: python3 tools/at_reference.py --check + build: runs-on: ubuntu-24.04 # (a hung test ends here, not at GitHub's 6 hours) diff --git a/.github/workflows/d-modem-bump.yml b/.github/workflows/d-modem-bump.yml index 401a813..7b11bba 100644 --- a/.github/workflows/d-modem-bump.yml +++ b/.github/workflows/d-modem-bump.yml @@ -1,5 +1,6 @@ # D-Modem bump: moves the external/d-modem-re submodule to D-Modem's -# latest main and opens (or updates) a pull request for it, set to merge +# latest main, with the AT command reference that comes with it (the +# app's assets' copy, tools/at_reference.py), and opens (or updates) a pull request for it, set to merge # by itself once its checks pass. Daily, by hand (Actions > D-Modem bump > # Run workflow), or from D-Modem (a repository_dispatch of type # "d-modem-main", for when its main changes). @@ -70,6 +71,7 @@ jobs: exit 0 fi git -C external/d-modem-re checkout --quiet "$new" + python3 tools/at_reference.py echo "changed=true" >> "$GITHUB_OUTPUT" { echo 'log< ${NEW:0:7} (D-Modem's main)." \ + -m "external/d-modem-re: ${OLD:0:7} -> ${NEW:0:7} (D-Modem's main), and its AT command reference." \ -m "Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" git push --force origin "$BRANCH" diff --git a/app/src/main/assets/docs/README.md b/app/src/main/assets/docs/README.md index a2e53e1..63db0c2 100644 --- a/app/src/main/assets/docs/README.md +++ b/app/src/main/assets/docs/README.md @@ -3,7 +3,9 @@ `at_commands.pdf` is D-Modem's AT command reference, the A5 manual: `docs/at_commands.pdf` in [D-Modem/D-Modem](https://github.com/D-Modem/D-Modem), built from `docs/at/at_commands.tex` (`docs/at/build.sh`). This copy is -from its main at 7f53883. When the manual changes, copy the new PDF here. +from its main at 3f7d6b2. `tools/at_reference.py` copies it from the D-Modem submodule +(`external/d-modem-re`); the D-Modem bump workflow runs it with each bump, +and CI's docs job fails when this copy isn't the submodule's. The app shows it in Settings, AT commands, and from the terminal's menu (`ui/AtReference.kt`). diff --git a/app/src/main/assets/docs/at_commands.pdf b/app/src/main/assets/docs/at_commands.pdf index 60639cd..dd191c3 100644 Binary files a/app/src/main/assets/docs/at_commands.pdf and b/app/src/main/assets/docs/at_commands.pdf differ diff --git a/docs/building.md b/docs/building.md index 7f17615..883aebe 100644 --- a/docs/building.md +++ b/docs/building.md @@ -61,7 +61,8 @@ CI (`.github/workflows/android.yml`) runs all three, and that check; it needs a `DMODEM_TOKEN` secret that can read the private D-Modem submodule. `.github/workflows/d-modem-bump.yml` keeps the submodule on D-Modem's -main: daily (or by hand) it opens a pull request that moves it, set to +main: daily (or by hand) it opens a pull request that moves it, with the +AT command reference in the app's assets (`tools/at_reference.py`), set to merge once CI passes. It needs a `DMODEM_BUMP_TOKEN` secret (its header says which permissions). diff --git a/tools/at_reference.py b/tools/at_reference.py new file mode 100755 index 0000000..d0f8fee --- /dev/null +++ b/tools/at_reference.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright (C) 2026 Neo-Desktop +# +# at_reference.py - the app's AT command reference (its assets' +# docs/at_commands.pdf) from the D-Modem submodule's +# docs/at_commands.pdf, and the commit its README names +# +# tools/at_reference.py copies it, if it differs +# tools/at_reference.py --check exit 1 if the app's copy is not the +# submodule's +"""The app's AT command reference from the D-Modem submodule's.""" + +import os +import re +import subprocess +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +DMODEM = os.path.join(ROOT, "external", "d-modem-re") +SOURCE = os.path.join(DMODEM, "docs", "at_commands.pdf") +ASSET = os.path.join(ROOT, "app", "src", "main", "assets", "docs", "at_commands.pdf") +README = os.path.join(ROOT, "app", "src", "main", "assets", "docs", "README.md") + + +def read(path): + """A file's bytes.""" + with open(path, "rb") as f: + return f.read() + + +def commit(): + """The submodule's commit, short.""" + return subprocess.run(["git", "-C", DMODEM, "rev-parse", "--short=7", "HEAD"], + check=True, capture_output=True, text=True).stdout.strip() + + +def main(): + """Copy (or with --check, compare) the PDF; 1 when --check finds it stale.""" + if not os.path.exists(SOURCE): + sys.exit(f"{SOURCE} not found: git submodule update --init external/d-modem-re") + new = read(SOURCE) + if new == read(ASSET): + print("AT command reference: up to date") + return 0 + if "--check" in sys.argv[1:]: + print("AT command reference: the app's copy is not D-Modem's " + "(tools/at_reference.py copies it)", file=sys.stderr) + return 1 + with open(ASSET, "wb") as f: + f.write(new) + with open(README, encoding="utf-8") as f: + text = f.read() + text = re.sub(r"from its main at [0-9a-f]+\.", f"from its main at {commit()}.", text) + with open(README, "w", encoding="utf-8") as f: + f.write(text) + print(f"AT command reference: copied from D-Modem {commit()}") + return 0 + + +if __name__ == "__main__": + sys.exit(main())