-
-
Notifications
You must be signed in to change notification settings - Fork 641
136 lines (119 loc) · 5.2 KB
/
lite-test-ubuntu-headless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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 .