-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
81 lines (80 loc) · 3.89 KB
/
action.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
name: 'Remove unused tools from the runner'
author: 'Altan Orhon'
description: 'This action will remove the tools that are not needed for the workflow from the runner'
inputs:
rm-android:
description: "Whether to remove Android tools"
default: 'true'
rm-dotnet:
description: "Whether to remove .NET tools"
default: 'true'
rm-hosted-tool-cache:
description: "Whether to remove the hosted tool cache"
default: 'true'
rm-powershell:
description: "Whether to remove PowerShell"
default: 'true'
rm-swift:
description: "Whether to remove Swift"
default: 'true'
rm-chromium:
description: "Whether to remove Chromium"
default: 'true'
rm-azure-cli:
description: "Whether to remove Azure CLI"
default: 'true'
rm-apt-packages:
description: "Remove apt packages"
default: 'false'
rm-apt-cache:
description: "Clear apt cache"
default: 'false'
apt-packages-remove-default:
description: "Packages to remove"
default: 'ansible azure-cli xorriso zsync esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable google-cloud-sdk imagemagick libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl mercurial mono-complete libmysqlclient unixodbc-dev yarn chrpath libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev snmp pollinate libpq-dev postgresql-client powershell ruby-full sphinxsearch subversion mongodb-org azure-cli microsoft-edge-stable google-cloud-sdk'
apt-packages-remove-include:
description: "Additional packages to remove"
apt-packages-remove-exclude:
description: "Packages to keep"
runs:
using: 'composite'
steps:
- name: Show disk usage
shell: bash
run: |
echo "Disk usage before cleanup:"
df -hlT
- name: Remove tools
shell: bash
run: |
set -eu -o pipefail
[[ "${{ inputs.rm-android }}" == "true" ]] && sudo du -s -h /usr/local/lib/android && sudo rm -rf "$_" && echo "::notice::Removed Android tools"
[[ "${{ inputs.rm-dotnet }}" == "true" ]] && sudo du -s -h /usr/share/dotnet && sudo rm -rf "$_" && echo "::notice::Removed .NET tools"
[[ "${{ inputs.rm-hosted-tool-cache }}" == "true" ]] && sudo du -s -h /opt/hostedtoolcache && sudo rm -rf "$_" && echo "::notice::Removed the hosted tool cache"
[[ "${{ inputs.rm-powershell }}" == "true" ]] && sudo du -s -h /usr/local/share/powershell && sudo rm -rf "$_" && echo "::notice::Removed PowerShell"
[[ "${{ inputs.rm-swift }}" == "true" ]] && sudo du -s -h /usr/share/swift && sudo rm -rf "$_" && echo "::notice::Removed Swift"
[[ "${{ inputs.rm-chromium }}" == "true" ]] && sudo du -s -h /usr/local/share/chromium && sudo rm -rf "$_" && echo "::notice::Removed Chromium"
[[ "${{ inputs.rm-azure-cli }}" == "true" ]] && sudo du -s -h /opt/az && sudo rm -rf "$_" /usr/share/az_* && echo "::notice::Removed Azure CLI"
- name: Remove apt packages
shell: bash
if: ${{ inputs.rm-apt-packages == 'true' }}
run: |
set -eu -o pipefail
declare -a packages=()
comm -23 <(echo "${{inputs.apt-packages-remove-default}} ${{inputs.apt-packages-remove-include}}" | tr ' ' '\n' | sort | uniq) <(echo "${{inputs.apt-packages-remove-exclude}}" | tr ' ' '\n' | sort | uniq) | while read -r package; do
packages+=("$package")
done
if [[ "${#packages[@]}" -gt 0 ]]; then
sudo apt-get purge -yq "${packages[@]}" && echo "::notice::Removed apt packages"
sudo apt-get autoremove -y && echo "::notice::Removed unused apt packages"
fi
- name: Clear apt cache
if: ${{ inputs.rm-apt-cache == 'true' || inputs.rm-apt-packages == 'true' }}
shell: bash
run: |
sudo apt-get clean -y && echo "::notice::Cleaned apt cache"
- name: Show disk usage
shell: bash
run: |
echo "Disk usage after cleanup:"
df -hlT