Skip to content
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

readme/docs: cache cleanup for ~/.cache/zig and windows global cache path is missing #21

Open
matu3ba opened this issue Dec 8, 2024 · 0 comments

Comments

@matu3ba
Copy link

matu3ba commented Dec 8, 2024

Maybe it is not and there is just no way to configure it, but at least the cache cleanup size is not documented.
Feel free to close, if this is out of scope and the user is supposed to handle it or if github has its own logic
that should be relied on.

Side node: uses: actions/checkout@v4 is available, currently uses: actions/checkout@v3 is used.

I have written shell scripts for each architecture to workaround that:

name: ci
on:
  pull_request:
  push:
    branches:
      - master
concurrency:
  # Cancels pending runs when a PR gets updated.
  group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
  cancel-in-progress: true
permissions:
  # Sets permission policy for `GITHUB_TOKEN`
  contents: read

# not needed here https://github.com/actions/cache
jobs:
  aarch64-macos:
    timeout-minutes: 20
    runs-on: "macos-latest"
    env:
      ARCH: "aarch64"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Zig
        uses: mlugg/setup-zig@v1
        with:
          version: master
          mirror: 'https://pkg.machengine.org/zig'
      - name: Build and Test
        run: ci/aarch64-macos.sh
  # other confix similar for x86_64 linux and windows..

windows

# x86_64-windows CI script to clean cache, if necessary
function CheckLastExitCode {
    if (!$?) { exit 1 }
    return 0
}

$MAX_SIZE_B = 2147483648 #2 GB = 2*(1024)**3 B
[string] $ZIG_CACHE_DIR = $(zig env | jq '. "global_cache_dir"')
if (Test-Path $ZIG_CACHE_DIR) {
  $CHECK_SIZE_B = (gci $ZIG_CACHE_DIR | measure Length -s).Sum
  if ($CHECK_SIZE_B -gt $MAX_SIZE_B) {
    Write-Host "Removing global zig cache dir.."
    Remove-Item -Recurse -Force -ErrorAction Ignore -Path $ZIG_CACHE_DIR
    CheckLastExitCode
  }
}

zig env
CheckLastExitCode

zig build -Dno_opt_deps -Dno_cross test --summary all
CheckLastExitCode

macos

#!/usr/bin/env sh
# aarch64-macos CI script to clean cache, if necessary

# set -x
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable

MAX_SIZE_B=2097152 #2 GB = 2*(1024)**2 KB
ZIG_CACHE_DIR="$(zig env | jq '. "global_cache_dir"')"
if test -e "$ZIG_CACHE_DIR"; then
  CHECK_SIZE_B=$(du -ks "$ZIG_CACHE_DIR" | cut -f1)
  if test "$CHECK_SIZE_B" -ge $MAX_SIZE_B; then
    echo "$CHECK_SIZE_B > $MAX_SIZE_B, removing global zig cache dir.."
    rm -fr "$ZIG_CACHE_DIR"
  fi
fi

zig env

zig build -Dno_opt_deps -Dno_cross test --summary all

linux

#!/usr/bin/env sh
# x86_64-linux CI script to clean cache, if necessary

# set -x
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable

MAX_SIZE_B=2097152 #2 GB = 2*(1024)**2 KB
ZIG_CACHE_DIR="$(zig env | jq '. "global_cache_dir"')"
if test -e "$ZIG_CACHE_DIR"; then
  CHECK_SIZE_B=$(du -ks "$ZIG_CACHE_DIR" | cut -f1)
  if test "$CHECK_SIZE_B" -ge $MAX_SIZE_B; then
    echo "$CHECK_SIZE_B > $MAX_SIZE_B, removing global zig cache dir.."
    rm -fr "$ZIG_CACHE_DIR"
  fi
fi

zig env

zig build -Dno_opt_deps -Dno_cross test --summary all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant