diff --git a/.github/actions/cache-clean/action.yml b/.github/actions/cache-clean/action.yml new file mode 100644 index 000000000..5507fb967 --- /dev/null +++ b/.github/actions/cache-clean/action.yml @@ -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 }} diff --git a/.github/actions/cache-save/action.yml b/.github/actions/cache-save/action.yml index 874c7fcf1..dc3527493 100644 --- a/.github/actions/cache-save/action.yml +++ b/.github/actions/cache-save/action.yml @@ -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 @@ -20,7 +16,7 @@ runs: path: | ${{ env.UCESB_DIR }} ${{ github.workspace }}/build/_deps - key: build-deps + key: build-deps-${{ matrix.os }} - name: cache r3b if: matrix.save != 'false' @@ -28,4 +24,4 @@ runs: 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 }} diff --git a/.github/actions/install-deps/action.yml b/.github/actions/install-deps/action.yml index dbd40ef3d..db10de801 100644 --- a/.github/actions/install-deps/action.yml +++ b/.github/actions/install-deps/action.yml @@ -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 @@ -22,7 +18,7 @@ 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' @@ -30,9 +26,10 @@ runs: 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 diff --git a/.github/workflows/cleanup_cache.yml b/.github/workflows/cleanup_cache.yml deleted file mode 100644 index fda55d0fc..000000000 --- a/.github/workflows/cleanup_cache.yml +++ /dev/null @@ -1,49 +0,0 @@ -# -# SPDX-License-Identifier: LGPL-3.0-or-later - -name: Cleanup old caches - -on: - schedule: - - cron: '0 0 1 */2 *' - -jobs: - cleanup: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Debug gh CLI - run: | - gh --version - gh auth status - gh extension list - - - name: Update GitHub CLI - run: sudo apt-get install gh - - - 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) - - - name: Test actions-cache list - run: | - gh actions-cache list -R R3BRootGroup/R3BRoot -L 5 || echo "Failed to list caches" - - - 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" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fa7c171f..0cce6a22a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 ] @@ -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. @@ -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).