diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..0c91440 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + test: + name: tests (Python ${{ matrix.python }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Ubuntu 22.04, Debian 12, Ubuntu 24.04, Debian 13 + python: ["3.10", "3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - run: python3 --version + - run: make test + + lint: + runs-on: ubuntu-latest + env: + SHELLCHECK_VERSION: v0.10.0 + steps: + - uses: actions/checkout@v4 + - name: Install shellcheck + run: | + curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \ + | tar -xJ -C /tmp + echo "/tmp/shellcheck-${SHELLCHECK_VERSION}" >> "$GITHUB_PATH" + - run: shellcheck --version + - run: make lint diff --git a/Makefile b/Makefile index cb938c2..e08dc17 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,4 @@ test: python3 -m unittest discover -s tests lint: - shellcheck agent/kernelwatch-agent agent/install.sh server/install.sh server/kernelwatch.sh + shellcheck agent/kernelwatch-agent agent/install.sh agent/deploy.sh server/install.sh server/kernelwatch.sh diff --git a/README.md b/README.md index 51db3c1..648bf47 100644 --- a/README.md +++ b/README.md @@ -393,6 +393,10 @@ make test # unit + integration tests (stdlib unittest) make lint # shellcheck, if available ``` +Gitea Actions (`.gitea/workflows/ci.yml`) runs both on every push to `main` +and every pull request: the tests on Python 3.10–3.13 (the versions on the +supported Ubuntu and Debian releases) and shellcheck on the shell scripts. + The tests run a real server on an ephemeral port. They also run the real agent script against stubbed `dpkg-query`/`apt-get`/`needrestart`/`uname` and a fake filesystem root (`KERNELWATCH_ROOT`), including one end-to-end agent → server diff --git a/agent/deploy.sh b/agent/deploy.sh index 4012a5d..050fb0f 100755 --- a/agent/deploy.sh +++ b/agent/deploy.sh @@ -126,8 +126,11 @@ deploy_one() { if [[ $mode != upgrade ]]; then # 2. Get a token from the dashboard and hand it over on stdin, never argv. say " $mode $name on $DASHBOARD" - token=$(fetch_token "$name" | tr -d '[:space:]') && [[ -n $token ]] || - { echo " could not get a token for $name" >&2; cleanup; return 1; } + if ! token=$(fetch_token "$name" | tr -d '[:space:]') || [[ -z $token ]]; then + echo " could not get a token for $name" >&2 + cleanup + return 1 + fi printf '%s\n' "$token" | ssh -T "$target" "umask 077 && cat > '$dir/token'" || { cleanup; return 1; } install+=(--server "$SERVER_URL" --token-file "$dir/token")