Implement retry mechanism for attic push commands in build workflows to enhance reliability and prevent pipeline failures. Update cache push logic in build-on-push, build-schemes, and weekly-build-cache workflows.
This commit is contained in:
@@ -34,17 +34,57 @@ jobs:
|
|||||||
nix build .#emacs-vm --quiet
|
nix build .#emacs-vm --quiet
|
||||||
|
|
||||||
- name: Push to cache
|
- name: Push to cache
|
||||||
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
echo "Pushing builds to cache..."
|
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
|
# Push all built derivations to cache
|
||||||
if ls result* 1> /dev/null 2>&1; then
|
if ls result* 1> /dev/null 2>&1; then
|
||||||
attic push servidos:nixos result*
|
retry_attic_push "attic push servidos:nixos result*"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Push the specific system derivations we just built
|
# Push the specific system derivations we just built
|
||||||
nix build .#nixosConfigurations.workstation.config.system.build.toplevel --print-out-paths | attic push servidos:nixos --stdin
|
# Get paths and push with retry (paths are already built, so this is fast)
|
||||||
nix build .#nixosConfigurations.server.config.system.build.toplevel --print-out-paths | attic push servidos:nixos --stdin
|
workstation_path=$(nix build .#nixosConfigurations.workstation.config.system.build.toplevel --print-out-paths 2>/dev/null || echo "")
|
||||||
nix build .#emacs-vm --print-out-paths | attic push servidos:nixos --stdin
|
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
|
- name: Summary
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -36,9 +36,36 @@ jobs:
|
|||||||
attic login servidos http://127.0.0.1:2343 ${{ secrets.ATTIC_TOKEN }}
|
attic login servidos http://127.0.0.1:2343 ${{ secrets.ATTIC_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push all schemes
|
- name: Build and push all schemes
|
||||||
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
echo "Building and pushing all schemes..."
|
echo "Building and pushing all schemes..."
|
||||||
|
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
# Store original scheme
|
# Store original scheme
|
||||||
ORIGINAL_SCHEME=$(grep -oP "scheme = schemesFile\.schemes\.\K\w+" config/stylix.nix)
|
ORIGINAL_SCHEME=$(grep -oP "scheme = schemesFile\.schemes\.\K\w+" config/stylix.nix)
|
||||||
echo "Original scheme: $ORIGINAL_SCHEME"
|
echo "Original scheme: $ORIGINAL_SCHEME"
|
||||||
@@ -61,14 +88,17 @@ jobs:
|
|||||||
--out-link ./result-$scheme \
|
--out-link ./result-$scheme \
|
||||||
--quiet
|
--quiet
|
||||||
|
|
||||||
# Push to cache
|
# Push to cache with retry
|
||||||
echo "Pushing $scheme to cache..."
|
echo "Pushing $scheme to cache..."
|
||||||
attic push servidos:nixos ./result-$scheme
|
retry_attic_push "attic push servidos:nixos ./result-$scheme"
|
||||||
|
|
||||||
# Also push using print-out-paths for better cache coverage
|
# Also push using print-out-paths for better cache coverage
|
||||||
nix build .#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel \
|
build_path=$(nix build .#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel \
|
||||||
--print-out-paths \
|
--print-out-paths \
|
||||||
--quiet | attic push servidos:nixos --stdin
|
--quiet 2>/dev/null || echo "")
|
||||||
|
if [ -n "$build_path" ]; then
|
||||||
|
retry_attic_push "echo \"$build_path\" | attic push servidos:nixos --stdin"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "✓ Completed $scheme"
|
echo "✓ Completed $scheme"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -60,17 +60,57 @@ jobs:
|
|||||||
|
|
||||||
- name: Push to cache
|
- name: Push to cache
|
||||||
if: steps.check_changes.outputs.changes == 'true'
|
if: steps.check_changes.outputs.changes == 'true'
|
||||||
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
echo "Pushing builds to cache..."
|
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
|
# Push all built derivations to cache
|
||||||
if ls result* 1> /dev/null 2>&1; then
|
if ls result* 1> /dev/null 2>&1; then
|
||||||
attic push servidos:nixos result*
|
retry_attic_push "attic push servidos:nixos result*"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Push the specific system derivations we just built
|
# Push the specific system derivations we just built
|
||||||
nix build .#nixosConfigurations.workstation.config.system.build.toplevel --print-out-paths | attic push servidos:nixos --stdin
|
# Get paths and push with retry (paths are already built, so this is fast)
|
||||||
nix build .#nixosConfigurations.server.config.system.build.toplevel --print-out-paths | attic push servidos:nixos --stdin
|
workstation_path=$(nix build .#nixosConfigurations.workstation.config.system.build.toplevel --print-out-paths 2>/dev/null || echo "")
|
||||||
nix build .#emacs-vm --print-out-paths | attic push servidos:nixos --stdin
|
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: Commit updated flake.lock
|
- name: Commit updated flake.lock
|
||||||
if: steps.check_changes.outputs.changes == 'true'
|
if: steps.check_changes.outputs.changes == 'true'
|
||||||
|
|||||||
Reference in New Issue
Block a user