Skip to content

Commit 67c7b3e

Browse files
authored
Github Actions - Cache Fix (#8247)
* Clean up caches Actions * Fix Github Actions
1 parent b1b33b0 commit 67c7b3e

File tree

3 files changed

+165
-77
lines changed

3 files changed

+165
-77
lines changed
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Cleanup Caches by Cron
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 * * *' # Runs daily at 03:00 UTC
6+
workflow_dispatch: # Allows manual triggering if needed
7+
8+
permissions:
9+
contents: write
10+
11+
12+
jobs:
13+
cleanup:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Set Up GitHub CLI
17+
run: |
18+
sudo apt-get update && sudo apt-get install -y gh
19+
gh extension install actions/gh-actions-cache || echo "Extension already installed"
20+
21+
- name: Cleanup Caches
22+
env:
23+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
24+
run: |
25+
REPO=${{ github.repository }}
26+
BRANCH="master" # Only focus on the master branch
27+
28+
echo "Fetching list of cache keys for branch: $BRANCH"
29+
cacheKeysForMaster=$(gh actions-cache list -R $REPO -B $BRANCH --json key | jq -r '.[].key')
30+
31+
if [ -z "$cacheKeysForMaster" ]; then
32+
echo "No caches found for branch: $BRANCH"
33+
exit 0
34+
fi
35+
36+
echo "Deleting caches..."
37+
for cacheKey in $cacheKeysForMaster; do
38+
echo "Deleting cache: $cacheKey"
39+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
40+
done
41+
echo "Cleanup completed."
42+
43+
- name: Verify Remaining Caches
44+
run: |
45+
echo "Checking for remaining caches in branch: $BRANCH"
46+
remainingCaches=$(gh actions-cache list -R ${{ github.repository }} -B $BRANCH --json key | jq -r '.[].key')
47+
48+
if [ -z "$remainingCaches" ]; then
49+
echo "All caches successfully cleared."
50+
else
51+
echo "Remaining caches detected:"
52+
echo "$remainingCaches"
53+
exit 1
54+
fi
55+
env:
56+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}

.github/workflows/clean-up-cache.yml

+44-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: cleanup caches by a branch
1+
name: Cleanup Caches by Branch
22
on:
33
pull_request:
44
types:
@@ -14,20 +14,52 @@ jobs:
1414
steps:
1515
- name: Check out code
1616
uses: actions/checkout@v4
17-
- name: Cleanup
17+
- name: Setup GitHub CLI
18+
run: |
19+
# Ensure the latest version of GitHub CLI is installed
20+
sudo apt-get update && sudo apt-get install -y gh
21+
# Install the actions-cache extension
22+
gh extension install actions/gh-actions-cache || echo "Extension already installed"
23+
24+
- name: Check Token Permissions
25+
run: gh auth status
26+
env:
27+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
28+
29+
- name: Cleanup Caches
1830
run: |
19-
gh extension install actions/gh-actions-cache
2031
REPO=${{ github.repository }}
32+
# Adjust branch reference if necessary
2133
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
22-
echo "Fetching list of cache key"
23-
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
24-
## Setting this to not fail the workflow while deleting cache keys.
25-
set +e
34+
35+
echo "Fetching list of cache keys for branch: $BRANCH"
36+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH --json key | jq -r '.[].key')
37+
38+
if [ -z "$cacheKeysForPR" ]; then
39+
echo "No caches found for branch: $BRANCH"
40+
exit 0
41+
fi
42+
2643
echo "Deleting caches..."
27-
for cacheKey in $cacheKeysForPR
28-
do
29-
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
44+
for cacheKey in $cacheKeysForPR; do
45+
echo "Deleting cache: $cacheKey"
46+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
3047
done
31-
echo "Done"
48+
echo "Cleanup completed."
49+
env:
50+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
51+
52+
- name: Verify Remaining Caches
53+
run: |
54+
echo "Checking for remaining caches in branch: $BRANCH"
55+
remainingCaches=$(gh actions-cache list -R ${{ github.repository }} -B $BRANCH --json key | jq -r '.[].key')
56+
57+
if [ -z "$remainingCaches" ]; then
58+
echo "All caches successfully cleared."
59+
else
60+
echo "Remaining caches detected:"
61+
echo "$remainingCaches"
62+
exit 1
63+
fi
3264
env:
33-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
GH_TOKEN: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}

.github/workflows/of.yml

+65-65
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ jobs:
3333
- uses: actions/checkout@v4
3434
- name: Docker Step
3535
run: "docker run -di --name emscripten -v $PWD:/src emscripten/emsdk:3.1.74 bash"
36-
- name: Determine Release
37-
id: vars
38-
shell: bash
39-
run: |
40-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
41-
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
42-
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
43-
echo "RELEASE=nightly" >> $GITHUB_ENV
44-
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
45-
echo "RELEASE=latest" >> $GITHUB_ENV
46-
else
47-
echo "RELEASE=latest" >> $GITHUB_ENV
48-
fi
36+
# - name: Determine Release
37+
# id: vars
38+
# shell: bash
39+
# run: |
40+
# if [[ "${{ github.ref }}" == refs/tags/* ]]; then
41+
# echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
42+
# elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
43+
# echo "RELEASE=nightly" >> $GITHUB_ENV
44+
# elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
45+
# echo "RELEASE=latest" >> $GITHUB_ENV
46+
# else
47+
# echo "RELEASE=latest" >> $GITHUB_ENV
48+
# fi
4949
- name: Download libs
5050
run: ./scripts/$TARGET/download_libs.sh -t $RELEASE
5151
- name: Install dependencies
@@ -131,19 +131,19 @@ jobs:
131131
install: >-
132132
git
133133
unzip
134-
- name: Determine Release
135-
id: vars
136-
shell: bash
137-
run: |
138-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
139-
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
140-
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
141-
echo "RELEASE=nightly" >> $GITHUB_ENV
142-
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
143-
echo "RELEASE=latest" >> $GITHUB_ENV
144-
else
145-
echo "RELEASE=latest" >> $GITHUB_ENV
146-
fi
134+
# - name: Determine Release
135+
# id: vars
136+
# shell: bash
137+
# run: |
138+
# if [[ "${{ github.ref }}" == refs/tags/* ]]; then
139+
# echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
140+
# elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
141+
# echo "RELEASE=nightly" >> $GITHUB_ENV
142+
# elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
143+
# echo "RELEASE=latest" >> $GITHUB_ENV
144+
# else
145+
# echo "RELEASE=latest" >> $GITHUB_ENV
146+
# fi
147147
- name: Install dependencies
148148
shell: msys2 {0}
149149
run: ./scripts/ci/vs/install.sh
@@ -257,19 +257,19 @@ jobs:
257257
uses: hendrikmuhs/ccache-action@v1.2.14
258258
with:
259259
key: ${{ matrix.cfg.libs }}
260-
- name: Determine Release
261-
id: vars
262-
shell: bash
263-
run: |
264-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
265-
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
266-
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
267-
echo "RELEASE=nightly" >> $GITHUB_ENV
268-
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
269-
echo "RELEASE=latest" >> $GITHUB_ENV
270-
else
271-
echo "RELEASE=latest" >> $GITHUB_ENV
272-
fi
260+
# - name: Determine Release
261+
# id: vars
262+
# shell: bash
263+
# run: |
264+
# if [[ "${{ github.ref }}" == refs/tags/* ]]; then
265+
# echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
266+
# elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
267+
# echo "RELEASE=nightly" >> $GITHUB_ENV
268+
# elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
269+
# echo "RELEASE=latest" >> $GITHUB_ENV
270+
# else
271+
# echo "RELEASE=latest" >> $GITHUB_ENV
272+
# fi
273273
- name: Download libs
274274
run: ./scripts/linux/download_libs.sh -t $RELEASE -a ${{matrix.cfg.libs}}
275275
- name: Install dependencies
@@ -297,19 +297,19 @@ jobs:
297297
uses: hendrikmuhs/ccache-action@v1.2.14
298298
with:
299299
key: ${{ matrix.cfg.target }}-${{ matrix.cfg.libs }}
300-
- name: Determine Release
301-
id: vars
302-
shell: bash
303-
run: |
304-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
305-
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
306-
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
307-
echo "RELEASE=nightly" >> $GITHUB_ENV
308-
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
309-
echo "RELEASE=latest" >> $GITHUB_ENV
310-
else
311-
echo "RELEASE=latest" >> $GITHUB_ENV
312-
fi
300+
# - name: Determine Release
301+
# id: vars
302+
# shell: bash
303+
# run: |
304+
# if [[ "${{ github.ref }}" == refs/tags/* ]]; then
305+
# echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
306+
# elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
307+
# echo "RELEASE=nightly" >> $GITHUB_ENV
308+
# elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
309+
# echo "RELEASE=latest" >> $GITHUB_ENV
310+
# else
311+
# echo "RELEASE=latest" >> $GITHUB_ENV
312+
# fi
313313
- name: Download libs
314314
run: ./scripts/${{matrix.cfg.libs}}/download_libs.sh -t $RELEASE
315315
- name: install
@@ -340,19 +340,19 @@ jobs:
340340
with:
341341
packages: aptitude aptitude-common libboost-iostreams1.83.0 libcwidget4 libsigc++-2.0-0v5 libxapian30 fonts-wine{a} libasound2-plugins{a} libcapi20-3t64{a} libosmesa6{a} libpcsclite1{a} libspeexdsp1{a} libwine{a} libxkbregistry0{a} libz-mingw-w64{a} wine{a} wine64 wget2 make libjack-jackd2-0 libjack-jackd2-dev freeglut3-dev libasound2-dev libxmu-dev libxxf86vm-dev g++ libgl1-mesa-dev libglu1-mesa-dev libraw1394-dev libudev-dev libdrm-dev libglew-dev libopenal-dev libsndfile1-dev libfreeimage-dev libcairo2-dev libfreetype6-dev libpulse-dev libusb-1.0-0-dev libgtk2.0-dev libopencv-dev libassimp-dev librtaudio-dev gdb libglfw3-dev liburiparser-dev libpugixml-dev libgconf-2-4 libgtk2.0-0 libpoco-dev libxcursor-dev libxi-dev libxinerama-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-libav gstreamer1.0-pulseaudio gstreamer1.0-x gstreamer1.0-plugins-bad gstreamer1.0-alsa gstreamer1.0-plugins-base gstreamer1.0-plugins-good
342342
version: 1.0
343-
- name: Determine Release
344-
id: vars
345-
shell: bash
346-
run: |
347-
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
348-
echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
349-
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
350-
echo "RELEASE=nightly" >> $GITHUB_ENV
351-
elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
352-
echo "RELEASE=latest" >> $GITHUB_ENV
353-
else
354-
echo "RELEASE=latest" >> $GITHUB_ENV
355-
fi
343+
# - name: Determine Release
344+
# id: vars
345+
# shell: bash
346+
# run: |
347+
# if [[ "${{ github.ref }}" == refs/tags/* ]]; then
348+
# echo "RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV
349+
# elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
350+
# echo "RELEASE=nightly" >> $GITHUB_ENV
351+
# elif [[ "${{ github.ref }}" == "refs/heads/bleeding" ]]; then
352+
# echo "RELEASE=latest" >> $GITHUB_ENV
353+
# else
354+
# echo "RELEASE=latest" >> $GITHUB_ENV
355+
# fi
356356
- uses: actions/checkout@v4
357357
- name: ccache
358358
uses: hendrikmuhs/ccache-action@v1.2.14

0 commit comments

Comments
 (0)