-
Notifications
You must be signed in to change notification settings - Fork 948
Composite GHA action with caching #10026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| name: 'Install apt dependencies' | ||
| description: 'Install apt packages with retry logic and caching' | ||
| inputs: | ||
| packages: | ||
| description: 'Space-separated list of apt packages to install' | ||
| required: true | ||
| retries: | ||
| description: 'Number of retry attempts' | ||
| required: false | ||
| default: '3' | ||
| retry-delay: | ||
| description: 'Initial delay between retries (seconds, doubles each attempt)' | ||
| required: false | ||
| default: '5' | ||
| no-install-recommends: | ||
| description: 'Pass --no-install-recommends to apt-get install' | ||
| required: false | ||
| default: 'false' | ||
| cache: | ||
| description: 'Cache apt archives (disable for dynamic package names)' | ||
| required: false | ||
| default: 'true' | ||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Compute cache key | ||
| if: inputs.cache == 'true' | ||
| id: cache-key | ||
| shell: bash | ||
| run: | | ||
| SORTED_PKGS=$(echo "${{ inputs.packages }}" | tr ' ' '\n' | sort | tr '\n' ' ') | ||
| PKG_HASH=$(echo "$SORTED_PKGS" | sha256sum | cut -d' ' -f1 | head -c 16) | ||
| OS_VERSION=$(lsb_release -rs 2>/dev/null || echo "unknown") | ||
| echo "key=apt-deps-${{ runner.os }}-${{ runner.arch }}-${OS_VERSION}-${PKG_HASH}" >> $GITHUB_OUTPUT | ||
| echo "restore-key=apt-deps-${{ runner.os }}-${{ runner.arch }}-${OS_VERSION}-" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Restore apt cache | ||
| if: inputs.cache == 'true' | ||
| id: apt-cache | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: ~/apt-cache | ||
| key: ${{ steps.cache-key.outputs.key }} | ||
| restore-keys: ${{ steps.cache-key.outputs.restore-key }} | ||
|
|
||
| - name: Pre-seed apt archives from cache | ||
| if: inputs.cache == 'true' && steps.apt-cache.outputs.cache-hit == 'true' | ||
| shell: bash | ||
| run: | | ||
| if [ -d ~/apt-cache ] && ls ~/apt-cache/*.deb >/dev/null 2>&1; then | ||
| sudo cp ~/apt-cache/*.deb /var/cache/apt/archives/ | ||
| echo "Restored $(ls ~/apt-cache/*.deb | wc -l) cached .deb files" | ||
| fi | ||
|
|
||
| - name: Install packages | ||
| shell: bash | ||
| run: | | ||
| export DEBIAN_FRONTEND=noninteractive | ||
| RETRIES=${{ inputs.retries }} | ||
| DELAY=${{ inputs.retry-delay }} | ||
| NO_REC="" | ||
| if [ "${{ inputs.no-install-recommends }}" = "true" ]; then | ||
| NO_REC="--no-install-recommends" | ||
| fi | ||
| for i in $(seq 1 $RETRIES); do | ||
| if sudo apt-get update -q && \ | ||
| sudo apt-get install -y $NO_REC ${{ inputs.packages }}; then | ||
|
||
| exit 0 | ||
| fi | ||
| if [ "$i" -eq "$RETRIES" ]; then | ||
| echo "::error::apt-get failed after $RETRIES attempts" | ||
| exit 1 | ||
| fi | ||
| echo "::warning::apt-get failed (attempt $i/$RETRIES), retrying in ${DELAY}s..." | ||
| sleep $DELAY | ||
| DELAY=$((DELAY * 2)) | ||
| done | ||
|
|
||
| - name: Collect .deb files for cache | ||
| if: inputs.cache == 'true' && steps.apt-cache.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| run: | | ||
| mkdir -p ~/apt-cache | ||
| cp /var/cache/apt/archives/*.deb ~/apt-cache/ 2>/dev/null || true | ||
| echo "Cached $(ls ~/apt-cache/*.deb 2>/dev/null | wc -l) .deb files" | ||
|
|
||
| - name: Save apt cache | ||
| if: inputs.cache == 'true' && steps.apt-cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: ~/apt-cache | ||
| key: ${{ steps.cache-key.outputs.key }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,15 +211,12 @@ jobs: | |
| run: tar -xf build-dir.tgz | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| # Don't prompt for anything | ||
| export DEBIAN_FRONTEND=noninteractive | ||
| sudo apt-get update | ||
| # hostap dependencies | ||
| sudo apt-get install -y libpcap0.8 libpcap-dev curl libcurl4-openssl-dev \ | ||
| libnl-3-dev binutils-dev libssl-dev libiberty-dev libnl-genl-3-dev \ | ||
| libnl-route-3-dev libdbus-1-dev bridge-utils tshark python3-pycryptodome | ||
| sudo pip install pycryptodome | ||
| uses: ./wolfssl/.github/actions/install-apt-deps | ||
| with: | ||
| packages: libpcap0.8 libpcap-dev curl libcurl4-openssl-dev libnl-3-dev binutils-dev libssl-dev libiberty-dev libnl-genl-3-dev libnl-route-3-dev libdbus-1-dev bridge-utils tshark python3-pycryptodome | ||
|
Comment on lines
+214
to
+216
|
||
|
|
||
| - name: Install pip dependencies | ||
| run: sudo pip install pycryptodome | ||
|
|
||
| - name: Checking if we have hostap in cache | ||
| uses: actions/cache/restore@v4 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,11 @@ jobs: | |
| - name: Prepare target kernel for module builds | ||
| run: | | ||
| echo "updating linux-headers" | ||
| sudo apt-get update || $(exit 2) | ||
| sudo apt-get install linux-headers-$(uname -r) -y || $(exit 3) | ||
| for i in 1 2 3; do | ||
| sudo apt-get update && sudo apt-get install -y linux-headers-$(uname -r) && break | ||
| echo "::warning::apt-get failed (attempt $i/3), retrying..." | ||
| sleep $((5 * i)) | ||
| done || $(exit 2) | ||
|
Comment on lines
+34
to
+38
|
||
| echo "preparing target kernel $(uname -r)" | ||
| pushd "/lib/modules/$(uname -r)/build" || $(exit 4) | ||
| if [ -f /proc/config.gz ]; then gzip -dc /proc/config.gz > /tmp/.config && sudo mv /tmp/.config . || $(exit 5); elif [ -f "/boot/config-$(uname -r)" ]; then sudo cp -p "/boot/config-$(uname -r)" .config || $(exit 6); fi | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The action expands
${{ inputs.packages }}unquoted into a shell command, which is fragile and can become a shell-injection vector if the input is ever derived from untrusted data (or even just contains unexpected whitespace/newlines). It also reduces cache hit-rate when callers include duplicate packages because the cache key is based on raw sorted tokens. Consider parsing packages into a bash array safely (e.g., read into an array and pass as\"${pkgs[@]}\"), and normalize the cache-key input withsort -uto dedupe packages so semantically-identical lists share a cache.