|
| 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 |
0 commit comments