--- /dev/null
+name: Restore APT cache
+description: Restores cached .deb packages for APT
+inputs:
+ packages:
+ description: Packages to cache
+ required: true
+ cache-key:
+ description: Cache key to use
+ required: true
+outputs:
+ cache-hit:
+ description: A boolean value to indicate an exact match was found for the primary key
+ value: ${{ steps.load-cache.outputs.cache-hit }}
+runs:
+ using: "composite"
+ steps:
+ - name: Get cache key (Ubuntu)
+ if: runner.os == 'Linux'
+ id: get-ubuntu-cache-key
+ shell: bash
+ run: |
+ echo "release=$(sed -n 's/UBUNTU_CODENAME=\(.*\)/\1/p' /etc/os-release)" >> $GITHUB_OUTPUT
+ echo "pkg_sig=$(printf '%s' "${{ inputs.packages }}" | sha256sum | cut -c1-12)" >> $GITHUB_OUTPUT
+ echo "key=$(/bin/date -u "+%G%V")" >> $GITHUB_OUTPUT
+
+ - name: Load package cache (Ubuntu)
+ if: runner.os == 'Linux'
+ id: load-cache
+ uses: actions/cache@v5
+ with:
+ path: ${{ runner.temp }}/apt-archives/*.deb
+ key: cache-apt-${{ inputs.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}-${{ steps.get-ubuntu-cache-key.outputs.key }}
+ restore-keys: |
+ cache-apt-${{ inputs.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}
+ cache-apt-${{ inputs.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}
+
+ - name: Restore cached packages (Ubuntu)
+ if: runner.os == 'Linux'
+ shell: bash
+ run: |
+ sudo mkdir -p /var/cache/apt/archives ${{ runner.temp }}/apt-archives
+ if compgen -G "${{ runner.temp }}/apt-archives/*.deb" > /dev/null; then
+ sudo mv -f ${{ runner.temp }}/apt-archives/*.deb /var/cache/apt/archives/
+ fi
--- /dev/null
+name: Update APT cache
+description: Updates list of cached .deb packages for APT
+runs:
+ using: "composite"
+ steps:
+ - name: Update package cache (Ubuntu)
+ if: runner.os == 'Linux'
+ shell: bash
+ run: |
+ if compgen -G "/var/cache/apt/archives/*.deb" > /dev/null; then
+ sudo apt autoclean
+ sudo apt autoremove
+ sudo cp -f /var/cache/apt/archives/*.deb ${{ runner.temp }}/apt-archives/
+ fi
curl http://mirrors.ubuntu.com/mirrors.txt | sudo tee --append /etc/apt/mirrors.txt
sudo sed -i 's#http://azure.archive.ubuntu.com/ubuntu/#mirror+file:/etc/apt/mirrors.txt#' /etc/apt/sources.list
- - name: Get cache key (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages && !contains(matrix.os, 'z15')
- id: get-ubuntu-cache-key
- shell: bash
- run: |
- echo "release=$(sed -n 's/UBUNTU_CODENAME=\(.*\)/\1/p' /etc/os-release)" >> $GITHUB_OUTPUT
- pkg='${{ matrix.packages }}'
- echo "pkg_sig=$(printf '%s' "$pkg" | sha256sum | cut -c1-12)" >> $GITHUB_OUTPUT
- echo "key=$(/bin/date -u "+%G%V")" >> $GITHUB_OUTPUT
-
- - name: Load package cache (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages && !contains(matrix.os, 'z15')
- uses: actions/cache@v5
- with:
- path: ${{ runner.temp }}/apt-archives/*.deb
- key: cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}-${{ steps.get-ubuntu-cache-key.outputs.key }}
- restore-keys: |
- cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}
- cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}
-
- name: Restore cached packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages && !contains(matrix.os, 'z15')
- run: |
- sudo mkdir -p /var/cache/apt/archives ${{ runner.temp }}/apt-archives
- if compgen -G "${{ runner.temp }}/apt-archives/*.deb" > /dev/null; then
- sudo mv -f ${{ runner.temp }}/apt-archives/*.deb /var/cache/apt/archives/
- fi
+ id: restore-apt-cache
+ uses: ./.github/actions/restore-apt-cache
+ with:
+ packages: ${{ matrix.packages }}
+ cache-key: ${{ matrix.cache-key }}
- name: Install packages (Ubuntu)
if: runner.os == 'Linux' && !contains(matrix.os, 'z15')
${{ matrix.packages || 'libgtest-dev libbenchmark-dev' }}
- name: Update package cache (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages && !contains(matrix.os, 'z15')
- run: |
- if compgen -G "/var/cache/apt/archives/*.deb" > /dev/null; then
- sudo apt autoclean
- sudo apt autoremove
- sudo cp -f /var/cache/apt/archives/*.deb ${{ runner.temp }}/apt-archives/
- fi
+ if: runner.os == 'Linux' && matrix.packages && !contains(matrix.os, 'z15') && steps.restore-apt-cache.outputs.cache-hit != 'true'
+ uses: ./.github/actions/update-apt-cache
- name: Install packages (Windows)
if: runner.os == 'Windows'
curl http://mirrors.ubuntu.com/mirrors.txt | sudo tee --append /etc/apt/mirrors.txt
sudo sed -i 's#http://azure.archive.ubuntu.com/ubuntu/#mirror+file:/etc/apt/mirrors.txt#' /etc/apt/sources.list
- - name: Get cache key (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages
- id: get-ubuntu-cache-key
- shell: bash
- run: |
- echo "release=$(sed -n 's/UBUNTU_CODENAME=\(.*\)/\1/p' /etc/os-release)" >> $GITHUB_OUTPUT
- pkg='${{ matrix.packages }}'
- echo "pkg_sig=$(printf '%s' "$pkg" | sha256sum | cut -c1-12)" >> $GITHUB_OUTPUT
- echo "key=$(/bin/date -u "+%G%V")" >> $GITHUB_OUTPUT
-
- - name: Load package cache (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages
- uses: actions/cache@v5
- with:
- path: ${{ runner.temp }}/apt-archives/*.deb
- key: cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}-${{ steps.get-ubuntu-cache-key.outputs.key }}
- restore-keys: |
- cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}-${{ steps.get-ubuntu-cache-key.outputs.pkg_sig }}
- cache-apt-${{ matrix.cache-key || 'default' }}-${{ runner.arch }}-${{ steps.get-ubuntu-cache-key.outputs.release }}
-
- name: Restore cached packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages
- run: |
- sudo mkdir -p /var/cache/apt/archives ${{ runner.temp }}/apt-archives
- if compgen -G "${{ runner.temp }}/apt-archives/*.deb" > /dev/null; then
- sudo mv -f ${{ runner.temp }}/apt-archives/*.deb /var/cache/apt/archives/
- fi
+ id: restore-apt-cache
+ uses: ./.github/actions/restore-apt-cache
+ with:
+ packages: ${{ matrix.packages }}
+ cache-key: ${{ matrix.cache-key }}
- name: Install packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages
sudo apt-get install -y ${{ matrix.packages }}
- name: Update package cache (Ubuntu)
- if: runner.os == 'Linux' && matrix.packages
- run: |
- if compgen -G "/var/cache/apt/archives/*.deb" > /dev/null; then
- sudo apt autoclean
- sudo apt autoremove
- sudo cp -f /var/cache/apt/archives/*.deb ${{ runner.temp }}/apt-archives/
- fi
+ if: runner.os == 'Linux' && matrix.packages && steps.restore-apt-cache.outputs.cache-hit != 'true'
+ uses: ./.github/actions/update-apt-cache
- name: Install packages (macOS)
if: runner.os == 'macOS'