Skip to content

Commit dbc5223

Browse files
authored
ci: clean node_modules and target (#7299)
1 parent e05fff8 commit dbc5223

File tree

2 files changed

+64
-27
lines changed

2 files changed

+64
-27
lines changed

.github/actions/clean/action.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Clean Repository
2+
3+
inputs:
4+
target:
5+
required: true
6+
type: string
7+
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Git Clean
12+
shell: bash
13+
run: |
14+
git config --system core.longpaths true
15+
rm -rf node_modules
16+
git clean -ffdx -e target
17+
git reset --hard HEAD
18+
19+
- name: Clean Large Directories by Size
20+
if: ${{ !contains(inputs.target, 'windows') }}
21+
shell: bash
22+
run: |
23+
if [ -d "target" ]; then
24+
TARGET_SIZE=$(du -s target | awk '{print $1}')
25+
MAX_SIZE=$((50 * 1024 * 1024))
26+
27+
echo "MAX_SIZE = $MAX_SIZE"
28+
if [ "$TARGET_SIZE" -gt "$MAX_SIZE" ]; then
29+
echo "`target` directory size is greater than 50GB, deleting..."
30+
rm -rf target
31+
else
32+
echo "`target` directory size is within limits."
33+
fi
34+
fi
35+
36+
- name: Clean Large Directories by Time
37+
if: ${{ contains(inputs.target, 'windows') }}
38+
shell: bash
39+
run: |
40+
if [ -d "target" ]; then
41+
TARGET_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime")
42+
TWO_WEEKS_AGO=$(date -d '2 weeks ago' +%s)
43+
44+
echo "TARGET_CREATION_TIME = $TARGET_CREATION_TIME"
45+
46+
if [ "$TARGET_CREATION_TIME" -lt "$TWO_WEEKS_AGO" ]; then
47+
echo "'target' directory is older than 2 weeks, deleting..."
48+
rm -rf target
49+
else
50+
echo "'target' directory is within 2 weeks."
51+
fi
52+
fi

.github/workflows/reusable-build.yml

+12-27
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,11 @@ jobs:
7171
ref: ${{ inputs.ref }}
7272
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}
7373

74-
- name: Git Clean
74+
- name: Clean
7575
if: ${{ !inputs.skipable && !startsWith(runner.name, 'GitHub Actions') }}
76-
shell: bash
77-
run: |
78-
git config --system core.longpaths true
79-
echo "rm -rf node_modules"
80-
rm -rf node_modules
81-
echo "git clean -ffdx -e target"
82-
git clean -ffdx -e target
83-
git reset --hard HEAD
76+
uses: ./.github/actions/clean
77+
with:
78+
target: ${{ inputs.target }}
8479

8580
- name: Setup tmate session
8681
uses: mxschmitt/action-tmate@v3
@@ -225,16 +220,11 @@ jobs:
225220
ref: ${{ inputs.ref }}
226221
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}
227222

228-
- name: Git Clean
223+
- name: Clean
229224
if: ${{ !startsWith(runner.name, 'GitHub Actions') }}
230-
shell: bash
231-
run: |
232-
git config --system core.longpaths true
233-
echo "rm -rf node_modules"
234-
rm -rf node_modules
235-
echo "git clean -ffdx -e target"
236-
git clean -ffdx -e target
237-
git reset --hard HEAD
225+
uses: ./.github/actions/clean
226+
with:
227+
target: ${{ inputs.target }}
238228

239229
- name: Download bindings
240230
uses: ./.github/actions/download-artifact
@@ -282,16 +272,11 @@ jobs:
282272
ref: ${{ inputs.ref }}
283273
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}
284274

285-
- name: Git Clean
275+
- name: Clean
286276
if: ${{ !inputs.skipable && !startsWith(runner.name, 'GitHub Actions') }}
287-
shell: bash
288-
run: |
289-
git config --system core.longpaths true
290-
echo "rm -rf node_modules"
291-
rm -rf node_modules
292-
echo "git clean -ffdx -e target"
293-
git clean -ffdx -e target
294-
git reset --hard HEAD
277+
uses: ./.github/actions/clean
278+
with:
279+
target: ${{ inputs.target }}
295280

296281
- name: Download bindings
297282
if: ${{ !inputs.skipable }}

0 commit comments

Comments
 (0)