ci: Try caching in the nix build

This commit is contained in:
2025-09-17 17:23:01 -05:00
parent daeb844fdf
commit 43b7694554
4 changed files with 72 additions and 6 deletions

View File

@@ -8,15 +8,13 @@ on:
- '*.*.*'
jobs:
build-deploy-ubuntu:
env:
RUNNER_TOOL_CACHE: /toolcache
# Is it a risk to Ouroboros this?
# Really want this to be able to run on ubuntu but it is a slow run.
runs-on: ubuntu-latest
# runs-on: nix-runner
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: Install Nix
@@ -58,22 +56,36 @@ jobs:
run: |
nix develop -c bash scripts/deploy.sh
nix-check:
env:
RUNNER_TOOL_CACHE: /toolcache
runs-on: nix-runner
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: "Cache Nix store"
uses: actions/cache@v4
id: nix-cache
with:
path: /tmp/nixcache
key: nix-${{ runner.os }}-nix-builder-image-${{ hashFiles('**/package.json', 'package-lock.json', '**/*.nix', '**/flake.lock', '.npmrc', '.eleventy.js') }}
restore-keys: |
nix-${{ runner.os }}-nix-builder-image
- name: Setup Attic Cache
uses: ryanccn/attic-action@3354ae812cb672e1381be4c7914204c44db53866
with:
endpoint: ${{ secrets.ATTIC_ENDPOINT }}
cache: ${{ secrets.ATTIC_CACHE }}
token: ${{ secrets.ATTIC_TOKEN }}
- name: "Import Nix store cache"
continue-on-error: true
# if: "steps.nix-cache.outputs.cache-hit == 'true'"
run: bash scripts/restore_cache.sh
- name: Build container
run: nix build .#act-runner-image
- name: Check Nix flake
run: nix flake check
id: flake-check
- name: "Export Nix store cache"
if: always()
# if: "steps.nix-cache.outputs.cache-hit != 'true'"
run: bash scripts/populate_cache.sh

38
scripts/populate_cache.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -Eeuox pipefail
CACHE_PATH=${CACHE_PATH:-"/tmp/nixcache"}
banner() {
echo "========================================================"
echo " $*"
echo "========================================================"
}
banner "List what we start with"
nix-store --query --requisites --include-outputs "$(nix eval .\#devShells.x86_64-linux.default.drvPath --raw)" >dependencies.txt
nix-store --query --requisites --include-outputs "$(nix eval .\#packages.x86_64-linux.default.drvPath --raw)" >>dependencies.txt
# nix-store --query --requisites --include-outputs "$(nix eval .\#checks.x86_64-linux.formatting.drvPath --raw)" >>dependencies.txt
# nix-store --query --requisites --include-outputs "$(nix eval .\#checks.x86_64-linux.test-check.drvPath --raw)" >>dependencies.txt
nix-store --query --requisites --include-outputs "$(nix eval .\#formatter.x86_64-linux.drvPath --raw)" >>dependencies.txt
sort -o dependencies.txt -u dependencies.txt
banner "list obtained paths to cache"
wc -l dependencies.txt
banner "filter out our matches"
echo "Using filter"
cat scripts/populate_cache_exclude_patterns.txt
grep -vf scripts/populate_cache_exclude_patterns.txt dependencies.txt >filtered_dependencies.txt
echo "Count our filtered"
wc -l filtered_dependencies.txt
xargs <filtered_dependencies.txt -r nix copy --to "file://${CACHE_PATH}" --no-substitute
banner "done with populating cache"

16
scripts/restore_cache.sh Normal file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -Eeuo pipefail
CACHE_PATH=${CACHE_PATH:-"/tmp/nixcache"}
banner() {
echo "========================================================"
echo " $*"
echo "========================================================"
}
# banner "List what we start with"
# ls -alh "${CACHE_PATH}"
banner "Copy time"
nix copy --from "file://${CACHE_PATH}" --no-check-sigs --all