From 45c205b781c1e37e569708310a10ebcc893976ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Lumbroso?= Date: Mon, 27 Jun 2022 14:33:18 -0400 Subject: [PATCH] =?UTF-8?q?Added=20`tool-cache`=20opt=20thx=20to=20@miketi?= =?UTF-8?q?mofeev=20=F0=9F=99=8F=F0=9F=8F=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 10 ++++++++++ README.md | 15 +++++++++++++-- action.yml | 22 +++++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61c04d1..4be928d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,3 +8,13 @@ jobs: # If there is a problem with this GitHub Actions, this step will fail - name: Free Disk Space uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + + # all of these default to true, but feel free to set to + # false if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + swap-storage: true diff --git a/README.md b/README.md index 5ff2cd5..594775d 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ A customizable GitHub Actions to free disk space on Ubuntu GitHub Actions runners. -On a typical Ubuntu runner, with all options turned on (or not turned off rather), this can clear up to 25 GB of disk space in about 3 minutes (the longest period is calling `apt` to uninstall packages). +On a typical Ubuntu runner, with all options turned on (or not turned off rather), this can clear up to 25 GB of disk space in about 3 minutes (the longest period is calling `apt` to uninstall packages). This is useful when you need a lot of disk space to run computations. -Please don't hesitate to [submit issues](https://github.com/jlumbroso/free-disk-space/issues) to report problems or suggest new features (or sets of files to help remove). Also, please ⭐️ the repo if you like this GitHub Actions! Thanks! 😊 +Please don't hesitate to [submit issues](https://github.com/jlumbroso/free-disk-space/issues) to report problems or suggest new features (or sets of files to help remove). + +Also, please ⭐️ the repo if you like this GitHub Actions! Thanks! 😊 ## Example @@ -20,6 +22,9 @@ jobs: - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@main with: + # this might remove tools that are actually needed + tool-cache: false + # all of these default to true, but feel free to set to # false if necessary for your workflow android: true @@ -28,6 +33,11 @@ jobs: large-packages: true swap-storage: true ``` +## Options + +Most of the options are self-explanatory. + +The option `tool-cache` removes all the pre-cached tools (Node, Go, Python, Ruby, ...) that are loaded in a runner's environment, [installed in the path specified by the `AGENT_TOOLSDIRECTORY` environment variable](https://github.com/actions/virtual-environments/blob/5a2cb18a48bce5da183486b95f5494e4fd0c0640/images/linux/scripts/installers/configure-environment.sh#L25-L29) (the same environment variable is used across Windows/macOS/Linux runners, see an example of its use on [the `setup-python` GitHub Action](https://github.com/actions/setup-python)). This option was [suggested](https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159) by [@miketimofeev](https://github.com/miketimofeev). ## Acknowledgement @@ -37,6 +47,7 @@ Here are a few sources of inspiration: - https://github.community/t/bigger-github-hosted-runners-disk-space/17267/11 - https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh - https://github.com/ShubhamTatvamasi/free-disk-space-action +- https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159 ## Typical Output diff --git a/action.yml b/action.yml index 4fb65df..04bac75 100644 --- a/action.yml +++ b/action.yml @@ -20,13 +20,20 @@ inputs: required: false default: "true" - # option inspired after: + # option inspired by: # https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh large-packages: description: "Remove large packages" required: false default: "true" + # option inspired by: + # https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159 + tool-cache: + description: "Remove image tool cache" + required: false + default: "false" + swap-storage: description: "Remove swap storage" required: false @@ -173,6 +180,19 @@ runs: printSavedSpace $SAVED "Large misc. packages" fi + # Option: Remove tool cache + # REF: https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159 + + if [[ ${{ inputs.tool-cache }} == 'true' ]]; then + BEFORE=$(getAvailableSpace) + + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + + AFTER=$(getAvailableSpace) + SAVED=$((AFTER-BEFORE)) + printSavedSpace $SAVED "Tool cache" + fi + # Option: Remove Swap storage if [[ ${{ inputs.swap-storage }} == 'true' ]]; then