From a596803a4fb7cc58dd295923638c09790fd70479 Mon Sep 17 00:00:00 2001 From: Lukas Mertens Date: Tue, 23 Apr 2024 11:13:28 +0200 Subject: [PATCH] ci: reusable setup + read node version from nvmrc Closes #145 Addresses the following discussions: - https://github.com/EVerest/everest-admin-panel/pull/148#discussion_r1574941800 - https://github.com/EVerest/everest-admin-panel/pull/148#discussion_r1574953991 Signed-off-by: Lukas Mertens commit-id:9b48f5ae --- .github/actions/setup-node/action.yml | 39 +++++++++++++++++++++++++++ .github/workflows/checks.yml | 2 +- .github/workflows/deploy.yml | 26 +++--------------- .github/workflows/e2e-tests.yml | 7 +++-- .github/workflows/package.yml | 26 +++--------------- .github/workflows/shrinkwrap.yml | 14 ++++++---- .github/workflows/unit-tests.yml | 26 +++--------------- 7 files changed, 64 insertions(+), 76 deletions(-) create mode 100644 .github/actions/setup-node/action.yml diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 00000000..d09842cc --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest + +name: Setup Node and pnpm +description: "Setups node + pnpm" + +inputs: + pnpm-version: + description: "pnpm version to install" + default: "8" + +outputs: + pnpm-version: + description: "The pnpm version that was installed" + value: ${{ inputs.pnpm-version }} + +runs: + using: "composite" + steps: + - uses: pnpm/action-setup@v2 + with: + version: ${{ inputs.pnpm-version }} + + - name: Read .nvmrc + id: nvmrc + shell: bash + run: echo version=$(cat .nvmrc) >> "$GITHUB_OUTPUT" + + - name: Setup Node.js ${{ steps.nvmrc.outputs.version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ steps.nvmrc.outputs.version }} + cache: 'pnpm' + cache-dependency-path: | + pnpm-lock.yaml + + - name: install dependencies + shell: bash + run: pnpm install diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 08484e63..7602e220 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -13,7 +13,7 @@ jobs: check_license_headers: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Check License Header uses: apache/skywalking-eyes/header@main diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3063ab6d..20bbc798 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,29 +20,11 @@ jobs: env: SUBDIR: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'main' }} steps: - - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - name: Setup node + pnpm install + uses: ./.github/actions/setup-node with: - node-version: '18.x' - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install + pnpm-version: 9 - name: Build run: pnpm build:pages - uses: ahmadnassri/action-workflow-queue@v1 # we have to ensure that no other deployment is running diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f86412ce..9f48978f 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -19,11 +19,10 @@ jobs: browser: ['electron', 'firefox'] steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v3 - name: Install pnpm + - name: Setup node + pnpm install + uses: ./.github/actions/setup-node with: - version: 8 - run_install: false + pnpm-version: 9 - name: Run Cypress Tests uses: cypress-io/github-action@v6 with: diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index f92b2cbf..259828eb 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -19,29 +19,11 @@ jobs: package: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - name: Setup node + pnpm install + uses: ./.github/actions/setup-node with: - node-version: '18.x' - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install + pnpm-version: 9 - name: Build run: pnpm build - name: Tar diff --git a/.github/workflows/shrinkwrap.yml b/.github/workflows/shrinkwrap.yml index 90e9d075..0f1a8590 100644 --- a/.github/workflows/shrinkwrap.yml +++ b/.github/workflows/shrinkwrap.yml @@ -14,13 +14,17 @@ jobs: create-shrinkwrap: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v3 + - name: Read .nvmrc + id: nvmrc + shell: bash + run: echo version=$(cat .nvmrc) >> "$GITHUB_OUTPUT" + + - name: Setup Node.js ${{ steps.nvmrc.outputs.version }} + uses: actions/setup-node@v4 with: - node-version: '20' + node-version: ${{ steps.nvmrc.outputs.version }} - name: Generate npm-shrinkwrap.json run: | diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ad04a076..f2a02f49 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,29 +19,11 @@ jobs: package: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - name: Setup node + pnpm install + uses: ./.github/actions/setup-node with: - node-version: '18.x' - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies - run: pnpm install + pnpm-version: 9 - name: Run Vitest run: pnpm test:coverage - name: 'Report Coverage'