Skip to content

Commit b1a6e40

Browse files
authored
Cache apt install [ci] (home-assistant#152113)
1 parent 937d3e4 commit b1a6e40

File tree

1 file changed

+118
-8
lines changed

1 file changed

+118
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 118 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ on:
3737
type: boolean
3838

3939
env:
40-
CACHE_VERSION: 7
40+
CACHE_VERSION: 8
4141
UV_CACHE_VERSION: 1
4242
MYPY_CACHE_VERSION: 1
4343
HA_SHORT_VERSION: "2025.10"
@@ -61,6 +61,9 @@ env:
6161
POSTGRESQL_VERSIONS: "['postgres:12.14','postgres:15.2']"
6262
PRE_COMMIT_CACHE: ~/.cache/pre-commit
6363
UV_CACHE_DIR: /tmp/uv-cache
64+
APT_CACHE_BASE: /home/runner/work/apt
65+
APT_CACHE_DIR: /home/runner/work/apt/cache
66+
APT_LIST_CACHE_DIR: /home/runner/work/apt/lists
6467
SQLALCHEMY_WARN_20: 1
6568
PYTHONASYNCIODEBUG: 1
6669
HASS_CI: 1
@@ -78,6 +81,7 @@ jobs:
7881
core: ${{ steps.core.outputs.changes }}
7982
integrations_glob: ${{ steps.info.outputs.integrations_glob }}
8083
integrations: ${{ steps.integrations.outputs.changes }}
84+
apt_cache_key: ${{ steps.generate_apt_cache_key.outputs.key }}
8185
pre-commit_cache_key: ${{ steps.generate_pre-commit_cache_key.outputs.key }}
8286
python_cache_key: ${{ steps.generate_python_cache_key.outputs.key }}
8387
requirements: ${{ steps.core.outputs.requirements }}
@@ -111,6 +115,10 @@ jobs:
111115
run: >-
112116
echo "key=pre-commit-${{ env.CACHE_VERSION }}-${{
113117
hashFiles('.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
118+
- name: Generate partial apt restore key
119+
id: generate_apt_cache_key
120+
run: |
121+
echo "key=$(lsb_release -rs)-apt-${{ env.CACHE_VERSION }}-${{ env.HA_SHORT_VERSION }}" >> $GITHUB_OUTPUT
114122
- name: Filter for core changes
115123
uses: dorny/[email protected]
116124
id: core
@@ -515,16 +523,36 @@ jobs:
515523
${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-uv-${{
516524
env.UV_CACHE_VERSION }}-${{ steps.generate-uv-key.outputs.version }}-${{
517525
env.HA_SHORT_VERSION }}-
526+
- name: Restore apt cache
527+
if: steps.cache-venv.outputs.cache-hit != 'true'
528+
id: cache-apt
529+
uses: actions/[email protected]
530+
with:
531+
path: |
532+
${{ env.APT_CACHE_DIR }}
533+
${{ env.APT_LIST_CACHE_DIR }}
534+
key: >-
535+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
518536
- name: Install additional OS dependencies
519537
if: steps.cache-venv.outputs.cache-hit != 'true'
520538
timeout-minutes: 10
521539
run: |
522540
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
523-
sudo apt-get update
541+
if [[ "${{ steps.cache-apt.outputs.cache-hit }}" != 'true' ]]; then
542+
mkdir -p ${{ env.APT_CACHE_DIR }}
543+
mkdir -p ${{ env.APT_LIST_CACHE_DIR }}
544+
fi
545+
546+
sudo apt-get update \
547+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
548+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
524549
sudo apt-get -y install \
550+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
551+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
525552
bluez \
526553
ffmpeg \
527554
libturbojpeg \
555+
libxml2-utils \
528556
libavcodec-dev \
529557
libavdevice-dev \
530558
libavfilter-dev \
@@ -534,6 +562,10 @@ jobs:
534562
libswresample-dev \
535563
libswscale-dev \
536564
libudev-dev
565+
566+
if [[ "${{ steps.cache-apt.outputs.cache-hit }}" != 'true' ]]; then
567+
sudo chmod -R 755 ${{ env.APT_CACHE_BASE }}
568+
fi
537569
- name: Create Python virtual environment
538570
if: steps.cache-venv.outputs.cache-hit != 'true'
539571
run: |
@@ -578,12 +610,25 @@ jobs:
578610
- info
579611
- base
580612
steps:
613+
- name: Restore apt cache
614+
uses: actions/cache/[email protected]
615+
with:
616+
path: |
617+
${{ env.APT_CACHE_DIR }}
618+
${{ env.APT_LIST_CACHE_DIR }}
619+
fail-on-cache-miss: true
620+
key: >-
621+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
581622
- name: Install additional OS dependencies
582623
timeout-minutes: 10
583624
run: |
584625
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
585-
sudo apt-get update
626+
sudo apt-get update \
627+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
628+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
586629
sudo apt-get -y install \
630+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
631+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
587632
libturbojpeg
588633
- name: Check out code from GitHub
589634
uses: actions/[email protected]
@@ -878,12 +923,25 @@ jobs:
878923
- mypy
879924
name: Split tests for full run
880925
steps:
926+
- name: Restore apt cache
927+
uses: actions/cache/[email protected]
928+
with:
929+
path: |
930+
${{ env.APT_CACHE_DIR }}
931+
${{ env.APT_LIST_CACHE_DIR }}
932+
fail-on-cache-miss: true
933+
key: >-
934+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
881935
- name: Install additional OS dependencies
882936
timeout-minutes: 10
883937
run: |
884938
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
885-
sudo apt-get update
939+
sudo apt-get update \
940+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
941+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
886942
sudo apt-get -y install \
943+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
944+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
887945
bluez \
888946
ffmpeg \
889947
libturbojpeg \
@@ -939,12 +997,25 @@ jobs:
939997
name: >-
940998
Run tests Python ${{ matrix.python-version }} (${{ matrix.group }})
941999
steps:
1000+
- name: Restore apt cache
1001+
uses: actions/cache/[email protected]
1002+
with:
1003+
path: |
1004+
${{ env.APT_CACHE_DIR }}
1005+
${{ env.APT_LIST_CACHE_DIR }}
1006+
fail-on-cache-miss: true
1007+
key: >-
1008+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
9421009
- name: Install additional OS dependencies
9431010
timeout-minutes: 10
9441011
run: |
9451012
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
946-
sudo apt-get update
1013+
sudo apt-get update \
1014+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1015+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
9471016
sudo apt-get -y install \
1017+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1018+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
9481019
bluez \
9491020
ffmpeg \
9501021
libturbojpeg \
@@ -1073,12 +1144,25 @@ jobs:
10731144
name: >-
10741145
Run ${{ matrix.mariadb-group }} tests Python ${{ matrix.python-version }}
10751146
steps:
1147+
- name: Restore apt cache
1148+
uses: actions/cache/[email protected]
1149+
with:
1150+
path: |
1151+
${{ env.APT_CACHE_DIR }}
1152+
${{ env.APT_LIST_CACHE_DIR }}
1153+
fail-on-cache-miss: true
1154+
key: >-
1155+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
10761156
- name: Install additional OS dependencies
10771157
timeout-minutes: 10
10781158
run: |
10791159
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
1080-
sudo apt-get update
1160+
sudo apt-get update \
1161+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1162+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
10811163
sudo apt-get -y install \
1164+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1165+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
10821166
bluez \
10831167
ffmpeg \
10841168
libturbojpeg \
@@ -1214,12 +1298,25 @@ jobs:
12141298
name: >-
12151299
Run ${{ matrix.postgresql-group }} tests Python ${{ matrix.python-version }}
12161300
steps:
1301+
- name: Restore apt cache
1302+
uses: actions/cache/[email protected]
1303+
with:
1304+
path: |
1305+
${{ env.APT_CACHE_DIR }}
1306+
${{ env.APT_LIST_CACHE_DIR }}
1307+
fail-on-cache-miss: true
1308+
key: >-
1309+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
12171310
- name: Install additional OS dependencies
12181311
timeout-minutes: 10
12191312
run: |
12201313
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
1221-
sudo apt-get update
1314+
sudo apt-get update \
1315+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1316+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
12221317
sudo apt-get -y install \
1318+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1319+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
12231320
bluez \
12241321
ffmpeg \
12251322
libturbojpeg \
@@ -1376,12 +1473,25 @@ jobs:
13761473
name: >-
13771474
Run tests Python ${{ matrix.python-version }} (${{ matrix.group }})
13781475
steps:
1476+
- name: Restore apt cache
1477+
uses: actions/cache/[email protected]
1478+
with:
1479+
path: |
1480+
${{ env.APT_CACHE_DIR }}
1481+
${{ env.APT_LIST_CACHE_DIR }}
1482+
fail-on-cache-miss: true
1483+
key: >-
1484+
${{ runner.os }}-${{ runner.arch }}-${{ needs.info.outputs.apt_cache_key }}
13791485
- name: Install additional OS dependencies
13801486
timeout-minutes: 10
13811487
run: |
13821488
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
1383-
sudo apt-get update
1489+
sudo apt-get update \
1490+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1491+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }}
13841492
sudo apt-get -y install \
1493+
-o Dir::Cache=${{ env.APT_CACHE_DIR }} \
1494+
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
13851495
bluez \
13861496
ffmpeg \
13871497
libturbojpeg \

0 commit comments

Comments
 (0)