Skip to content

Commit 45c205b

Browse files
committed
Added tool-cache opt thx to @miketimofeev πŸ™πŸ»
1 parent c73e8a3 commit 45c205b

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

β€Ž.github/workflows/test.ymlβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ jobs:
88
# If there is a problem with this GitHub Actions, this step will fail
99
- name: Free Disk Space
1010
uses: jlumbroso/free-disk-space@main
11+
with:
12+
tool-cache: true
13+
14+
# all of these default to true, but feel free to set to
15+
# false if necessary for your workflow
16+
android: true
17+
dotnet: true
18+
haskell: true
19+
large-packages: true
20+
swap-storage: true

β€ŽREADME.mdβ€Ž

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
A customizable GitHub Actions to free disk space on Ubuntu GitHub Actions runners.
44

5-
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).
5+
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.
66

7-
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! 😊
7+
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).
8+
9+
Also, please ⭐️ the repo if you like this GitHub Actions! Thanks! 😊
810

911
## Example
1012

@@ -20,6 +22,9 @@ jobs:
2022
- name: Free Disk Space (Ubuntu)
2123
uses: jlumbroso/free-disk-space@main
2224
with:
25+
# this might remove tools that are actually needed
26+
tool-cache: false
27+
2328
# all of these default to true, but feel free to set to
2429
# false if necessary for your workflow
2530
android: true
@@ -28,6 +33,11 @@ jobs:
2833
large-packages: true
2934
swap-storage: true
3035
```
36+
## Options
37+
38+
Most of the options are self-explanatory.
39+
40+
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).
3141

3242
## Acknowledgement
3343

@@ -37,6 +47,7 @@ Here are a few sources of inspiration:
3747
- https://github.community/t/bigger-github-hosted-runners-disk-space/17267/11
3848
- https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
3949
- https://github.com/ShubhamTatvamasi/free-disk-space-action
50+
- https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159
4051

4152
## Typical Output
4253

β€Žaction.ymlβ€Ž

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ inputs:
2020
required: false
2121
default: "true"
2222

23-
# option inspired after:
23+
# option inspired by:
2424
# https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
2525
large-packages:
2626
description: "Remove large packages"
2727
required: false
2828
default: "true"
2929

30+
# option inspired by:
31+
# https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159
32+
tool-cache:
33+
description: "Remove image tool cache"
34+
required: false
35+
default: "false"
36+
3037
swap-storage:
3138
description: "Remove swap storage"
3239
required: false
@@ -173,6 +180,19 @@ runs:
173180
printSavedSpace $SAVED "Large misc. packages"
174181
fi
175182
183+
# Option: Remove tool cache
184+
# REF: https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159
185+
186+
if [[ ${{ inputs.tool-cache }} == 'true' ]]; then
187+
BEFORE=$(getAvailableSpace)
188+
189+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
190+
191+
AFTER=$(getAvailableSpace)
192+
SAVED=$((AFTER-BEFORE))
193+
printSavedSpace $SAVED "Tool cache"
194+
fi
195+
176196
# Option: Remove Swap storage
177197
178198
if [[ ${{ inputs.swap-storage }} == 'true' ]]; then

0 commit comments

Comments
Β (0)