Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,52 @@ jobs:
# at about 0.5 MB/s, and the 3D-model download timed out every few runs. A missing 3D model
# 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.
#
# 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"

- name: Restore KiCad package cache
id: cache
uses: actions/cache/restore@v6
with:
path: ~/apt-cache
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
id: install
timeout-minutes: 20
run: ci/install_kicad.sh ~/apt-cache

# A timed-out install leaves apt's download processes running, still writing to the cache
# (tar then fails with "file changed as we read it" and nothing is saved): stop them first.
# Half-downloaded files in partial/ stay; apt resumes them. apt also leaves root-owned files
# the cache action can't read.
- name: Prepare the package cache for saving
if: always() && steps.cache.outcome == 'success' && steps.install.outputs.changed != 'false'
run: |
sudo add-apt-repository --yes ppa:kicad/kicad-10.0-releases
sudo apt-get update
sudo apt-get install -y --no-install-recommends -o Acquire::Retries=5 \
kicad kicad-footprints
running() { pgrep -x apt-get || pgrep -f '^/usr/lib/apt/methods/'; } > /dev/null
sudo pkill -x apt-get || true
sudo pkill -f '^/usr/lib/apt/methods/' || true
for _ in $(seq 10); do running || break; sleep 1; done
sudo pkill -9 -x apt-get || true
sudo pkill -9 -f '^/usr/lib/apt/methods/' || true
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: |
Expand Down
68 changes: 68 additions & 0 deletions ci/install_kicad.sh
Original file line number Diff line number Diff line change
@@ -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}"
42 changes: 42 additions & 0 deletions ci/kicad-ppa.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: Hostname:
Version: Hockeypuck 2.2

xsFNBF8ER7cBEACXkTz5mUfH9JYNDLLPZqpXrkHSIKu8HDJX79CTKsABAyE4Fl3s
mERIIEQnwvGTuodey9IU5vH/FQowTzkXt6OeAx8R3pVueqsavrn3ddKMPovP9os/
hWFEzwVDojRxZBhXHfiGIK30VhbDxuhvnIkIqOaYCtI/qv4pAOYYJfkg5PopyZlA
P0u3TKXUI6mVUioWxraZYUuNyx1MPpY7plaqt8ft8RbHja2Rp6xtg89Vtyk/jFfy
HvHi0aRd54Zzf+37jg7+diWt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