-
Notifications
You must be signed in to change notification settings - Fork 81
197 lines (167 loc) · 6.87 KB
/
test.yaml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Test
on:
workflow_dispatch:
schedule:
# weekly, randomly chosen time
- cron: "17 18 * * 0"
push:
branches-ignore:
- 'test-report'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
REPORT_DIR: /tmp/build-report
jobs:
test-docker-tmp:
name: Test removing root-owned folder
runs-on: ubuntu-latest
steps:
- name: Check out Maximize Build Space action
uses: actions/checkout@v4
with:
path: ./.github/actions/maximize-test
- name: Maximize build space
uses: ./.github/actions/maximize-test
with:
build-mount-path: /var/lib/docker/tmp
test-mount-parent-of-workspace:
name: Test mounting the parent of GITHUB_WORKSPACE
runs-on: ubuntu-latest
steps:
- name: Check out Maximize Build Space action
uses: actions/checkout@v4
with:
path: ./.github/actions/maximize-test
- name: Calculate parent of workspace
id: workspace-parent
run: echo "parent=$(dirname "${GITHUB_WORKSPACE}")" >> "$GITHUB_OUTPUT"
- name: Maximize build space
uses: ./.github/actions/maximize-test
with:
build-mount-path: ${{ steps.workspace-parent.outputs.parent }}
- name: Create file in build folder as runner user (test ownership)
run: |
mkdir -p ${{ steps.workspace-parent.outputs.parent }}/new
touch ${{ steps.workspace-parent.outputs.parent }}/new/file.txt
touch ${GITHUB_WORKSPACE}/file.txt
ls -alR ${{ steps.workspace-parent.outputs.parent }}
determine-free-space:
name: Determine free space with different settings
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-22.04
remove-android:
- 'true'
- 'false'
remove-dotnet:
- 'true'
- 'false'
remove-haskell:
- 'true'
- 'false'
remove-codeql:
- 'true'
- 'false'
remove-docker-images:
- 'true'
- 'false'
steps:
- name: Record start time
run: |
echo "START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Determine free space before
run: |
echo "FREE_GIG_BEFORE=$(df --output=avail --sync -BG "${{ github.workspace }}" | tail -1 | sed 's/[^0-9]*//g')" >> $GITHUB_ENV
- name: Check out Maximize Build Space action
uses: actions/checkout@v4
with:
path: ./.github/actions/maximize-test
- name: Maximize build space
uses: ./.github/actions/maximize-test
with:
remove-android: ${{ matrix.remove-android }}
remove-dotnet: ${{ matrix.remove-dotnet }}
remove-haskell: ${{ matrix.remove-haskell }}
remove-codeql: ${{ matrix.remove-codeql }}
remove-docker-images: ${{ matrix.remove-docker-images }}
- name: Record end time
run: |
echo "END_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Determine free space after
run: |
echo "FREE_GIG_AFTER=$(df --output=avail --sync -BG "${{ github.workspace }}" | tail -1 | sed 's/[^0-9]*//g')" >> $GITHUB_ENV
- name: Calculate freed space and elapsed time
run: |
REPORT_FILENAME_BASE="${REPORT_DIR}/${{ matrix.os }}_${{ matrix.remove-android }}_${{ matrix.remove-dotnet }}_${{ matrix.remove-haskell }}_${{ matrix.remove-codeql }}_${{ matrix.remove-docker-images }}"
FREED_GIG=$(expr ${FREE_GIG_AFTER} - ${FREE_GIG_BEFORE})
ELAPSED_TIME=$(expr ${END_TIME} - ${START_TIME})
echo "Free space before: ${FREE_GIG_BEFORE}G"
echo "Free space after : ${FREE_GIG_AFTER}G"
echo "Space freed : ${FREED_GIG}G"
echo "Time elapsed : ${ELAPSED_TIME} seconds"
mkdir -p "${REPORT_DIR}"
REMOVE_ANDROID="${{ matrix.remove-android }}"
REMOVE_DOTNET="${{ matrix.remove-dotnet }}"
REMOVE_HASKELL="${{ matrix.remove-haskell }}"
REMOVE_CODEQL="${{ matrix.remove-codeql }}"
REMOVE_DOCKER_IMAGES="${{ matrix.remove-docker-images }}"
cat <<EOF > "${REPORT_FILENAME_BASE}.json"
{
"os": "${{ matrix.os }}",
"remove_android": "${REMOVE_ANDROID//false/}",
"remove_dotnet": "${REMOVE_DOTNET//false/}",
"remove_haskell": "${REMOVE_HASKELL//false/}",
"remove_codeql": "${REMOVE_CODEQL//false/}",
"remove_docker_images": "${REMOVE_DOCKER_IMAGES//false/}",
"space_free_before": "${FREE_GIG_BEFORE}",
"space_free_after": "${FREE_GIG_AFTER}",
"space_freed": "${FREED_GIG}",
"elapsed_time": "${ELAPSED_TIME}"
}
EOF
jq -r '[.os, .remove_android, .remove_dotnet, .remove_haskell, .remove_codeql, .remove_docker_images, .space_freed, .space_free_after, .elapsed_time] | join(" | ")' < "${REPORT_FILENAME_BASE}.json" >> "${REPORT_FILENAME_BASE}.txt"
- name: Upload disk space report
uses: actions/upload-artifact@v3
with:
name: disk-space-report-single
path: ${{ env.REPORT_DIR }}
collect-reports:
name: Collect reports
runs-on: ubuntu-latest
needs: determine-free-space
env:
REPORT_FILE: space-free-report.md
steps:
- name: Download single reports
uses: actions/download-artifact@v3
with:
name: disk-space-report-single
path: ${{ env.REPORT_DIR }}
- name: Join Markdown report
run: |
echo 'OS | Android SDKs removed | .NET SDKs removed | Haskell removed | CodeQL Removed | Cached Docker Images Removed | GB freed | GB free | Elapsed Time (seconds) |' > "${REPORT_DIR}/${REPORT_FILE}"
echo '---|:--------------------:|:-----------------:|:---------------:|:--------------:|:----------------------------:|:--------:|:-------:|:----------------------:|' >> "${REPORT_DIR}/${REPORT_FILE}"
cat ${REPORT_DIR}/*.txt >> "${REPORT_DIR}/${REPORT_FILE}"
- name: Upload collected report
uses: actions/upload-artifact@v3
with:
name: disk-space-report-markdown
path: ${{ env.REPORT_DIR }}/${{ env.REPORT_FILE }}
- name: Checkout report branch
uses: actions/checkout@v4
with:
ref: test-report
- name: Overwrite old report
run: |
cp README.md.template README.md
cat ${{ env.REPORT_DIR }}/${{ env.REPORT_FILE }} >> README.md
cat "${REPORT_DIR}/${REPORT_FILE}"
git config user.name github-actions
git config user.email [email protected]
git add README.md
git commit -m "Generated new report" && git push || echo "Report unchanged, not updating."