diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 246128df..53104039 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -32,12 +32,6 @@ runs: run: python .github/assistant.py set-oldest-versions shell: bash - - run: python -c "import time ; days = time.time() / 60 / 60 / 24 ; print(f'TIME_PERIOD={int(days / ${{ inputs.interval }})}')" >> $GITHUB_ENV - if: inputs.requires == 'latest' - shell: bash - - # Note: This uses an internal pip API and may not always work - # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow - name: Determine caches env: PWD: $(pwd) @@ -49,13 +43,13 @@ runs: uses: actions/cache@v3 with: path: $PIP_CACHE_DIR - key: ${{ runner.os }}-py${{ inputs.python-version }}-pip-td${{ env.TIME_PERIOD }}-${{ inputs.offset }}-${{ hashFiles('requirements.txt') }} - restore-keys: ${{ runner.os }}-py${{ inputs.python-version }}-pip-td${{ env.TIME_PERIOD }}-${{ inputs.offset }}- + key: ${{ runner.os }}-py${{ inputs.python-version }}-pip-${{ inputs.offset }}-${{ hashFiles('requirements.txt') }} + restore-keys: ${{ runner.os }}-py${{ inputs.python-version }}-pip-${{ inputs.offset }}- - name: Cache conda uses: actions/cache@v3 if: runner.os == 'Linux' with: path: ~/conda_pkgs_dir - key: py${{ inputs.python-version }}-conda-td${{ env.TIME_PERIOD }}-${{ inputs.offset }} - restore-keys: py${{ inputs.python-version }}-conda-td${{ env.TIME_PERIOD }}-${{ inputs.offset }} + key: py${{ inputs.python-version }}-conda-${{ inputs.offset }} + restore-keys: py${{ inputs.python-version }}-conda-${{ inputs.offset }} diff --git a/.github/workflows/clear-cache.yml b/.github/workflows/clear-cache.yml new file mode 100644 index 00000000..aff5e707 --- /dev/null +++ b/.github/workflows/clear-cache.yml @@ -0,0 +1,39 @@ +name: Clear cache flow + +on: + workflow_call: + inputs: + pattern: + description: 'string to grep cache keys with' + required: true + type: string + +jobs: + clear-cache: + runs-on: ubuntu-latest + + steps: + - name: Get the list of cache keys + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/caches --paginate --jq ".actions_caches[].key" | sort | uniq > cache_keys.txt && cat cache_keys.txt || echo "no cache keys found with the pattern" + + - name: Filter cache keys + run: | + grep -E ${{ inputs.pattern }} cache_keys.txt > cache_keys_to_remove.txt && cat cache_keys_to_remove.txt || echo "no cache keys found with the pattern" + + - name: Remove caches + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo created_at last_accessed_at ref key size_in_bytes + for key in $(cat cache_keys_to_remove.txt); do + gh api --method DELETE -H "Accept: application/vnd.github+json" "/repos/${{ github.repository }}/actions/caches?key=${key}" --jq '.actions_caches[] | [.created_at, .last_accessed_at, .ref, .key, .size_in_bytes] | join(" ")' + done + + - name: Show the list of remaining caches + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/caches --paginate --jq ".actions_caches[].key" | sort | uniq diff --git a/.github/workflows/schedule-clear-cache.yml b/.github/workflows/schedule-clear-cache.yml new file mode 100644 index 00000000..cdc7ab96 --- /dev/null +++ b/.github/workflows/schedule-clear-cache.yml @@ -0,0 +1,13 @@ +name: Clear cache weekly + +on: + schedule: + # on Sundays + - cron: "0 0 * * 0" + +jobs: + clear-cache: + if: ${{ github.repository_owner == 'Lightning-AI' }} + uses: ./.github/workflows/clear-cache.yml + with: + pattern: 'pip|conda'