Files
NixOS/.gitea/workflows/build-on-push.yml

95 lines
3.4 KiB
YAML

name: Build on Push
on:
push:
branches:
- main
workflow_dispatch: # Allow manual trigger
jobs:
build-configurations:
runs-on: nixos
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure Attic cache
run: |
# Configure attic client to use your cache server
attic login servidos http://127.0.0.1:2343 ${{ secrets.ATTIC_TOKEN }}
- name: Build workstation configuration
run: |
echo "Building workstation configuration..."
nix build .#nixosConfigurations.workstation.config.system.build.toplevel --quiet
- name: Build server configuration
run: |
echo "Building server configuration..."
nix build .#nixosConfigurations.server.config.system.build.toplevel --quiet
- name: Build emacs-vm configuration
run: |
echo "Building emacs-vm configuration..."
nix build .#emacs-vm --quiet
- name: Push to cache
continue-on-error: true
run: |
echo "Pushing builds to cache..."
# Retry function for attic push commands
retry_attic_push() {
local max_attempts=5
local attempt=1
local command="$@"
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt/$max_attempts: $command"
if eval "$command"; then
echo "✓ Successfully pushed to cache on attempt $attempt"
return 0
else
local exit_code=$?
echo "✗ Attempt $attempt failed with exit code $exit_code"
if [ $attempt -lt $max_attempts ]; then
echo "Waiting 2 seconds before retry..."
sleep 2
fi
attempt=$((attempt + 1))
fi
done
echo "⚠️ Failed to push to cache after $max_attempts attempts. Continuing anyway..."
return 0 # Don't fail the pipeline
}
# Push all built derivations to cache
if ls result* 1> /dev/null 2>&1; then
retry_attic_push "attic push servidos:nixos result*"
fi
# Push the specific system derivations we just built
# Get paths and push with retry (paths are already built, so this is fast)
workstation_path=$(nix build .#nixosConfigurations.workstation.config.system.build.toplevel --print-out-paths 2>/dev/null || echo "")
if [ -n "$workstation_path" ]; then
retry_attic_push "echo \"$workstation_path\" | attic push servidos:nixos --stdin"
fi
server_path=$(nix build .#nixosConfigurations.server.config.system.build.toplevel --print-out-paths 2>/dev/null || echo "")
if [ -n "$server_path" ]; then
retry_attic_push "echo \"$server_path\" | attic push servidos:nixos --stdin"
fi
emacs_path=$(nix build .#emacs-vm --print-out-paths 2>/dev/null || echo "")
if [ -n "$emacs_path" ]; then
retry_attic_push "echo \"$emacs_path\" | attic push servidos:nixos --stdin"
fi
- name: Summary
run: |
echo "✅ Build on push completed successfully!"
echo "- Built workstation, server, and emacs-vm configurations"
echo "- Pushed all builds to Atticd cache"