11name : ' Install apt dependencies'
2- description : ' Install apt packages with retry logic and caching '
2+ description : ' Install apt packages with retry logic and an optional offline ghcr bundle '
33inputs :
44 packages :
55 description : ' Space-separated list of apt packages to install'
@@ -16,16 +16,12 @@ inputs:
1616 description : ' Pass --no-install-recommends to apt-get install'
1717 required : false
1818 default : ' false'
19- cache :
20- description : ' Cache apt archives (disable for dynamic package names)'
21- required : false
22- default : ' true'
2319 ghcr-debs-tag :
2420 description : >
2521 Tag of a prebuilt .deb bundle published to
2622 ghcr.io/<owner>/wolfssl-ci-debs by the ci-deps-image workflow
2723 (e.g. "ubuntu-24.04-minimal"). When set, the packages are installed
28- offline from that bundle and the apt cache path below is skipped; on
24+ offline from that bundle and the apt path below is skipped; on
2925 that happy path the apt mirror is not contacted. The offline install
3026 is all-or-nothing (a single --no-download install of the whole set),
3127 so any failure - bundle missing, not public, or not covering every
3935 # Preferred path: install from a prebuilt .deb bundle pulled from ghcr,
4036 # entirely offline (--no-download), so a flaky/timing-out apt mirror
4137 # cannot break the build. Best-effort: on any failure we leave
42- # "satisfied" unset and the apt steps below run unchanged. The bundle
38+ # "satisfied" unset and the apt step below runs unchanged. The bundle
4339 # image must be PUBLIC so anonymous `docker pull` works (including from
4440 # fork PRs whose GITHUB_TOKEN cannot read private packages).
4541 - name : Install from ghcr .deb bundle (offline)
7773 echo "::notice::offline install incomplete for $IMG; using apt"
7874 fi
7975
80- - name : Compute cache key
81- if : inputs.cache == 'true' && steps.ghcr.outputs.satisfied != 'true'
82- id : cache-key
83- shell : bash
84- run : |
85- SORTED_PKGS=$(echo "${{ inputs.packages }}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
86- PKG_HASH=$(echo "$SORTED_PKGS" | sha256sum | cut -d' ' -f1 | head -c 16)
87- OS_VERSION=$(lsb_release -rs 2>/dev/null || echo "unknown")
88- echo "key=apt-deps-${{ runner.os }}-${{ runner.arch }}-${OS_VERSION}-${PKG_HASH}" >> $GITHUB_OUTPUT
89- echo "restore-key=apt-deps-${{ runner.os }}-${{ runner.arch }}-${OS_VERSION}-" >> $GITHUB_OUTPUT
90-
91- - name : Restore apt cache
92- if : inputs.cache == 'true' && steps.ghcr.outputs.satisfied != 'true'
93- id : apt-cache
94- uses : actions/cache/restore@v5
95- with :
96- path : ~/apt-cache
97- key : ${{ steps.cache-key.outputs.key }}
98- restore-keys : ${{ steps.cache-key.outputs.restore-key }}
99-
100- - name : Pre-seed apt archives from cache
101- if : inputs.cache == 'true' && steps.apt-cache.outputs.cache-hit == 'true' && steps.ghcr.outputs.satisfied != 'true'
102- shell : bash
103- run : |
104- if [ -d ~/apt-cache ] && ls ~/apt-cache/*.deb >/dev/null 2>&1; then
105- sudo cp ~/apt-cache/*.deb /var/cache/apt/archives/
106- echo "Restored $(ls ~/apt-cache/*.deb | wc -l) cached .deb files"
107- fi
108-
10976 - name : Install packages
11077 if : steps.ghcr.outputs.satisfied != 'true'
11178 shell : bash
112- env :
113- APT_CACHE_HIT : ${{ steps.apt-cache.outputs.cache-hit }}
11479 run : |
11580 export DEBIAN_FRONTEND=noninteractive
11681 RETRIES=${{ inputs.retries }}
@@ -120,17 +85,6 @@ runs:
12085 NO_REC="--no-install-recommends"
12186 fi
12287
123- # Fast path: on cache hit the .debs are already pre-seeded into
124- # /var/cache/apt/archives. Try installing directly first; if that
125- # fails (e.g. the cached .debs were superseded in the index) fall
126- # through to the regular update + install path.
127- if [ "$APT_CACHE_HIT" = "true" ]; then
128- if sudo apt-get install -y $NO_REC ${{ inputs.packages }}; then
129- exit 0
130- fi
131- echo "::warning::install from cached .debs failed, falling back to apt-get update"
132- fi
133-
13488 for i in $(seq 1 $RETRIES); do
13589 if sudo apt-get update -q && \
13690 sudo apt-get install -y $NO_REC ${{ inputs.packages }}; then
@@ -144,21 +98,3 @@ runs:
14498 sleep $DELAY
14599 DELAY=$((DELAY * 2))
146100 done
147-
148- # PR runs never write the apt cache (no churn); only push/schedule runs
149- # refresh it. The make-check family does not need it anyway - it installs
150- # from the ghcr bundle above.
151- - name : Collect .deb files for cache
152- if : inputs.cache == 'true' && github.event_name != 'pull_request' && steps.apt-cache.outputs.cache-hit != 'true' && steps.ghcr.outputs.satisfied != 'true'
153- shell : bash
154- run : |
155- mkdir -p ~/apt-cache
156- cp /var/cache/apt/archives/*.deb ~/apt-cache/ 2>/dev/null || true
157- echo "Cached $(ls ~/apt-cache/*.deb 2>/dev/null | wc -l) .deb files"
158-
159- - name : Save apt cache
160- if : inputs.cache == 'true' && github.event_name != 'pull_request' && steps.apt-cache.outputs.cache-hit != 'true' && steps.ghcr.outputs.satisfied != 'true'
161- uses : actions/cache/save@v5
162- with :
163- path : ~/apt-cache
164- key : ${{ steps.cache-key.outputs.key }}
0 commit comments