Skip to content

lite Test Adding automated build cache wipe if > 50gb #5

lite Test Adding automated build cache wipe if > 50gb

lite Test Adding automated build cache wipe if > 50gb #5

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: |
# Get the build cache size (in MB)
cache_size=$(docker system df --format '{{.Size}}' --filter type=build-cache | tr -d '[:alpha:]' | tr -d '[:space:]')
# Check if the cache size exceeds 50GB (50000MB)
if [ "$cache_size" -gt 50000 ]; then
echo "Cache is over 50GB, pruning..."
docker builder prune --all --force
else
echo "Cache size is under 50GB, no action taken."
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 .