Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving cache management #2068

Merged
merged 4 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/cache_cleaner.yml
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: cleanup caches by a branch
on:
workflow_dispatch:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup PR caches
if: github.event_name != 'workflow_dispatch'
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm && echo "Deleting cache with key: $cacheKey"
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cleanup by workflow dispatch
if: github.event_name == 'workflow_dispatch'
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm && echo "Deleting cache with key: $cacheKey"
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 2 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ env:
# You should go up in number, if you go down (or repeat a previous value)
# you might end up reusing a previous cache if it haven't been deleted already.
# It applies 7 days retention policy by default.
RESET_PIP_CACHE: 0
RESET_EXAMPLES_CACHE: 0
RESET_DOC_BUILD_CACHE: 0
RESET_AUTOSUMMARY_CACHE: 0
Expand Down Expand Up @@ -100,21 +99,14 @@ jobs:
- name: "Setup Python"
uses: actions/setup-python@v4
with:
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
cache: 'pip'
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: "Install OS packages"
run: |
sudo apt update
sudo apt install zip pandoc libgl1-mesa-glx xvfb texlive-latex-extra latexmk graphviz

- name: "Cache pip"
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-v${{ env.RESET_PIP_CACHE }}-Linux-${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
Python-v${{ env.RESET_PIP_CACHE }}-Linux-${{ env.MAIN_PYTHON_VERSION }}

- name: "Test virtual framebuffer"
run: |
pip install -r .ci/requirements_test_xvfb.txt
Expand Down Expand Up @@ -288,21 +280,14 @@ jobs:
- name: "Setup Python"
uses: actions/setup-python@v4
with:
cache: 'pip'
germa89 marked this conversation as resolved.
Show resolved Hide resolved
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: "Install os packages"
run: |
sudo apt update
sudo apt install libgl1-mesa-glx xvfb

- name: "Cache pip"
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-v${{ env.RESET_PIP_CACHE }}-Linux-${{ env.MAIN_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
Python-v${{ env.RESET_PIP_CACHE }}-Linux-${{ env.MAIN_PYTHON_VERSION }}

- name: "Test virtual framebuffer"
run: |
pip install -r .ci/requirements_test_xvfb.txt
Expand Down