Skip to content

Commit

Permalink
Added tool-cache opt thx to @miketimofeev πŸ™πŸ»
Browse files Browse the repository at this point in the history
  • Loading branch information
jlumbroso committed Jun 27, 2022
1 parent c73e8a3 commit 45c205b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
22 changes: 21 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45c205b

Please sign in to comment.