Skip to content

Commit 9774ee6

Browse files
authored
Merge pull request #11667 from mikeysklar/ci-cache-apt-packages
Keep downloaded Ubuntu packages in the CI cache
2 parents 4beff61 + 4c8200c commit 9774ee6

3 files changed

Lines changed: 66 additions & 15 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Install apt packages, caching the downloaded files
2+
3+
inputs:
4+
packages:
5+
description: 'The apt packages to install, separated by spaces'
6+
required: true
7+
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Name the cache
12+
id: cache-name
13+
run: echo "prefix=apt-$ImageOS-$(echo "$PACKAGES" | sha256sum | cut -c1-16)-" >> $GITHUB_OUTPUT
14+
shell: bash
15+
env:
16+
PACKAGES: ${{ inputs.packages }}
17+
- name: Restore downloaded packages
18+
id: restore
19+
uses: actions/cache/restore@v5
20+
with:
21+
path: ~/apt-archives
22+
key: ${{ steps.cache-name.outputs.prefix }}
23+
restore-keys: ${{ steps.cache-name.outputs.prefix }}
24+
- name: Install packages
25+
id: install
26+
# apt only downloads the packages that are not already in ~/apt-archives, and
27+
# autoclean drops versions the mirror no longer has. The cache key names the
28+
# .deb files kept, so it changes whenever a package is updated.
29+
run: |
30+
mkdir -p ~/apt-archives/partial
31+
sudo apt-get update
32+
sudo apt-get install -y -o Dir::Cache::Archives="$HOME/apt-archives" $PACKAGES
33+
sudo apt-get autoclean -o Dir::Cache::Archives="$HOME/apt-archives"
34+
sudo rm -rf ~/apt-archives/partial ~/apt-archives/lock
35+
sudo chown -R "$(id -un)" ~/apt-archives
36+
echo "key=$PREFIX$(ls ~/apt-archives | sha256sum | cut -c1-16)" >> $GITHUB_OUTPUT
37+
shell: bash
38+
env:
39+
PACKAGES: ${{ inputs.packages }}
40+
PREFIX: ${{ steps.cache-name.outputs.prefix }}
41+
- name: Save downloaded packages
42+
if: github.event_name == 'push' && steps.restore.outputs.cache-matched-key != steps.install.outputs.key
43+
uses: actions/cache/save@v5
44+
with:
45+
path: ~/apt-archives
46+
key: ${{ steps.install.outputs.key }}

‎.github/actions/deps/ports/zephyr-cp/action.yml‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ inputs:
99
runs:
1010
using: composite
1111
steps:
12-
- name: Get Linux build dependencies
12+
- name: Show CPU model
1313
if: runner.os == 'Linux'
14-
run: |
15-
echo "--- cpu model ---"
16-
grep "model name" /proc/cpuinfo | head -1
17-
sudo apt-get update
18-
sudo apt-get install -y libusb-1.0-0-dev libudev-dev pkg-config mtools
14+
run: grep "model name" /proc/cpuinfo | head -1
1915
shell: bash
20-
- name: Get SDL2 for native_sim
16+
- name: Get Linux build dependencies
17+
if: runner.os == 'Linux'
18+
uses: ./.github/actions/deps/apt_packages
19+
with:
20+
# The last four are the packages action-zephyr-setup@v1 installs, so its apt-get has nothing to download.
21+
packages: libusb-1.0-0-dev libudev-dev pkg-config mtools ccache gperf libc6-dev-i386 g++-multilib
22+
- name: Prepare for 32-bit SDL2
2123
if: runner.os == 'Linux' && inputs.sdl == 'true'
2224
run: |
2325
sudo dpkg --add-architecture i386
24-
sudo apt-get update
2526
# We have to hold python3 so the following install works. See https://github.com/actions/runner-images/issues/13803
2627
sudo apt-mark hold python3
27-
sudo apt-get install -y libsdl2-dev:i386 libsdl2-image-dev:i386
2828
echo "PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" >> $GITHUB_ENV
2929
shell: bash
30+
- name: Get SDL2 for native_sim
31+
if: runner.os == 'Linux' && inputs.sdl == 'true'
32+
uses: ./.github/actions/deps/apt_packages
33+
with:
34+
packages: libsdl2-dev:i386 libsdl2-image-dev:i386
3035
- name: Setup Zephyr project
3136
uses: zephyrproject-rtos/action-zephyr-setup@v1
3237
with:

‎.github/workflows/build-mpy-cross.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ jobs:
4545

4646
- name: Install toolchain (aarch64)
4747
if: matrix.mpy-cross == 'static-aarch64'
48-
run: |
49-
sudo apt-get update
50-
sudo apt-get install -y gcc-aarch64-linux-gnu
48+
uses: ./.github/actions/deps/apt_packages
49+
with:
50+
packages: gcc-aarch64-linux-gnu
5151
- name: Install toolchain (mingw)
5252
if: matrix.mpy-cross == 'static-mingw'
53-
run: |
54-
sudo apt-get update
55-
sudo apt-get install -y gcc-mingw-w64-x86-64-win32
53+
uses: ./.github/actions/deps/apt_packages
54+
with:
55+
packages: gcc-mingw-w64-x86-64-win32
5656

5757
- name: Build mpy-cross.${{ matrix.mpy-cross }}
5858
run: make -C mpy-cross -j$(nproc) -f Makefile.${{ matrix.mpy-cross }}

0 commit comments

Comments
 (0)