diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3066a7dc1..feac96cdb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,8 @@ jobs: REPLAY: ${{ needs.changes.outputs.replay }} # The Python tests and the replay take the module and binary from check-merge's gate build. PYTHON_MODULE_BUILD: gate-build + # Noble's only valgrind version; the instruction-count guard runs under it. + VALGRIND_VERSION: "1:3.22.0-0ubuntu3" steps: - uses: actions/checkout@v4 with: @@ -116,22 +118,71 @@ jobs: run: uv python install 3.12 - name: Install development tools without the recorder run: uv sync --locked --no-group recorder - # The instruction-count guard in check-ci runs its workloads under callgrind. - # The runner's Azure Ubuntu mirror sometimes stops resolving, so apt uses archive.ubuntu.com - # directly. apt still checks the archive's signatures. + # The instruction-count guard in check-ci runs its workloads under callgrind, so valgrind is + # required. Its packages come from the cache below, else the runner's own mirror, else + # archive.ubuntu.com. The key holds the runner image, whose libc6 the libc6-dbg dependency + # must match, and noble's only valgrind version. A warm cache installs without the network. + - name: Name the valgrind package cache + id: valgrind-key + run: echo "key=valgrind-debs-${ImageOS}-${ImageVersion}-${VALGRIND_VERSION}" >> "${GITHUB_OUTPUT}" + - name: Restore the valgrind packages + id: valgrind-cache + uses: actions/cache/restore@v4 + with: + path: ~/.cache/valgrind-debs + key: ${{ steps.valgrind-key.outputs.key }} - name: Install valgrind + env: + CACHE_HIT: ${{ steps.valgrind-cache.outputs.cache-hit }} run: | + debs="${HOME}/.cache/valgrind-debs" + apt_options=(-q -o Acquire::Retries=2 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20) + install_debs() { + compgen -G "${debs}/*.deb" > /dev/null && sudo dpkg -i "${debs}"/*.deb && valgrind --version + } + # Downloads valgrind and the packages it needs that the image lacks, then installs them. + download_and_install() { + sudo rm -rf "${debs}" && mkdir -p "${debs}/partial" + for attempt in 1 2; do + if sudo apt-get update "${apt_options[@]}" && + sudo apt-get install -y --download-only --no-install-recommends "${apt_options[@]}" \ + -o Dir::Cache::archives="${debs}" "valgrind=${VALGRIND_VERSION}" && + install_debs; then + sudo rm -rf "${debs}/partial" "${debs}/lock" + sudo chown -R "$(id -u):$(id -g)" "${debs}" + return 0 + fi + sleep $((attempt * 15)) + done + return 1 + } + if valgrind --version 2> /dev/null; then + echo "valgrind source: the runner image" + exit 0 + fi + if [[ "${CACHE_HIT}" == "true" ]] && install_debs; then + echo "valgrind source: package cache" + exit 0 + fi + if download_and_install; then + echo "valgrind source: the runner's default mirror" + exit 0 + fi { sudo grep -rlE 'mirror\+file:|azure\.archive\.ubuntu\.com' /etc/apt || true; } | xargs -r sudo sed -i -E \ -e 's#mirror\+file:/etc/apt/apt-mirrors\.txt#http://archive.ubuntu.com/ubuntu/#g' \ -e 's#https?://azure\.archive\.ubuntu\.com/ubuntu/?#http://archive.ubuntu.com/ubuntu/#g' - for attempt in 1 2 3; do - if sudo apt-get update -q -o Acquire::Retries=3 && - sudo apt-get install -y -q --no-install-recommends -o Acquire::Retries=3 valgrind; then - exit 0 - fi - sleep $((attempt * 15)) - done + if download_and_install; then + echo "valgrind source: archive.ubuntu.com" + exit 0 + fi + echo "::error title=Infrastructure::infrastructure: could not install valgrind from the package cache, the runner's default mirror or archive.ubuntu.com; the instruction-count guard needs it" exit 1 + - name: Save the valgrind packages + if: steps.valgrind-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ~/.cache/valgrind-debs + key: ${{ steps.valgrind-key.outputs.key }} # One gate build serves every step: check-ci, the Rust tests, the Python tests and the replay. - name: Run static checks and tests run: make check-merge test-python