Skip to content

Commit a03ffbb

Browse files
committed
ci: clean node_modules and target
1 parent f48b59f commit a03ffbb

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

.github/actions/clean/action.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 clean -ffdx -e node_modules target
15+
git reset --hard HEAD
16+
17+
- name: Clean Large Directories by Size
18+
if: ${{ !contains(inputs.target, 'windows') }}
19+
shell: bash
20+
run: |
21+
if [ -d "target" ]; then
22+
TARGET_SIZE=$(du -s target | awk '{print $1}')
23+
MAX_SIZE=$((50 * 1024 * 1024))
24+
25+
echo "MAX_SIZE = $MAX_SIZE"
26+
if [ "$TARGET_SIZE" -gt "$MAX_SIZE" ]; then
27+
echo "`target` directory size is greater than 50GB, deleting..."
28+
rm -rf target
29+
else
30+
echo "`target` directory size is within limits."
31+
fi
32+
fi
33+
34+
if [ -d "node_modules" ]; then
35+
NODE_MODULES_SIZE=$(du -s node_modules | awk '{print $1}')
36+
MAX_SIZE=$((50 * 1024 * 1024))
37+
38+
echo "MAX_SIZE = $MAX_SIZE"
39+
if [ "$NODE_MODULES_SIZE" -gt "$MAX_SIZE" ]; then
40+
echo "`node_modules` directory size is greater than 50GB, deleting..."
41+
rm -rf node_modules
42+
else
43+
echo "`node_modules` directory size is within limits."
44+
fi
45+
fi
46+
47+
- name: Clean Large Directories by Time
48+
if: ${{ contains(inputs.target, 'windows') }}
49+
shell: bash
50+
run: |
51+
if [ -d "target" ]; then
52+
TARGET_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime)"
53+
TWO_WEEKS_AGO=$(date -d '2 weeks ago' +%s)
54+
55+
echo "TARGET_CREATION_TIME = $TARGET_CREATION_TIME"
56+
57+
if [ "$TARGET_CREATION_TIME" -lt "$TWO_WEEKS_AGO" ]; then
58+
echo "'target' directory is older than 2 weeks, deleting..."
59+
rm -rf target
60+
else
61+
echo "'target' directory is within 2 weeks."
62+
fi
63+
fi
64+
65+
if [ -d "node_modules" ]; then
66+
NODE_MODULES_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime)
67+
ONE_MONTH_AGO=$(date -d '1 month ago' +%s)
68+
69+
echo "NODE_MODULES_CREATION_TIME = $NODE_MODULES_CREATION_TIME"
70+
71+
if [ "$NODE_MODULES_CREATION_TIME" -lt "$ONE_MONTH_AGO" ]; then
72+
echo "'node_modules' directory is older than 1 month, deleting..."
73+
rm -rf node_modules
74+
else
75+
echo "'node_modules' directory is within 1 month."
76+
fi
77+
fi

.github/workflows/reusable-build.yml

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

74-
- name: Git Clean
74+
- name: Clean
7575
if: ${{ !startsWith(runner.name, 'GitHub Actions') }}
76-
shell: bash
77-
run: |
78-
git clean -ffdx -e node_modules target
79-
git reset --hard HEAD
76+
uses: ./.github/actions/clean
77+
with:
78+
target: ${{ inputs.target }}
8079

8180
- name: Setup tmate session
8281
uses: mxschmitt/action-tmate@v3
@@ -221,12 +220,11 @@ jobs:
221220
ref: ${{ inputs.ref }}
222221
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}
223222

224-
- name: Git Clean
223+
- name: Clean
225224
if: ${{ !startsWith(runner.name, 'GitHub Actions') }}
226-
shell: bash
227-
run: |
228-
git clean -ffdx -e node_modules target
229-
git reset --hard HEAD
225+
uses: ./.github/actions/clean
226+
with:
227+
target: ${{ inputs.target }}
230228

231229
- name: Download bindings
232230
uses: ./.github/actions/download-artifact
@@ -274,12 +272,11 @@ jobs:
274272
ref: ${{ inputs.ref }}
275273
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}
276274

277-
- name: Git Clean
275+
- name: Clean
278276
if: ${{ !startsWith(runner.name, 'GitHub Actions') }}
279-
shell: bash
280-
run: |
281-
git clean -ffdx -e node_modules target
282-
git reset --hard HEAD
277+
uses: ./.github/actions/clean
278+
with:
279+
target: ${{ inputs.target }}
283280

284281
- name: Download bindings
285282
if: ${{ !inputs.skipable }}

0 commit comments

Comments
 (0)