From 928f67c39736d6e15a883d240b611cb76bdc9923 Mon Sep 17 00:00:00 2001 From: Lucian Buzzo Date: Wed, 28 Feb 2024 14:44:57 +0000 Subject: [PATCH] chore: add workflow that tests if tarball is installable --- .github/workflows/npm-pack-check.yml | 42 ++++++++++++++++++++++++++++ .github/workflows/publish-beta.yml | 2 +- test/npm-pack.js | 12 ++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/npm-pack-check.yml create mode 100644 test/npm-pack.js diff --git a/.github/workflows/npm-pack-check.yml b/.github/workflows/npm-pack-check.yml new file mode 100644 index 0000000..3628479 --- /dev/null +++ b/.github/workflows/npm-pack-check.yml @@ -0,0 +1,42 @@ +name: NPM pack check +on: + pull_request: + branches: + - master +jobs: + npm-pack-check: + runs-on: ubuntu-latest + # Only run this job if the PR is from a trusted collaborator (i.e. not a fork) + if: github.event.pull_request.head.repo.full_name == github.repository + steps: + # Checkout project repository + - name: Checkout + uses: actions/checkout@v3.5.0 + + # Setup Node.js environment + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + registry-url: https://registry.npmjs.org/ + node-version: 20 + + # Install dependencies so that prepublish scripts work as expected + - name: Install deps + run: npm i + + - name: Build package + run: npm run build + + - name: Create test install directory + run: mkdir ../test-install + + # Pack the package and move it to the test install directory, then + # install it and ensure that it can be "required" + - name: Ensure pack file can be installed + run: | + export PACK_FILENAME=$(npm pack --json | jq -r '.[] | .filename') + mv $PACK_FILENAME ../test-install/ + mv test/npm-pack.js ../test-install/ + cd ../test-install + npm install $PACK_FILENAME + node npm-pack.js diff --git a/.github/workflows/publish-beta.yml b/.github/workflows/publish-beta.yml index e0f7e0a..1bbaa5f 100644 --- a/.github/workflows/publish-beta.yml +++ b/.github/workflows/publish-beta.yml @@ -20,7 +20,7 @@ jobs: uses: actions/setup-node@v3 with: registry-url: https://registry.npmjs.org/ - node-version: 16 + node-version: 20 # Use a cache for dependencies - uses: actions/cache@v3.3.1 diff --git a/test/npm-pack.js b/test/npm-pack.js new file mode 100644 index 0000000..a11500b --- /dev/null +++ b/test/npm-pack.js @@ -0,0 +1,12 @@ +/** + * This is a simple test script that checks that the package can be required and + * that the setup export is defined. + * This script is used in the `npm-pack-check` GitHub workflow. + */ +const yates = require("@cerebruminc/yates"); + +if (typeof yates.setup === "undefined") { + throw new Error("setup export is undefined"); +} + +console.log("Success!");