Skip to content

Commit

Permalink
add cache with os tag and auto chache clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW committed Mar 1, 2025
1 parent 777e782 commit efadc31
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 64 deletions.
48 changes: 48 additions & 0 deletions .github/actions/cache-clean/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: cache-clean
description: 'steps to clean the old caches before creating new ones'

inputs:
GH_TOKEN:
description: 'Github token for the cache cleaning'
required: true

runs:
using: composite
steps:
- name: Debug gh CLI
run: |
gh --version
gh auth status
gh extension list
shell: bash

- name: Update GitHub CLI
run: sudo apt-get install gh
shell: bash

- name: Install and Verify gh-actions-cache Extension
run: |
gh extension install actions/gh-actions-cache || exit 1
gh extension list | grep gh-actions-cache || (echo "Extension installation failed" && exit 1)
shell: bash

- name: Test actions-cache list
run: |
gh actions-cache list -R R3BRootGroup/R3BRoot -L 5 || echo "Failed to list caches"
shell: bash

- name: Cleanup
run: |
echo "Fetching list of cache keys"
cacheKeys=$(gh actions-cache list -R R3BRootGroup/R3BRoot -L 100 | cut -f 1 | grep -v 'build-deps') || exit 1
set +e
echo "Deleting old caches..."
for cacheKey in $cacheKeys
do
gh actions-cache delete $cacheKey -R R3BRootGroup/R3BRoot --confirm || echo "Failed to delete $cacheKey"
done
echo "Done"
shell: bash
env:
GH_TOKEN: ${{ inputs.GH_TOKEN }}
8 changes: 2 additions & 6 deletions .github/actions/cache-save/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: cache-save
description: 'steps to cache R3BRoot and ucesb'

inputs:
r3b-dev-key:
description: 'key for r3b dev cache'
required: false
default: ''
cache-name:
description: 'repository name'
required: true
Expand All @@ -20,12 +16,12 @@ runs:
path: |
${{ env.UCESB_DIR }}
${{ github.workspace }}/build/_deps
key: build-deps
key: build-deps-${{ matrix.os }}

- name: cache r3b
if: matrix.save != 'false'
id: cache-r3b
uses: actions/cache/save@v4
with:
path: .ccache
key: r3b-build-${{ inputs.cache-name }}-${{ inputs.r3b-dev-key }}
key: r3b-build-${{ inputs.cache-name }}-${{ matrix.os }}
11 changes: 4 additions & 7 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: install-deps
description: 'steps to install deps'

inputs:
r3b-dev-key:
description: 'key for r3b dev cache'
required: false
default: ''
cache-name:
description: 'repository name'
required: false
Expand All @@ -22,17 +18,18 @@ runs:
path: |
${{ env.UCESB_DIR }}
${{ github.workspace }}/build/_deps
key: build-deps
key: build-deps-${{ matrix.os }}

- name: cache r3b
if: inputs.cache-name != 'false' && github.event_name == 'pull_request'
id: cache-r3b
uses: actions/cache/restore@v4
with:
path: .ccache
key: r3b-build-${{ inputs.cache-name }}-${{ inputs.r3b-dev-key }}
key: r3b-build-${{ inputs.cache-name }}-${{ matrix.os }}
restore-keys: |
r3b-build-${{ inputs.cache-name }}-
r3b-build-${{ inputs.cache-name }}-${{ matrix.os }}
r3b-build-
r3b-build-
- name: build ucesb
Expand Down
49 changes: 0 additions & 49 deletions .github/workflows/cleanup_cache.yml

This file was deleted.

15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ name: CI-CD
on:
# Triggers the workflow in case of a push or pull request events
push:
branches: [ dev ]
branches: [ dev, edwin_fix_ci ]
pull_request:
branches: [ dev ]

Expand All @@ -61,7 +61,19 @@ on:
# parallelly. As has been specified above, all the jobs below will be
# triggered either by a pull request or a merge of a pull request.
jobs:
# The job to clean the old caches before new caches are created when the PR is merged.
cache-cleanup:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: clean-cache
uses: './.github/actions/pre-build'
with:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# The job to run the main CI pipelines
build-test:
needs: cache-cleanup
runs-on: ubuntu-latest
# A strategy matrix gives different settings separately to different jobs
# which are run parallelly.
Expand Down Expand Up @@ -177,7 +189,6 @@ jobs:
uses: './.github/actions/install-deps'
with:
cache-name: ${{ matrix.cache }}
r3b-dev-key: ${{ env.cacheSHA }}

# A self-defined composite action for the cmake configuration and build
# of r3broot (along with necessary dep repos).
Expand Down

0 comments on commit efadc31

Please sign in to comment.