lite Test Adding automated build cache wipe if > 50gb #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: lite Test Adding automated build cache wipe if > 50gb | |
on: | |
push: | |
branches: | |
- act-trigger | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: [self-hosted, Linux, ARM64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Clean up Docker Buildx Cache if it exceeds 50GB (Windows) | |
- name: Clean up Docker Buildx Cache (Windows) | |
if: runner.os == 'Windows' | |
shell: powershell | |
run: | | |
# Get the build cache size (in MB) | |
$cacheSize = (docker system df --format '{{.BuildCacheSize}}') -replace '[^\d]', '' | |
# Check if the cache size exceeds 50GB (50000MB) | |
if ($cacheSize -gt 50000) { | |
Write-Host "Cache is over 50GB, pruning..." | |
docker builder prune --all --force | |
} else { | |
Write-Host "Cache size is under 50GB, no action taken." | |
} | |
# Set up Docker Buildx conditionally based on OS: | |
- name: Set up Docker Buildx (Windows) | |
if: runner.os == 'Windows' | |
uses: docker/setup-buildx-action@v2 | |
- name: Set up Docker Buildx (Unix) | |
if: runner.os != 'Windows' | |
uses: docker/setup-buildx-action@v2 | |
with: | |
driver: docker-container | |
buildkitd-flags: --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Get Git Commit Hash for Linux/macOS | |
- name: Get Git Commit Hash (Unix) | |
if: runner.os != 'Windows' | |
run: echo "GIT_HASH=$(git rev-parse --short=9 HEAD)" >> $GITHUB_ENV | |
# Get Git Commit Hash for Windows using PowerShell | |
- name: Get Git Commit Hash (Windows) | |
if: runner.os == 'Windows' | |
shell: powershell | |
run: | | |
$gitHash = (git rev-parse --short=9 HEAD).Trim() | |
Add-Content -Path $env:GITHUB_ENV -Value "GIT_HASH=$gitHash" | |
# Get Latest Release Tag for Linux/macOS | |
- name: Get Latest Release Tag (Unix) | |
if: runner.os != 'Windows' | |
id: get_tag | |
run: | | |
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) | |
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
# Get Latest Release Tag for Windows using PowerShell | |
- name: Get Latest Release Tag (Windows) | |
if: runner.os == 'Windows' | |
id: get_tag_win | |
shell: powershell | |
run: | | |
$response = Invoke-WebRequest -Uri "https://api.github.com/repos/${{ github.repository }}/releases/latest" -UseBasicParsing | |
$json = $response.Content | ConvertFrom-Json | |
$tag = $json.tag_name | |
Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_TAG=$tag" | |
# Clean up Docker Buildx Cache if it exceeds 50GB (Unix) | |
- name: Clean up Docker Buildx Cache (Unix) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
# First check if build cache exists | |
if docker system df -v | grep -q "Build Cache"; then | |
# Get the build cache size and convert to MB | |
cache_info=$(docker system df -v | grep "Build Cache") | |
if echo "$cache_info" | grep -q "GB"; then | |
# Extract value and convert GB to MB | |
cache_size=$(echo "$cache_info" | awk '{print $3}' | sed 's/GB//' | awk '{printf "%.0f", $1 * 1024}') | |
elif echo "$cache_info" | grep -q "MB"; then | |
# Extract MB value directly | |
cache_size=$(echo "$cache_info" | awk '{print $3}' | sed 's/MB//' | awk '{printf "%.0f", $1}') | |
else | |
# Handle KB or smaller (treat as 0 MB) | |
cache_size=0 | |
fi | |
# Ensure cache_size is a number | |
if [[ "$cache_size" =~ ^[0-9]+$ ]]; then | |
# Check if the cache size exceeds 50GB (51200MB) | |
if [ "$cache_size" -gt 51200 ]; then | |
echo "Cache is over 50GB (${cache_size}MB), pruning..." | |
docker builder prune --all --force | |
else | |
echo "Cache size is ${cache_size}MB, under 50GB, no action taken." | |
fi | |
else | |
echo "Could not determine cache size, output was: $cache_info" | |
# Show example output to debug | |
echo "Full docker system df -v output:" | |
docker system df -v | |
fi | |
else | |
echo "No build cache found." | |
fi | |
# Build and Push Dev_25 Docker Image for Unix using bash | |
- name: Build and Push Dev_25 Docker Image (multi-arch, Unix) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
docker buildx build --platform linux/amd64,linux/arm64 \ | |
-t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:dev_v25 \ | |
--push . | |
# Build and Push Dev_25 Docker Image for Windows using PowerShell | |
- name: Build and Push Dev_25 Docker Image (multi-arch, Windows) | |
if: runner.os == 'Windows' | |
shell: powershell | |
run: docker buildx build --platform linux/amd64,linux/arm64 -t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:dev_v25 --push . |