From 89b0806941caf1e6bb93d696614da4be3276f33c Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 15 Jul 2024 11:23:14 +0100 Subject: [PATCH] Improve `cache-clean` action, remove `cache-rebuild` Select level of cleaning required Rebuild happens in due course, no need for a specific action. --- .github/workflows/cache-clean.yml | 32 +++++++++- .github/workflows/cache-rebuild.yml | 97 ----------------------------- Tools/ci/README.rst | 28 +++++++-- 3 files changed, 55 insertions(+), 102 deletions(-) delete mode 100644 .github/workflows/cache-rebuild.yml diff --git a/.github/workflows/cache-clean.yml b/.github/workflows/cache-clean.yml index fcb54cf00b..3ccbea4891 100644 --- a/.github/workflows/cache-clean.yml +++ b/.github/workflows/cache-clean.yml @@ -2,6 +2,16 @@ name: Cache clean on: workflow_dispatch: + inputs: + clean_opt: + description: 'Level of cleaning required' + type: choice + default: push-requests + options: + - pull-requests + - ccache + - idf-tools + - ccache+idf jobs: cleanup: @@ -12,7 +22,26 @@ jobs: gh extension install actions/gh-actions-cache echo "Fetching list of cache keys" - cacheKeys=$(gh actions-cache list -R $REPO -L 100 | grep -v develop | cut -f 1 ) + case $CLEAN_OPT in + pull-requests) + filter="-v develop" + ;; + ccache) + filter="ccache" + ;; + idf-tools) + filter="idf" + ;; + ccache+idf) + filter="ccache\|idf" + ;; + *) + echo "Unknown option '$CLEAN_OPT'" + exit 1 + ;; + esac + + cacheKeys=$(gh actions-cache list -R $REPO -L 100 | grep $filter | cut -f 1 ) echo "Deleting caches..." set +e @@ -23,3 +52,4 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} + CLEAN_OPT: ${{ inputs.clean_opt }} diff --git a/.github/workflows/cache-rebuild.yml b/.github/workflows/cache-rebuild.yml deleted file mode 100644 index 8bac555e3a..0000000000 --- a/.github/workflows/cache-rebuild.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Cache rebuild - -on: - workflow_dispatch: - inputs: - clean_all: - description: 'Clean all caches, not just esp32 ones' - default: false - -jobs: - cleanup: - runs-on: ubuntu-latest - steps: - - name: Cleanup - id: cleanup - run: | - gh extension install actions/gh-actions-cache - - echo "Fetching list of cache keys" - if [ -z "$CLEAN_ALL" ]; then - cacheKeys=$(gh actions-cache list -R "$REPO" -L 100 | cut -f 1 ) - else - cacheKeys=$(gh actions-cache list -R "$REPO" -L 100 | grep -w "idf\|esp32" | cut -f 1 ) - fi - - echo "Deleting caches..." - set +e - for cacheKey in $cacheKeys; do - gh actions-cache delete "$cacheKey" -R "$REPO" --confirm - done - echo "Done" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} - CLEAN_ALL: ${{ inputs.clean_all }} - - build: - needs: cleanup - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - idf_version: ["4.4", "5.2"] - include: - - os: ubuntu-latest - idf_version: "4.3" - - os: ubuntu-latest - idf_version: "5.0" - exclude: - - os: macos-latest - idf_version: "4.4" - - runs-on: ${{ matrix.os }} - - env: - SMING_ARCH: Esp32 - SMING_SOC: esp32 - INSTALL_IDF_VER: ${{ matrix.idf_version }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.idf_version == '4.3' && '3.8' || '3.12' }} - - - name: Configure environment - shell: pwsh - run: | - "CI_BUILD_DIR=" + (Resolve-Path ".").path >> $env:GITHUB_ENV - "SMING_HOME=" + (Resolve-Path "Sming").path >> $env:GITHUB_ENV - - - name: Fix permissions - if: matrix.os != 'windows-latest' - run: | - sudo chown $USER /opt - - - name: Install build tools for Ubuntu / MacOS - if: matrix.os != 'windows-latest' - run: | - Tools/ci/install.sh - - - name: Install build tools for Windows - if: matrix.os == 'windows-latest' - run: | - . Tools/ci/setenv.ps1 - Tools/ci/install.cmd - - - name: Cache ESP-IDF and build tools - uses: actions/cache/save@v4 - with: - path: | - /opt/esp-idf-${{ matrix.idf_version }} - /opt/esp32 - key: ${{ matrix.os }}-idf-${{ matrix.idf_version }} diff --git a/Tools/ci/README.rst b/Tools/ci/README.rst index f8e39c3281..4d330b3bb0 100644 --- a/Tools/ci/README.rst +++ b/Tools/ci/README.rst @@ -7,11 +7,31 @@ Github actions See ``.github/workflows``. Cache clean - Dispatch workflow to remove caches for pull requests, but leave those for the default (develop) branch intact. + Dispatch workflow as convenient way to clean action cache. Cleaning levels are: + + - pull-requests + Any items created by pull requests, excludes anything in develop branch. + Normally pull requests will make use of caches present in the develop branch, but if there isn't one it will create its own. This becomes redundant when merged to develop. + + Such caches should be expired automatically, but this option can be used to remove them. + + - ccache + All ccache items. Use if pull requests are taking too long to build. + + - idf-tools + All IDF tool. Use before merging to develop if IDF toolchains have been updated. + + - ccache+idf + All ccache and IDF tool caches. + + Note that cleaning can always be done locally using ``gh``:: + + gh cache list # For fork + gh cache list -R SmingHub/Sming + gh cache delete --all -R SmingHub/Sming + + etc. -Cache rebuild - Dispatch workflow to rebuild the esp32 idf/tool caches. - By default, cleans only idf/esp32 caches but has option to perform full clean. CodeQL Performs code quality analysis when develop branch is updated.