From 949d08d235d6fb02830f9ab4218dbe6803e1d4a3 Mon Sep 17 00:00:00 2001 From: Victor Alfaro Date: Fri, 2 Feb 2024 14:51:53 -0600 Subject: [PATCH] Clean-up runner (#27504) * Clean-up runner * test * test * test --- .github/actions/cleanup-runner/action.yml | 72 +++++++++++++++++++++++ .github/workflows/maven-cicd-pipeline.yml | 37 +++++------- 2 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 .github/actions/cleanup-runner/action.yml diff --git a/.github/actions/cleanup-runner/action.yml b/.github/actions/cleanup-runner/action.yml new file mode 100644 index 000000000000..606544be5262 --- /dev/null +++ b/.github/actions/cleanup-runner/action.yml @@ -0,0 +1,72 @@ +# action.yml +name: 'Cleanup Runner' +description: 'Cleans up runner resources' +author: 'victoralfaro-dotcms' +runs: + using: 'composite' + steps: + - name: Show Disk Usage + shell: bash + run: | + echo '# df -h' + df -h + + echo '# docker images' + docker images || true + + echo '# du -sh /home/runner' + sudo du -sh /home/runner || true + + - name: Clean apt cache + shell: bash + run: | + echo 'Clean apt cache' + time sudo apt-get clean -y + time sudo apt-get autoclean -y + time sudo apt-get autoremove -y + time sudo rm -rf /var/lib/apt/lists/* + + - name: Cleanup Docker + shell: bash + run: | + echo 'Cleanup Docker' + time docker system prune -f + time docker volume prune -f + time docker image prune -f + time docker container prune -f + time docker network prune -f + + - name: Reclaim Disk Space + shell: bash + run: | + removeIfExists() { + local file=$1 + [[ -e $file ]] && time sudo rm -rf $1 || true + } + + removeIfExists /usr/share/dotnet + removeIfExists /usr/share/swift + removeIfExists /usr/local/lib/android + removeIfExists /opt/ghc + removeIfExists /opt/pipx + + removeIfExists /opt/hostedtoolcache/CodeQL + removeIfExists /imagegeneration/installers/go-* + removeIfExists /imagegeneration/installers/node-* + removeIfExists /imagegeneration/installers/python-* + + removeIfExists /home/runner/work/_temp/* + removeIfExists /home/runner/work/_tool/* + removeIfExists /home/runner/work/_config/* + + - name: Show Disk Usage + shell: bash + run: | + echo "# df -h" + df -h + + echo '# docker images' + docker images || true + + echo '# du -sh /home/runner' + sudo du -sh /home/runner || true diff --git a/.github/workflows/maven-cicd-pipeline.yml b/.github/workflows/maven-cicd-pipeline.yml index d2a630eacec7..fa794ce37924 100644 --- a/.github/workflows/maven-cicd-pipeline.yml +++ b/.github/workflows/maven-cicd-pipeline.yml @@ -100,7 +100,8 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - name: Set up JDK 11 uses: actions/setup-java@v3 with: @@ -232,7 +233,8 @@ jobs: maven_args: "" } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - name: Set up JDK ${{ matrix.java.name }} uses: actions/setup-java@v3 with: @@ -292,7 +294,8 @@ jobs: maven_args: "" } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - name: Set up JDK ${{ matrix.java.name }} uses: actions/setup-java@v3 with: @@ -360,10 +363,8 @@ jobs: env: MAVEN_OPTS: -Xmx2048m steps: - - uses: actions/checkout@v3 - - name: apt clean - shell: bash - run: sudo apt-get clean + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - name: Set up JDK 11 uses: actions/setup-java@v3 with: @@ -471,10 +472,8 @@ jobs: maven_args: '"-Dit.test=MainSuite2b" -Dit.test.forkcount=1' } steps: - - uses: actions/checkout@v3 - - name: apt clean - shell: bash - run: sudo apt-get clean + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - name: Set up IT Tests ${{ matrix.java.name }} ${{ matrix.suites.name }} uses: actions/setup-java@v3 with: @@ -534,9 +533,8 @@ jobs: matrix: collection_group: [ 'category-container', 'content', 'experiment', 'graphql', 'page', 'pp', 'template', 'workflow', 'default' ] steps: - - id: fetch-core - name: Fetch Core Repo - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: ./.github/actions/cleanup-runner - run: sudo npm install --location=global newman@5.3.2 newman-reporter-htmlextra@1.23.0 - id: docker-login name: Login to GHCR @@ -604,12 +602,10 @@ jobs: runs-on: ubuntu-latest needs: [build-jdk11] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: apt clean - shell: bash - run: sudo apt-get clean + - uses: ./.github/actions/cleanup-runner - name: Set up JDK 11 uses: actions/setup-java@v3 with: @@ -647,10 +643,7 @@ jobs: needs: linux-postman-tests if: (success() || failure()) && (github.repository == 'dotCMS/core' || !endsWith(github.ref, '/master')) steps: - - id: fetch-core - name: Fetch Core Repo - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 - id: cleanup-package name: Clean up CICD packages uses: ./.github/actions/cleanup-gh-packages