diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af3819c..84298ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,36 +67,41 @@ jobs: # is reported by the sync, not counted as a change. Retries ride out a dropped connection; # the timeout stops a hung download from holding the job for hours. # - # The downloaded .debs are cached, so a run only fetches the package indexes and anything - # newer than the cache; the Ubuntu mirrors and the PPA are both slow at times. The key - # changes with the runner image (roughly weekly) or this file, which picks up KiCad point - # releases; a new key restores the previous cache, and autoclean drops superseded .debs - # before the new one is saved. - # ImageOS/ImageVersion are runner environment variables, not in the `env` context. + # ci/install_kicad.sh keeps apt's lists and .debs in ~/apt-cache and, when that cache is + # recent, installs from it with no network: Launchpad and the Ubuntu mirrors are each slow + # or down at times (see the script). The cache is saved after every run that changed it, + # including one that failed or timed out, so a partial download is never thrown away. + # Each save gets a new key (caches are immutable); restores take the newest by prefix. + # A PR can restore main's cache, but main can't restore a PR's. + # ImageOS is a runner environment variable, not in the `env` context. - name: Read runner image id: image - run: | - echo "os=${ImageOS}" >> "$GITHUB_OUTPUT" - echo "version=${ImageVersion}" >> "$GITHUB_OUTPUT" + run: echo "os=${ImageOS}" >> "$GITHUB_OUTPUT" - name: Restore KiCad package cache - uses: actions/cache@v6 + id: cache + uses: actions/cache/restore@v6 with: path: ~/apt-cache - key: kicad-debs-${{ steps.image.outputs.os }}-${{ steps.image.outputs.version }}-${{ hashFiles('.github/workflows/ci.yml') }} - restore-keys: kicad-debs-${{ steps.image.outputs.os }}- + key: kicad-apt-${{ steps.image.outputs.os }}-${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: kicad-apt-${{ steps.image.outputs.os }}- - name: Install KiCad 10 - timeout-minutes: 15 - run: | - mkdir -p ~/apt-cache/partial - APT_CACHE="-o Dir::Cache::archives=$HOME/apt-cache" - sudo add-apt-repository --yes --no-update ppa:kicad/kicad-10.0-releases - sudo apt-get update -o Acquire::Retries=5 -o Acquire::Languages=none - sudo apt-get install -y --no-install-recommends -o Acquire::Retries=5 $APT_CACHE \ - kicad kicad-footprints - sudo apt-get autoclean $APT_CACHE - sudo chown -R "$USER" ~/apt-cache + id: install + timeout-minutes: 20 + run: ci/install_kicad.sh ~/apt-cache + + # apt leaves root-owned files the cache action can't read. + - name: Make the package cache readable + if: always() && steps.cache.outcome == 'success' && steps.install.outputs.changed != 'false' + run: sudo chown -R "$USER" ~/apt-cache + + - name: Save KiCad package cache + if: always() && steps.cache.outcome == 'success' && steps.install.outputs.changed != 'false' + uses: actions/cache/save@v6 + with: + path: ~/apt-cache + key: ${{ steps.cache.outputs.cache-primary-key }} - name: Check PCB sync run: | diff --git a/ci/install_kicad.sh b/ci/install_kicad.sh new file mode 100755 index 0000000..6143d16 --- /dev/null +++ b/ci/install_kicad.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Install what the PCB sync check needs from KiCad 10 (pcbnew and its Python module, and the +# stock footprints) on a GitHub Ubuntu runner, keeping apt's package lists and downloaded .debs +# in a directory the workflow caches between runs (default ~/apt-cache). +# +# Launchpad (the KiCad PPA and its API) and the Ubuntu mirrors are each slow or down at times, so: +# - The PPA's signing key is committed (ci/kicad-ppa.asc) and the source written here, instead of +# `add-apt-repository`, which asks Launchpad's API for the key on every run. +# - With a cache from the last 7 days, the install runs from it with no network at all +# (`--no-download`). If packages are missing (a run that timed out partway), it downloads just +# those against the cached lists, and runs a fresh `apt-get update` only if that fails. +# An older cache is refreshed first (picking up KiCad point releases), and used as-is if the +# refresh fails. +# - The workflow saves the cache even when this step fails or times out, so every .deb that +# finished downloading carries over and a slow day's runs make progress instead of restarting. +# +# Writes changed=true|false to $GITHUB_OUTPUT: whether the cache contents changed. A failed or +# timed-out run writes nothing, which the workflow also treats as changed. +set -euo pipefail + +CACHE=${1:-$HOME/apt-cache} +PKGS=(kicad kicad-footprints) +HERE=$(cd "$(dirname "$0")" && pwd) + +sudo install -D -m 644 "$HERE/kicad-ppa.asc" /etc/apt/keyrings/kicad-ppa.asc +sudo tee /etc/apt/sources.list.d/kicad-10.0-releases.sources > /dev/null <<'EOF' +Types: deb +URIs: https://ppa.launchpadcontent.net/kicad/kicad-10.0-releases/ubuntu/ +Suites: noble +Components: main +Signed-By: /etc/apt/keyrings/kicad-ppa.asc +EOF + +mkdir -p "$CACHE/archives/partial" "$CACHE/lists/partial" +APT=(-o "Dir::Cache::archives=$CACHE/archives" -o "Dir::State::Lists=$CACHE/lists" + -o Acquire::Retries=5 -o Acquire::Languages=none) +# apt dates downloaded lists by the server's Last-Modified, so the lists' age comes from a stamp +# written after each successful `apt-get update`. +STAMP=$CACHE/updated +manifest() { (cd "$CACHE" && find . -type f ! -name lock -printf '%p %s %T@\n' | sort); } +before=$(manifest) + +offline() { + echo "Installing from the cache (no downloads)" + sudo apt-get install -y --no-install-recommends --no-download "${APT[@]}" "${PKGS[@]}" +} +missing() { + echo "Downloading only the packages the cache is missing" + sudo apt-get install -y --no-install-recommends "${APT[@]}" "${PKGS[@]}" +} +online() { + echo "Refreshing the package lists" + sudo apt-get update --error-on=any "${APT[@]}" && touch "$STAMP" && + sudo apt-get install -y --no-install-recommends "${APT[@]}" "${PKGS[@]}" +} + +if [ -n "$(find "$STAMP" -mtime -7 -print 2> /dev/null)" ]; then + offline || missing || online +elif [ -e "$STAMP" ]; then + online || offline +else + online +fi + +sudo apt-get autoclean "${APT[@]}" +if [ "$(manifest)" = "$before" ]; then changed=false; else changed=true; fi +echo "Cache changed: $changed" +echo "changed=$changed" >> "${GITHUB_OUTPUT:-/dev/null}" diff --git a/ci/kicad-ppa.asc b/ci/kicad-ppa.asc new file mode 100644 index 0000000..8ec837d --- /dev/null +++ b/ci/kicad-ppa.asc @@ -0,0 +1,42 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Comment: Hostname: +Version: Hockeypuck 2.2 + +xsFNBF8ER7cBEACXkTz5mUfH9JYNDLLPZqpXrkHSIKu8HDJX79CTKsABAyE4Fl3s +mERIIEQnwvGTuodey9IU5vH/FQowTzkXt6OeAx8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