From bdc968d8bbabb66e498c3403d05a591c952fe071 Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:46:12 -0700 Subject: [PATCH 1/8] fix(ci): update README deps and build.yml --- .github/workflows/build.yml | 26 ++++---------------------- README.md | 6 +++--- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c020d7..63b3ef9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ env: jobs: push-ghcr: name: Build and push image - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest permissions: contents: read packages: write @@ -21,12 +21,12 @@ jobs: strategy: fail-fast: false matrix: - major_version: [38, 39] + major_version: [39, 40] include: - - major_version: 38 + - major_version: 39 is_latest_version: true is_stable_version: true - - major_version: 39 + - major_version: 40 is_latest_version: true is_stable_version: false steps: @@ -139,21 +139,3 @@ jobs: if: github.event_name != 'pull_request' run: | echo "${{ toJSON(steps.push.outputs) }}" - - copr-build: - permissions: - contents: read - packages: read - runs-on: ubuntu-latest - container: - image: ghcr.io/akdev1l/copr-build:latest - if: github.event_name != 'pull_request' - steps: - - name: trigger copr build - uses: akdev1l/copr-build@main - id: copr-build - env: - COPR_API_TOKEN_CONFIG: ${{ secrets.UBLUE_COPR_API_TOKEN }} - with: - owner: ublue-os - project-name: staging diff --git a/README.md b/README.md index 13b6ee5..647bcae 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Small update program written in python intended for use in Universal Blue that u Includes systemd timers and services for auto update -dependencies (fedora): ```sudo dnf install python3-psutil libnotify``` +dependencies (fedora): ```sudo dnf install python3-psutil libnotify && pip install topgrade``` # Usage @@ -16,14 +16,14 @@ You can add this to your image by simply pulling down and installing the rpm: ``` COPY --from=ghcr.io/ublue-os/ublue-update:latest /rpms/ublue-update.noarch.rpm /tmp/rpms/ -RUN rpm-ostree install /tmp/rpms/ublue-update.noarch.rpm +RUN pip install topgrade && rpm-ostree install /tmp/rpms/ublue-update.noarch.rpm ``` If you are on an image derived from uBlue main: ``` COPY --from=ghcr.io/ublue-os/ublue-update:latest /rpms/ublue-update.noarch.rpm /tmp/rpms/ -RUN rpm-ostree override remove ublue-os-update-services && rpm-ostree install /tmp/rpms/ublue-update.noarch.rpm +RUN pip install topgrade && rpm-ostree override remove ublue-os-update-services && rpm-ostree install /tmp/rpms/ublue-update.noarch.rpm ``` > **Note** From f62e60e7a329e1b585ea7bda5807c319c993975b Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:52:09 -0700 Subject: [PATCH 2/8] style: reformat and remove unused imports --- src/ublue_update/cli.py | 13 ++----- src/ublue_update/update_inhibitors/custom.py | 36 +++++++++++-------- .../update_inhibitors/hardware.py | 10 +++--- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index 12af882..71120aa 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -127,9 +127,7 @@ def run_updates(system, system_update_available): log.debug(out.stdout.decode("utf-8")) if out.returncode != 0: - print( - f"topgrade returned code {out.returncode}, program output:" - ) + print(f"topgrade returned code {out.returncode}, program output:") print(out.stdout.decode("utf-8")) os._exit(out.returncode) @@ -140,9 +138,7 @@ def run_updates(system, system_update_available): except KeyError as e: log.error(f"failed to get xdg_runtime_dir for user: {user['Name']}", e) break - log.info( - f"""Running update for user: '{user['Name']}'""" - ) + log.info(f"""Running update for user: '{user['Name']}'""") out = subprocess.run( [ @@ -211,10 +207,7 @@ def main(): action="store_true", help="wait for transactions to complete and exit", ) - parser.add_argument( - "--config", - help="use the specified config file" - ) + parser.add_argument("--config", help="use the specified config file") parser.add_argument( "--system", action="store_true", diff --git a/src/ublue_update/update_inhibitors/custom.py b/src/ublue_update/update_inhibitors/custom.py index cb83398..6b85468 100644 --- a/src/ublue_update/update_inhibitors/custom.py +++ b/src/ublue_update/update_inhibitors/custom.py @@ -1,4 +1,3 @@ -import psutil import subprocess from typing import List, Optional from logging import getLogger @@ -9,22 +8,28 @@ def run_custom_check_script(script) -> dict: - if 'run' in script and 'shell' not in script: - raise Exception('checks.scripts.*: \'shell\' must be specified when \'run\' is used') + if "run" in script and "shell" not in script: + raise Exception( + "checks.scripts.*: 'shell' must be specified when 'run' is used" + ) - if 'run' in script and 'file' in script: - raise Exception('checks.scripts.*: Only one of \'run\' and \'file\' must be set for a given script') + if "run" in script and "file" in script: + raise Exception( + "checks.scripts.*: Only one of 'run' and 'file' must be set for a given script" + ) log.debug(f"Running script {script}") # Run the specified custom script - if 'run' in script: - run_args = [script['shell'], '-c', script['run']] - elif 'shell' in script: - run_args = [script['shell'], script['file']] + if "run" in script: + run_args = [script["shell"], "-c", script["run"]] + elif "shell" in script: + run_args = [script["shell"], script["file"]] else: - run_args = [script['file']] - script_result = subprocess.run(run_args, capture_output=True, text=True, check=False) + run_args = [script["file"]] + script_result = subprocess.run( + run_args, capture_output=True, text=True, check=False + ) # An exit code of 0 means "OK", a non-zero exit code # means "Do not download or perform updates right now" @@ -40,10 +45,12 @@ def run_custom_check_script(script) -> dict: # to catch any interpreter errors etc. script_stderr = script_result.stderr.strip() if not script_pass and len(script_stderr) > 0: - log.warning(f"A custom check script failed and wrote the following to STDERR:\n====\n{script_stderr}\n====") + log.warning( + f"A custom check script failed and wrote the following to STDERR:\n====\n{script_stderr}\n====" + ) fallback_message = "A custom check script returned a non-0 exit code" - script_message = script.get('message') or script_output or fallback_message + script_message = script.get("message") or script_output or fallback_message return { "passed": script_pass, @@ -53,13 +60,12 @@ def run_custom_check_script(script) -> dict: def run_custom_check_scripts() -> List[dict]: results = [] - for script in (cfg.custom_check_scripts or []): + for script in cfg.custom_check_scripts or []: results.append(run_custom_check_script(script)) return results def check_custom_inhibitors() -> bool: - custom_inhibitors = run_custom_check_scripts() failures = [] diff --git a/src/ublue_update/update_inhibitors/hardware.py b/src/ublue_update/update_inhibitors/hardware.py index c3f77e1..81b42c3 100644 --- a/src/ublue_update/update_inhibitors/hardware.py +++ b/src/ublue_update/update_inhibitors/hardware.py @@ -1,6 +1,5 @@ import psutil import subprocess -from typing import Optional from logging import getLogger from ublue_update.config import cfg @@ -29,7 +28,8 @@ def check_network_not_metered() -> dict: # Use busctl CLI to query the NetworkManager via D-Bus for # the current metering status of the connection. # The output on stdout will be " ". - metered_status = subprocess.run([ + metered_status = subprocess.run( + [ "busctl", "get-property", "org.freedesktop.NetworkManager", @@ -50,7 +50,7 @@ def check_network_not_metered() -> dict: # NM_METERED_GUESS_YES = 3 # Metered, the value was guessed # NM_METERED_GUESS_NO = 4 # Not metered, the value was guessed # - is_network_metered = metered_status.strip() in ['u 1', 'u 3'] + is_network_metered = metered_status.strip() in ["u 1", "u 3"] return { "passed": not is_network_metered, "message": "Network is metered", @@ -65,7 +65,8 @@ def check_battery_status() -> dict: battery_pass: bool = True if battery_status is not None: battery_pass = ( - battery_status.percent >= cfg.min_battery_percent or battery_status.power_plugged + battery_status.percent >= cfg.min_battery_percent + or battery_status.power_plugged ) return { "passed": battery_pass, @@ -109,7 +110,6 @@ def check_mem_percentage() -> dict: def check_hardware_inhibitors() -> bool: - hardware_inhibitors = [ check_network_status(), check_network_not_metered(), From f4acbf109e74d2fbba7cc13b7c446b061fb895bd Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Mon, 10 Jun 2024 15:42:49 -0700 Subject: [PATCH 3/8] fix(ci): intall topgrade before building --- Containerfile.builder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Containerfile.builder b/Containerfile.builder index df05bcc..d4a5036 100644 --- a/Containerfile.builder +++ b/Containerfile.builder @@ -6,6 +6,8 @@ WORKDIR /app ADD . /app +RUN dnf install python3-pip && pip install topgrade + RUN dnf install \ --disablerepo='*' \ --enablerepo='fedora,updates' \ @@ -17,7 +19,7 @@ RUN dnf install \ rpm-build && \ mkdir -p "$UBLUE_ROOT" && \ rpkg spec --outdir "$UBLUE_ROOT" && \ - dnf builddep -y output/ublue-update.spec + dnf builddep -y output/ublue-update.spec \ FROM builder AS rpm From e328071e117ad73dc3874ee1b689ecfea294611a Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:49:15 -0700 Subject: [PATCH 4/8] fix: fedora version 40, remove rpm file extractor --- Containerfile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Containerfile b/Containerfile index d5af966..9421a6b 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" +ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}" FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder @@ -22,16 +22,6 @@ RUN dnf install \ dnf builddep -y output/ublue-update.spec && \ make build-rpm -# Dump a file list for each RPM for easier consumption -RUN \ - for RPM in ${UBLUE_ROOT}/noarch/*.rpm; do \ - NAME="$(rpm -q $RPM --queryformat='%{NAME}')"; \ - mkdir -p "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \ - rpm2cpio "${RPM}" | cpio -idmv --directory "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \ - mkdir -p ${UBLUE_ROOT}/ublue-os/rpms/; \ - cp "${RPM}" "${UBLUE_ROOT}/ublue-os/rpms/$(rpm -q "${RPM}" --queryformat='%{NAME}.%{ARCH}.rpm')"; \ - done - FROM scratch ENV UBLUE_ROOT=/app/output From da42c718c9fcc180c28c79f26b7c43f92003aa6d Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:47:10 -0700 Subject: [PATCH 5/8] fix: revert --- Containerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index 9421a6b..d5af966 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}" +ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}" FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder @@ -22,6 +22,16 @@ RUN dnf install \ dnf builddep -y output/ublue-update.spec && \ make build-rpm +# Dump a file list for each RPM for easier consumption +RUN \ + for RPM in ${UBLUE_ROOT}/noarch/*.rpm; do \ + NAME="$(rpm -q $RPM --queryformat='%{NAME}')"; \ + mkdir -p "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \ + rpm2cpio "${RPM}" | cpio -idmv --directory "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \ + mkdir -p ${UBLUE_ROOT}/ublue-os/rpms/; \ + cp "${RPM}" "${UBLUE_ROOT}/ublue-os/rpms/$(rpm -q "${RPM}" --queryformat='%{NAME}.%{ARCH}.rpm')"; \ + done + FROM scratch ENV UBLUE_ROOT=/app/output From d2cc2a63b2c6cf972fb5239d0e8148dca6827a37 Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:57:11 -0700 Subject: [PATCH 6/8] fix: update tags --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63b3ef9..2410035 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: major_version: [39, 40] include: - major_version: 39 - is_latest_version: true + is_latest_version: false is_stable_version: true - major_version: 40 is_latest_version: true From 1635cca16b5e7a6e0b6b89beebe373ffeb1baaff Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Sat, 3 Aug 2024 18:59:24 -0700 Subject: [PATCH 7/8] fix: change runner to 24.04 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2410035..b0a2fd9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ env: jobs: push-ghcr: name: Build and push image - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: read packages: write From 856dee270f75490a6be4620e4b99d5157894f6fa Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:09:37 -0700 Subject: [PATCH 8/8] fix: remove unnecessary \ --- Containerfile.builder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile.builder b/Containerfile.builder index d4a5036..f820f85 100644 --- a/Containerfile.builder +++ b/Containerfile.builder @@ -19,7 +19,7 @@ RUN dnf install \ rpm-build && \ mkdir -p "$UBLUE_ROOT" && \ rpkg spec --outdir "$UBLUE_ROOT" && \ - dnf builddep -y output/ublue-update.spec \ + dnf builddep -y output/ublue-update.spec FROM builder AS rpm