|
| 1 | +name: Initialize Environment |
| 2 | + |
| 3 | +description: Initialization steps for kagent actions |
| 4 | + |
| 5 | +runs: |
| 6 | + using: "composite" |
| 7 | + steps: |
| 8 | + - name: Cancel Previous Actions |
| 9 | + uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 |
| 10 | + with: |
| 11 | + access_token: ${{ github.token }} |
| 12 | + - name: Free disk space |
| 13 | + shell: bash |
| 14 | + run: | |
| 15 | + echo "Before clearing disk space:" |
| 16 | + df -h |
| 17 | + docker system df -v |
| 18 | +
|
| 19 | + # https://github.com/actions/runner-images/discussions/3242 github runners are bad at cleanup |
| 20 | + echo "Removing large packages" |
| 21 | + sudo apt-get remove -y '^dotnet-.*' || true |
| 22 | + sudo apt-get remove -y '^llvm-.*' || true |
| 23 | + sudo apt-get remove -y 'php.*' || true |
| 24 | + sudo apt-get remove -y '^mongodb-.*' || true |
| 25 | + sudo apt-get remove -y '^mysql-.*' || true |
| 26 | + sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri || true |
| 27 | + sudo apt-get autoremove -y || true |
| 28 | + sudo apt-get clean -y || true |
| 29 | + echo "Done removing large packages" |
| 30 | +
|
| 31 | + # Clean up pre-installed tools |
| 32 | + # For some reason, GHA often takes minutes (up to 20min observed) to clean up somehow. |
| 33 | + # Presumably this is due to a slow disk? |
| 34 | + function clean-dir() { |
| 35 | + echo "Cleaning $1" |
| 36 | + time sudo rm -rf "$1" || true |
| 37 | + } |
| 38 | + # These two were found to take very very long. Even though its large, its not worth the cost |
| 39 | + # clean-dir /usr/local/lib/android # 8.9gb |
| 40 | + # clean-dir $AGENT_TOOLSDIRECTORY # 5.6gb |
| 41 | + clean-dir /usr/share/dotnet # 3.4gb |
| 42 | + clean-dir /usr/share/swift # 3.1gb |
| 43 | + clean-dir /usr/local/.ghcup # 6.3gb |
| 44 | + clean-dir /usr/local/share/powershell # 1.2gb |
| 45 | + clean-dir /usr/local/share/chromium # 600mb |
| 46 | +
|
| 47 | + # Clean up images |
| 48 | + docker image rm node:18 || true |
| 49 | + docker image rm node:18-alpine || true |
| 50 | + docker image rm node:20 || true |
| 51 | + docker image rm node:20-alpine || true |
| 52 | + # remove the dangling images and containers |
| 53 | + docker images | tail -n +2 | awk '$1 == "<none>" {print $3}' | xargs --no-run-if-empty docker rmi |
| 54 | + docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $1}' | xargs --no-run-if-empty docker rm --volumes=true |
| 55 | +
|
| 56 | + # Clean up Docker |
| 57 | + docker system prune -f || true |
| 58 | +
|
| 59 | + echo "After clearing disk space:" |
| 60 | + df -h |
| 61 | + docker system df -v |
0 commit comments