From 15817ee94149765dcdb4c0beab17b0f25f9b9e2a Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Mon, 9 Jun 2025 17:35:58 +0200 Subject: [PATCH 1/3] Create build-test.yml --- .github/workflows/build-test.yml | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/build-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..adc0bed --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,73 @@ +name: Node.js CI with pnpm + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + strategy: + # Define a matrix for different Node.js versions + matrix: + node-version: [18.x, 20.x, 22.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 # Action to checkout your repository code + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 # Action to set up Node.js environment + with: + node-version: ${{ matrix.node-version }} + # Configure cache for pnpm. The key uses the pnpm-lock.yaml checksum + # to ensure the cache is invalidated when dependencies change. + cache: 'pnpm' + + - name: Install pnpm + # Use pnpm's official setup action to ensure the correct version of pnpm is installed + uses: pnpm/action-setup@v4 + with: + version: latest # Specify the desired pnpm version (e.g., 8, 9, or latest) + # 'run-install' is set to false as we will run `pnpm install` explicitly later + run_install: false + + - name: Get pnpm store path + # This step gets the path to the pnpm content-addressable store. + # This path is used by the cache action to store and restore pnpm's global packages. + shell: bash + run: | + echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV + + - name: Cache pnpm dependencies + uses: actions/cache@v4 # Action to cache files + with: + # Cache the pnpm store. The key depends on the pnpm-lock.yaml file + # and the runner's OS to ensure reproducibility. + path: ${{ env.PNPM_STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies with pnpm + # `pnpm install --frozen-lockfile` is the equivalent of `npm ci` for pnpm. + # It ensures that dependencies are installed exactly as specified in pnpm-lock.yaml + # and will fail if the lockfile is out of sync with package.json. + run: pnpm install --frozen-lockfile + + - name: Run build (TypeScript compilation) + # Assumes you have a "build" script in your package.json that handles TypeScript compilation. + # For example: "scripts": { "build": "tsc" } + run: pnpm run build + + - name: Run tests (Vitest) + # Assumes you have a "test" script in your package.json that runs Vitest. + # To ensure Vitest runs once and exits in CI, we explicitly pass the `--run` flag. + # The `--` is crucial to pass arguments to the underlying `vitest` command. + # For example: "scripts": { "test": "vitest" } + run: pnpm run test -- --run From 0836ec5b2849e59e40768ed50e2c4dee781b7160 Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Mon, 9 Jun 2025 17:42:53 +0200 Subject: [PATCH 2/3] Update build-test.yml --- .github/workflows/build-test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index adc0bed..c63b9f5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -21,14 +21,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 # Action to checkout your repository code - - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 # Action to set up Node.js environment - with: - node-version: ${{ matrix.node-version }} - # Configure cache for pnpm. The key uses the pnpm-lock.yaml checksum - # to ensure the cache is invalidated when dependencies change. - cache: 'pnpm' - - name: Install pnpm # Use pnpm's official setup action to ensure the correct version of pnpm is installed uses: pnpm/action-setup@v4 @@ -37,6 +29,14 @@ jobs: # 'run-install' is set to false as we will run `pnpm install` explicitly later run_install: false + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 # Action to set up Node.js environment + with: + node-version: ${{ matrix.node-version }} + # Configure cache for pnpm. The key uses the pnpm-lock.yaml checksum + # to ensure the cache is invalidated when dependencies change. + cache: 'pnpm' + - name: Get pnpm store path # This step gets the path to the pnpm content-addressable store. # This path is used by the cache action to store and restore pnpm's global packages. From e756ea83937d671036c11e12c11fe58d6b57e28b Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Mon, 9 Jun 2025 17:53:09 +0200 Subject: [PATCH 3/3] Remove redundant steps --- .github/workflows/build-test.yml | 37 +++----------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c63b9f5..dbd815a 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -19,55 +19,24 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 # Action to checkout your repository code + uses: actions/checkout@v4 - name: Install pnpm - # Use pnpm's official setup action to ensure the correct version of pnpm is installed uses: pnpm/action-setup@v4 with: - version: latest # Specify the desired pnpm version (e.g., 8, 9, or latest) - # 'run-install' is set to false as we will run `pnpm install` explicitly later - run_install: false + version: latest - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 # Action to set up Node.js environment + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - # Configure cache for pnpm. The key uses the pnpm-lock.yaml checksum - # to ensure the cache is invalidated when dependencies change. cache: 'pnpm' - - name: Get pnpm store path - # This step gets the path to the pnpm content-addressable store. - # This path is used by the cache action to store and restore pnpm's global packages. - shell: bash - run: | - echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV - - - name: Cache pnpm dependencies - uses: actions/cache@v4 # Action to cache files - with: - # Cache the pnpm store. The key depends on the pnpm-lock.yaml file - # and the runner's OS to ensure reproducibility. - path: ${{ env.PNPM_STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies with pnpm - # `pnpm install --frozen-lockfile` is the equivalent of `npm ci` for pnpm. - # It ensures that dependencies are installed exactly as specified in pnpm-lock.yaml - # and will fail if the lockfile is out of sync with package.json. run: pnpm install --frozen-lockfile - name: Run build (TypeScript compilation) - # Assumes you have a "build" script in your package.json that handles TypeScript compilation. - # For example: "scripts": { "build": "tsc" } run: pnpm run build - name: Run tests (Vitest) - # Assumes you have a "test" script in your package.json that runs Vitest. - # To ensure Vitest runs once and exits in CI, we explicitly pass the `--run` flag. - # The `--` is crucial to pass arguments to the underlying `vitest` command. - # For example: "scripts": { "test": "vitest" } run: pnpm run test -- --run