From 5ba6825cc6299bfbd2d19a5b637b5a1384615725 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Sun, 17 Sep 2023 01:27:13 +0200 Subject: [PATCH] preview based on test-webpage-build --- .github/actions/generate-metadata/action.yml | 11 +++- .github/workflows/ci.yml | 50 ++++++++++++++ .github/workflows/comment.yml | 13 ++-- .github/workflows/preview.yml | 68 -------------------- 4 files changed, 63 insertions(+), 79 deletions(-) delete mode 100644 .github/workflows/preview.yml diff --git a/.github/actions/generate-metadata/action.yml b/.github/actions/generate-metadata/action.yml index 69564821..024676ca 100644 --- a/.github/actions/generate-metadata/action.yml +++ b/.github/actions/generate-metadata/action.yml @@ -7,30 +7,35 @@ inputs: description: GitHub token required: true type: string + cache: + description: use caching or not + required: true + type: boolean runs: using: composite steps: - name: Restore cached Plugins + if: inputs.cache == true 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' + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' || inputs.cache id: fetch_metadata env: GITHUB_TOKEN: ${{ inputs.gh_token }} run: aiida-registry fetch shell: bash - name: Check plugins installation - if: steps.cache-plugins-restore.outputs.cache-hit != 'true' + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' || inputs.cache # This step will attach plugin installation inforamtion to the metadata, e.g. if the plugin can be installed or not run: aiida-registry test-install shell: bash - name: Cache plugins metadata - if: steps.cache-plugins-restore.outputs.cache-hit != 'true' + if: steps.cache-plugins-restore.outputs.cache-hit != 'true' || inputs.cache id: cache-plugins-save uses: actions/cache/save@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3d175d4..c0765cbb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,12 +53,62 @@ jobs: - name: Generate metadata uses: ./.github/actions/generate-metadata + with: + gh_token: ${{ secrets.GITHUB_TOKEN }} + cache: true + + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + - name: Install npm dependencies and build + run: | + echo $VITE_PR_PREVIEW_PATH + npm install + npm run build + working-directory: ./aiida-registry-app + + preview: + needs: [test-webpage-build] + runs-on: ubuntu-latest + strategy: + fail-fast: false + timeout-minutes: 60 + env: + COMMIT_AUTHOR: Deploy Action + COMMIT_AUTHOR_EMAIL: action@github.com + VITE_PR_PREVIEW_PATH: "/aiida-registry/pr-preview/pr-${{ github.event.number }}/" + + # This is a CI job that checks if the webpage can be built + # We use the plugins metadata from caching since we don't want to + # fetch it twice and it is not essential for this job to have + # the latest generated metadata + steps: + - name: Checkout Repo ⚡️ + uses: actions/checkout@v3 + - name: Create dev environment + uses: ./.github/actions/create-dev-env + + - name: Generate metadata + uses: ./.github/actions/generate-metadata + with: + gh_token: ${{ secrets.GITHUB_TOKEN }} + cache: false - uses: actions/setup-node@v3 with: node-version: '18.x' - name: Install npm dependencies and build run: | + echo $VITE_PR_PREVIEW_PATH npm install npm run build working-directory: ./aiida-registry-app + + - name: Deploy preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./aiida-registry-app/dist + preview-branch: gh-pages + umbrella-dir: pr-preview + action: auto + custom-url: diff --git a/.github/workflows/comment.yml b/.github/workflows/comment.yml index 9c951d58..58d9f0fb 100644 --- a/.github/workflows/comment.yml +++ b/.github/workflows/comment.yml @@ -20,14 +20,11 @@ jobs: - name: Create dev environment uses: ./.github/actions/create-dev-env - - name: fetch metadata - id: fetch_metadata - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: aiida-registry fetch - - name: Check plugins installation - # This step will attach plugin installation inforamtion to the metadata, e.g. if the plugin can be installed or not - run: aiida-registry test-install + - name: Generate metadata + uses: ./.github/actions/generate-metadata + with: + gh_token: ${{ secrets.GITHUB_TOKEN }} + cache: false - name: Create commit comment if: steps.fetch_metadata.outputs.error diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index 81243890..00000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Deploy PR previews - -on: - pull_request: - types: - - opened - - reopened - - synchronize - - closed - workflow_run: - workflows: ["CI"] - types: - - completed - -# 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: - runs-on: ubuntu-latest - strategy: - fail-fast: false - timeout-minutes: 60 - env: - COMMIT_AUTHOR: Deploy Action - COMMIT_AUTHOR_EMAIL: action@github.com - VITE_PR_PREVIEW_PATH: "/aiida-registry/pr-preview/pr-${{ github.event.number }}/" - steps: - - name: Checkout Repo ⚡️ - uses: actions/checkout@v3 - - name: Create dev environment - uses: ./.github/actions/create-dev-env - - - name: fetch metadata - env: - # Use the GITHUB_TOKEN for github API calls - # otherwise the rate limit will be exceeded - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: aiida-registry fetch - - name: Check plugins installation - # This step will attach plugin installation inforamtion to the metadata, e.g. if the plugin can be installed or not - run: aiida-registry test-install - - - name: Move JSON file to the React project - run: | - cp plugins_metadata.json aiida-registry-app/src/ - cp plugins_metadata.json aiida-registry-app/dist/ - - uses: actions/setup-node@v3 - with: - node-version: '18.x' - - name: Install npm dependencies and build - run: | - echo $VITE_PR_PREVIEW_PATH - npm install - npm run build - working-directory: ./aiida-registry-app - - - name: Deploy preview - uses: rossjrw/pr-preview-action@v1 - with: - source-dir: ./aiida-registry-app/dist - preview-branch: gh-pages - umbrella-dir: pr-preview - action: auto - custom-url: