Skip to content

Commit

Permalink
fix: type errors, CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Nov 24, 2024
1 parent 447e54f commit a1f34fa
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 46 deletions.
161 changes: 161 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: build development package
on:
pull_request:
merge_group:
push:
branches:
- main
workflow_dispatch:
env:
IMAGE_NAME: ublue-update
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}

jobs:
push-ghcr:
name: Build and push image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
major_version: [39, 40, 41]
include:
- major_version: 39
is_latest_version: false
is_stable_version: true
- major_version: 40
is_latest_version: true
is_stable_version: false
- major_version: 41
is_latest_version: false
is_stable_version: false
steps:
# Checkout push-to-registry action GitHub repository
- name: Checkout Push to Registry action
uses: actions/checkout@v4

- name: Generate tags
id: generate-tags
shell: bash
run: |
# Generate a timestamp for creating an image version history
TIMESTAMP="$(date +%Y%m%d)"
MAJOR_VERSION="${{ matrix.major_version }}"
COMMIT_TAGS=()
BUILD_TAGS=()
# Have tags for tracking builds during pull request
SHA_SHORT="${GITHUB_SHA::7}"
COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}-${MAJOR_VERSION}")
COMMIT_TAGS+=("${SHA_SHORT}-${MAJOR_VERSION}")
if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \
[[ "${{ matrix.is_stable_version }}" == "true" ]]; then
COMMIT_TAGS+=("pr-${{ github.event.pull_request.number }}")
COMMIT_TAGS+=("${SHA_SHORT}")
fi
BUILD_TAGS=("${MAJOR_VERSION}" "${MAJOR_VERSION}-${TIMESTAMP}")
if [[ "${{ matrix.is_latest_version }}" == "true" ]] && \
[[ "${{ matrix.is_stable_version }}" == "true" ]]; then
BUILD_TAGS+=("latest")
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Generated the following commit tags: "
for TAG in "${COMMIT_TAGS[@]}"; do
echo "${TAG}"
done
alias_tags=("${COMMIT_TAGS[@]}")
else
alias_tags=("${BUILD_TAGS[@]}")
fi
echo "Generated the following build tags: "
for TAG in "${BUILD_TAGS[@]}"; do
echo "${TAG}"
done
echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT
# Build image using Buildah action
# - name: Build Image
# id: build_image
# uses: redhat-actions/buildah-build@v2
# with:
# containerfiles: |
# ./Containerfile
# image: ${{ env.IMAGE_NAME }}
# tags: |
# ${{ steps.generate-tags.outputs.alias_tags }}
# build-args: |
# FEDORA_MAJOR_VERSION=${{ matrix.major_version }}
# oci: true

- name: Build Image
id: build_image
env:
FEDORA_MAJOR_VERSION: ${{ matrix.major_version }}
run: |
just container-build
with:
containerfiles: |
./Containerfile
image: ${{ env.IMAGE_NAME }}
tags: |
${{ steps.generate-tags.outputs.alias_tags }}
build-args: |
FEDORA_MAJOR_VERSION=${{ matrix.major_version }}
oci: true


# Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR.
# https://github.com/macbre/push-to-ghcr/issues/12
- name: Lowercase Registry
id: registry_case
uses: ASzc/change-string-case-action@v6
with:
string: ${{ env.IMAGE_REGISTRY }}

# Push the image to GHCR (Image Registry)
- name: Push To GHCR
uses: redhat-actions/push-to-registry@v2
id: push
if: github.event_name != 'pull_request'
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ steps.registry_case.outputs.lowercase }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Sign container
- uses: sigstore/[email protected]
if: github.event_name != 'pull_request'

- name: Sign container image
if: github.event_name != 'pull_request'
run: |
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ steps.registry_case.outputs.lowercase }}/${{ env.IMAGE_NAME }}@${TAGS}
env:
TAGS: ${{ steps.push.outputs.digest }}
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}

- name: Echo outputs
if: github.event_name != 'pull_request'
run: |
echo "${{ toJSON(steps.push.outputs) }}"
19 changes: 18 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,25 @@ jobs:
echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT
# Build image using Buildah action
# - name: Build Image
# id: build_image
# uses: redhat-actions/buildah-build@v2
# with:
# containerfiles: |
# ./Containerfile
# image: ${{ env.IMAGE_NAME }}
# tags: |
# ${{ steps.generate-tags.outputs.alias_tags }}
# build-args: |
# FEDORA_MAJOR_VERSION=${{ matrix.major_version }}
# oci: true

- name: Build Image
id: build_image
uses: redhat-actions/buildah-build@v2
env:
FEDORA_MAJOR_VERSION: ${{ matrix.major_version }}
run: |
just container-build
with:
containerfiles: |
./Containerfile
Expand All @@ -92,6 +108,7 @@ jobs:
FEDORA_MAJOR_VERSION=${{ matrix.major_version }}
oci: true


# Workaround bug where capital letters in your GitHub username make it impossible to push to GHCR.
# https://github.com/macbre/push-to-ghcr/issues/12
- name: Lowercase Registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

build-release:
name: Build and push rpm package
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: write
packages: write
Expand Down
30 changes: 5 additions & 25 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG TEST_IMAGE="${TEST_IMAGE:-ghcr.io/ublue-os/base-main:40}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-40}"
ARG TEST_IMAGE="${TEST_IMAGE:-ghcr.io/ublue-os/base-main:41}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-41}"

FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder

Expand All @@ -9,29 +9,9 @@ WORKDIR /app

ADD . /app

RUN dnf install \
--disablerepo='*' \
--enablerepo='fedora,updates' \
--setopt install_weak_deps=0 \
--nodocs \
--assumeyes \
'dnf-command(builddep)' \
rpkg \
rpm-build && \
mkdir -p "$UBLUE_ROOT" && \
rpkg spec --outdir "$UBLUE_ROOT" && \
dnf builddep -y output/ublue-update.spec && \
just 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
RUN dnf install -y just

RUN just build-rpm-container

FROM ${TEST_IMAGE}

Expand Down
18 changes: 18 additions & 0 deletions Containerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-41}"

FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder

ENV UBLUE_ROOT=/app/output

WORKDIR /app
ADD . /app

RUN dnf install -y just git

RUN just build-rpm

FROM scratch

ENV UBLUE_ROOT=/app/output
COPY --from=builder ${UBLUE_ROOT}/ublue-os/rpms /tmp/rpms
38 changes: 32 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ export TARGET := "ublue-update"
export SOURCE_DIR := UBLUE_ROOT + "/" + TARGET
export RPMBUILD := UBLUE_ROOT + "/rpmbuild"

export GITHUB_REF := env_var_or_default("GITHUB_REF","refs/tags/v1.0.0+" + `git rev-parse --short HEAD`)
# export GITHUB_REF := env_var_or_default("GITHUB_REF","refs/tags/v1.0.0+" + `git rev-parse --short HEAD`)

# Define the GITHUB_REF variable if it's not already set
default:
just --list

venv-create:
/usr/bin/python -m venv venv
source venv/bin/activate && pip3 install .
echo 'Enter: `source venv/bin/activate` to enter the venv'

default:
just --list

build:
black --check src
python3 -m build
Expand All @@ -28,22 +28,48 @@ spec: output
build-rpm:
rpkg local --outdir "$PWD/output"

build-rpm-container:
#!/usr/bin/env bash
dnf install \
--disablerepo='*' \
--enablerepo='fedora,updates' \
--setopt install_weak_deps=0 \
--nodocs \
--assumeyes \
'dnf-command(builddep)' \
rpkg \
rpm-build \
git
mkdir -p "$UBLUE_ROOT"
rpkg spec --outdir "$UBLUE_ROOT"
dnf builddep -y output/ublue-update.spec
rpkg local --outdir "$PWD/output"
# file rpm filelist
for RPM in ${UBLUE_ROOT}/noarch/*.rpm; do
NAME="$(rpm -q $RPM --queryformat='%{NAME}')"
mkdir -p "${UBLUE_ROOT}/ublue-os/rpms/"
cp "${RPM}" "${UBLUE_ROOT}/ublue-os/rpms/$(rpm -q "${RPM}" --queryformat='%{NAME}.%{ARCH}.rpm')"
done

output:
mkdir -p output

format:
black src
flake8 src


dnf-install:
dnf install -y "output/noarch/*.rpm"

container-build:
podman build . -t testing -f Containerfile
podman build . -t test-container -f Containerfile

container-test:
#!/usr/bin/env bash
podman run -d --replace --name ublue_update_test --security-opt label=disable --device /dev/fuse:rw --privileged testing
podman run -d --replace --name ublue_update_test --security-opt label=disable --device /dev/fuse:rw --privileged test-container
while [[ "$(podman exec ublue_update_test systemctl is-system-running)" != "running" && "$(podman exec ublue_update_test systemctl is-system-running)" != "degraded" ]]; do
echo "Waiting for systemd to finish booting..."
sleep 1
Expand Down
13 changes: 7 additions & 6 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ublue_update.filelock import acquire_lock, release_lock


def notify(title: str, body: str, actions: list = [], urgency: str = "normal"):
def notify(title: str, body: str, actions: list = [], urgency: str = "normal") -> subprocess.CompletedProcess[bytes] | None:
if not cfg.dbus_notify:
return
process_uid = os.getuid()
Expand All @@ -31,17 +31,18 @@ def notify(title: str, body: str, actions: list = [], urgency: str = "normal"):
if actions != []:
for action in actions:
args.append(f"--action={action}")
# If root run per user:
if process_uid == 0:
users = []
try:
users = get_active_users()
except KeyError as e:
log.error("failed to get active logind session info", e)
out: subprocess.CompletedProcess[bytes] | None = None
for user in users:
out = run_uid(user[0], args)
if actions != []:
return out
return
return out

out = subprocess.run(args, capture_output=True)
return out

Expand Down Expand Up @@ -80,7 +81,7 @@ def run_updates(system, system_update_available, dry_run):
filelock_path = "/run/ublue-update.lock"
if process_uid != 0:
xdg_runtime_dir = os.environ.get("XDG_RUNTIME_DIR")
if os.path.isdir(xdg_runtime_dir):
if xdg_runtime_dir is not None and os.path.isdir(xdg_runtime_dir):
filelock_path = f"{xdg_runtime_dir}/ublue-update.lock"
fd = acquire_lock(filelock_path)
if fd is None:
Expand Down Expand Up @@ -158,7 +159,7 @@ def run_updates(system, system_update_available, dry_run):
["universal-blue-update-reboot=Reboot Now"],
)
# if the user has confirmed the reboot
if "universal-blue-update-reboot" in out.stdout.decode("utf-8"):
if out is not None and "universal-blue-update-reboot" in out.stdout.decode("utf-8"):
subprocess.run(["systemctl", "reboot"])
else:
if system:
Expand Down
Loading

0 comments on commit a1f34fa

Please sign in to comment.