diff --git a/.github/workflows/selfdrive_tests.yaml b/.github/workflows/selfdrive_tests.yaml index 991ce74ca9..143f831995 100644 --- a/.github/workflows/selfdrive_tests.yaml +++ b/.github/workflows/selfdrive_tests.yaml @@ -82,9 +82,8 @@ jobs: run: ${{ env.RUN }} "scons -j$(nproc) --extras && release/check-dirty.sh" - name: Cleanup scons cache and rebuild timeout-minutes: ${{ ((steps.restore-scons-cache.outputs.cache-hit == 'true') && 2 || 30) }} # allow more time when we missed the scons cache - run: | - ${{ env.RUN }} "rm -rf /tmp/scons_cache/* && \ - scons -j$(nproc) --cache-populate" + if: github.ref == 'refs/heads/master' + run: ${{ env.RUN }} "release/clean-cache.sh" - name: Save scons cache uses: actions/cache/save@v3 if: github.ref == 'refs/heads/master' @@ -159,9 +158,8 @@ jobs: - name: Pre Cache - Cleanup scons cache if: github.ref == 'refs/heads/master' run: | - rm -rf /tmp/scons_cache/* eval "$(pyenv init --path)" - poetry run scons -j$(nproc) --cache-populate + poetry run release/clean-cache.sh - name: Save scons cache id: scons-save-cache uses: actions/cache/save@v3 diff --git a/release/clean-cache.sh b/release/clean-cache.sh new file mode 100755 index 0000000000..ec63ee95b1 --- /dev/null +++ b/release/clean-cache.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +# delete outdated moc files +scons --dry-run --taskmastertrace /tmp/tasktrace.log >/dev/null +MOC_EXISTING_PROD="$(find /tmp/scons_cache/moc_files -type f | sort)" +MOC_CURRENT_PROD="$(egrep -o "'[^']*moc_files[^']*'" /tmp/tasktrace.log | sed "s/'//g" | sort | uniq)" +MOC_JUNK="$(comm -23 <(echo "$MOC_EXISTING_PROD") <(echo "$MOC_CURRENT_PROD"))" +echo "$MOC_JUNK" | xargs -I{} rm {} +rm /tmp/tasktrace.log + +# delete cache except for moc files +rm -rf $(find /tmp/scons_cache -maxdepth 1 ! -name moc_files ! -name scons_cache) + +# repopulate cache +scons --dry-run --cache-populate >/dev/null