Skip to content

Add composite action to cache CI apt installs#171735

Open
bdraco wants to merge 6 commits into
devfrom
ci-cache-postgres-mariadb-deps
Open

Add composite action to cache CI apt installs#171735
bdraco wants to merge 6 commits into
devfrom
ci-cache-postgres-mariadb-deps

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 21, 2026

Proposed change

apt installs on CI are flakey, especially on the database runners that hit an external mirror with no retry. Add a cache-apt-packages composite action under .github/actions/ so every workflow installs apt packages through one entry point. The composite removes the conflicting Microsoft apt source, restores from cache when possible, and refreshes the dynamic linker so update-alternatives symlinks (eg libblas, liblapack via ffmpeg) keep resolving after a cache restore. The library path is derived from dpkg-architecture so it stays correct on non-x86_64 runners. Workflows do not pin a third-party action directly, so the implementation can be swapped later without touching each workflow. Under the hood it delegates to awalsh128/cache-apt-pkgs-action, which esphome already uses in production. setup-uv bootstraps uv on cache miss so the venv no longer needs base pip.

Setup is faster as a bonus, PR vs recent dev:

Job dev PR Δ
hassfest 32s 5s -27s
pytest-full grp 1 25s 12s -13s
pytest-mariadb 10.3.32 27s 9s -18s
pytest-postgres 15.2 31s 28s -3s

Postgres only saves 3s because the pgdg setup script still has to run. Total across a full CI matrix is roughly 5 to 6 minutes of compute per PR.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings May 21, 2026 14:43
@home-assistant home-assistant Bot added cla-signed code-quality small-pr PRs with less than 30 lines. labels May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Home Assistant Core CI workflow to use awalsh128/cache-apt-pkgs-action for apt package caching/installation to reduce flaky apt installs, and adjusts the base job to provision uv via setup-uv on venv cache misses.

Changes:

  • Replace the previous custom apt cache directory + actions/cache restore/save approach with awalsh128/cache-apt-pkgs-action across jobs.
  • Add APT_CACHE_VERSION to control apt cache invalidation centrally.
  • On base venv cache misses, read the pinned uv version from requirements.txt and install uv via astral-sh/setup-uv, removing the explicit pip install uv... bootstrap step.

bdraco added 2 commits May 21, 2026 10:02
The action restores cached .deb files to disk but skips dpkg-trigger so
/etc/ld.so.cache stays stale and ctypes-based loaders (eg opuslib)
cannot find libopus.so.0. Add an explicit ldconfig step after each
action call.
Wrap awalsh128/cache-apt-pkgs-action in .github/actions/cache-apt-packages
so every job uses the same pattern, and route /usr/lib/x86_64-linux-gnu
subdirectories through ldconfig. The upstream action does not run postinst
on cache restore so update-alternatives symlinks (libblas, liblapack via
ffmpeg) never appear; adding the subdirs to ld.so.conf.d lets the linker
find the real libraries without those symlinks.
Copilot AI review requested due to automatic review settings May 21, 2026 15:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 21, 2026 18:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread .github/actions/cache-apt-packages/action.yml Outdated
So the ldconfig workaround also works on non-x86_64 runners.
@bdraco bdraco changed the title Switch CI apt caching to awalsh128/cache-apt-pkgs-action Add composite action to cache CI apt installs May 21, 2026
@bdraco bdraco marked this pull request as ready for review May 21, 2026 20:10
@bdraco bdraco requested a review from a team as a code owner May 21, 2026 20:10
Copilot AI review requested due to automatic review settings May 21, 2026 20:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed code-quality small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants