From 03c525bed49ff0d706a1177b907c08a6e38eaa4e Mon Sep 17 00:00:00 2001 From: Ahmed Basem Date: Fri, 1 Sep 2023 13:33:32 +0300 Subject: [PATCH] Cache plugins data. (#264) This includes attempts to speed up the workflow and limit the API calls to github by caching plugins data. In preview.yml remove the fetch step and use the data that resides in gh-pages instead. In ci.yml, the webpage created a cache for plugin data and restored it for each step. Setup concurrency to the workflow. --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++++++ .github/workflows/preview.yml | 20 ++++++++++++-------- .github/workflows/webpage.yml | 17 +++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eefee2a7..902d5d14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,12 @@ name: CI on: [push, pull_request] +# https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + # only cancel in-progress jobs or runs for the current workflow - matches against branch & tags + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: pre-commit: @@ -38,11 +44,30 @@ jobs: run: pip install --upgrade wheel setuptools - name: Install run: pip install -e . -v + + - name: Restore cached Plugins + id: cache-plugins-restore + uses: actions/cache/restore@v3 + with: + path: | + plugins_metadata.json + key: plugins_metadata + - name: fetch metadata + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' id: fetch_metadata env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: aiida-registry fetch + + - name: Cache plugins metadata + id: cache-plugins-save + uses: actions/cache/save@v3 + with: + path: | + plugins_metadata.json + key: ${{ steps.cache-plugins-restore.outputs.cache-primary-key }} + - name: Move JSON file to the React project run: | mv plugins_metadata.json aiida-registry-app/src/ @@ -78,7 +103,17 @@ jobs: run: pip install --upgrade pip - name: Install run: pip install -e . -v + - name: Restore cached Plugins + id: cache-plugins-restore + uses: actions/cache/restore@v3 + with: + path: | + plugins_metadata.json + key: plugins_metadata + - name: fetch metadata + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' + id: fetch_metadata env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: aiida-registry fetch diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 0689e111..5e04ad05 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -8,7 +8,11 @@ on: - synchronize - closed -concurrency: preview-${{ github.ref }} +# https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + # only cancel in-progress jobs or runs for the current workflow - matches against branch & tags + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: deploy-preview: @@ -27,13 +31,13 @@ jobs: run: pip install --upgrade wheel setuptools - name: Install run: pip install -e . -v - - name: fetch metadata - id: fetch_metadata - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: aiida-registry fetch - - name: Get entry points data - run: aiida-registry test-install + - name: Get cloned data from gh-pages + run: | + git remote set-url origin https://github.com/aiidateam/aiida-registry.git + git fetch origin gh-pages + git checkout origin/gh-pages plugins_metadata.json || true + + - name: Move JSON file to the React project run: | mv plugins_metadata.json aiida-registry-app/src/ diff --git a/.github/workflows/webpage.yml b/.github/workflows/webpage.yml index 276b30b2..b4971ce0 100644 --- a/.github/workflows/webpage.yml +++ b/.github/workflows/webpage.yml @@ -11,6 +11,12 @@ on: branches: - master +# https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + # only cancel in-progress jobs or runs for the current workflow - matches against branch & tags + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: webpage: if: github.repository == 'aiidateam/aiida-registry' @@ -36,11 +42,22 @@ jobs: git fetch origin gh-pages git checkout origin/gh-pages plugins_metadata.json || true mv plugins_metadata.json cloned_plugins_metadata.json || true + + - name: Restore cached Plugins + id: cache-plugins-restore + uses: actions/cache/restore@v3 + with: + path: | + plugins_metadata.json + key: plugins_metadata + - name: fetch metadata + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' id: fetch_metadata env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: aiida-registry fetch + - name: Get entry points data run: aiida-registry test-install - name: Move the JSON file to the React directory