Skip to content

Commit

Permalink
ci: clean node_modules and target
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Jul 24, 2024
1 parent f48b59f commit f6549d4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 15 deletions.
77 changes: 77 additions & 0 deletions .github/actions/clean/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Clean Repository

inputs:
target:
required: true
type: string

runs:
using: composite
steps:
- name: Git Clean
shell: bash
run: |
git clean -ffdx -e node_modules target
git reset --hard HEAD
- name: Clean Large Directories by Size
if: ${{ !contains(inputs.target, 'windows') }}
shell: bash
run: |
if [ -d "target" ]; then
TARGET_SIZE=$(du -s target | awk '{print $1}')
MAX_SIZE=$((50 * 1024 * 1024))
echo "MAX_SIZE = $MAX_SIZE"
if [ "$TARGET_SIZE" -gt "$MAX_SIZE" ]; then
echo "`target` directory size is greater than 50GB, deleting..."
rm -rf target
else
echo "`target` directory size is within limits."
fi
fi
if [ -d "node\_modules" ]; then
NODE_MODULES_SIZE=$(du -s node_modules | awk '{print $1}')
MAX_SIZE=$((50 * 1024 * 1024))
echo "MAX_SIZE = $MAX_SIZE"
if [ "$NODE_MODULES_SIZE" -gt "$MAX_SIZE" ]; then
echo "`node_modules` directory size is greater than 50GB, deleting..."
rm -rf node_modules
else
echo "`node_modules` directory size is within limits."
fi
fi
- name: Clean Large Directories by Time
if: ${{ contains(inputs.target, 'windows') }}
shell: bash
run: |
if [ -d "target" ]; then
TARGET_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime")
TWO_WEEKS_AGO=$(date -d '2 weeks ago' +%s)
echo "TARGET_CREATION_TIME = $TARGET_CREATION_TIME"
if [ "$TARGET_CREATION_TIME" -lt "$TWO_WEEKS_AGO" ]; then
echo "'target' directory is older than 2 weeks, deleting..."
rm -rf target
else
echo "'target' directory is within 2 weeks."
fi
fi
if [ -d "node\_modules" ]; then
NODE_MODULES_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime")
ONE_MONTH_AGO=$(date -d '1 month ago' +%s)
echo "NODE_MODULES_CREATION_TIME = $NODE_MODULES_CREATION_TIME"
if [ "$NODE_MODULES_CREATION_TIME" -lt "$ONE_MONTH_AGO" ]; then
echo "'node_modules' directory is older than 1 month, deleting..."
rm -rf node_modules
else
echo "'node_modules' directory is within 1 month."
fi
fi
27 changes: 12 additions & 15 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ jobs:
ref: ${{ inputs.ref }}
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}

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

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

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

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

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

- name: Download bindings
if: ${{ !inputs.skipable }}
Expand Down

0 comments on commit f6549d4

Please sign in to comment.