diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index cf2f5b32..e2a61d35 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -10,33 +10,95 @@ on: # Leave out to test branches off of branches # branches: [ main ] +env: + NODE_VERSION_MAJOR: 16 + GITHUB_SHA: ${{ github.event.pull_request.head.sha }} + jobs: + + prepare-node: + name: Prepare Node + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x + uses: actions/setup-node@v2 + with: + node-version: ${{ env.NODE_VERSION_MAJOR }}.x + cache: 'yarn' + - run: yarn install + lint: name: Lint runs-on: ubuntu-latest + needs: prepare-node steps: - uses: actions/checkout@v2 - - name: Use Node.js 16.x + - name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x uses: actions/setup-node@v2 with: - node-version: 16.x + node-version: ${{ env.NODE_VERSION_MAJOR }}.x cache: 'yarn' - run: yarn install - run: yarn lint:quiet - test: - name: Test + unit-test: + name: Unit Test runs-on: ubuntu-latest + needs: prepare-node + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x + uses: actions/setup-node@v2 + with: + node-version: ${{ env.NODE_VERSION_MAJOR }}.x + cache: 'yarn' + - run: yarn install + - run: yarn test + + build-package: + name: Build Package + runs-on: ubuntu-latest + needs: prepare-node + steps: + - uses: actions/checkout@v2 + - name: Cache Package Build + id: cache-package-build + uses: actions/cache@v3 + with: + # We'll cache this file + path: test/build/spectaql.tgz + key: ${{ runner.os }}-node-v${{ env.NODE_VERSION_MAJOR }}-${{ env.GITHUB_SHA }} + - name: Use Node.js ${{ env.NODE_VERSION_MAJOR }}.x + uses: actions/setup-node@v2 + with: + node-version: ${{ env.NODE_VERSION_MAJOR }}.x + cache: 'yarn' + - run: yarn install + - run: yarn pack --filename test/build/spectaql.tgz + + test-package: + name: Test Package + runs-on: ubuntu-latest + needs: build-package strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - uses: actions/checkout@v2 + - name: Cache Package Build + id: cache-package-build + uses: actions/cache@v3 + with: + # We'll cache this file + path: test/build/spectaql.tgz + #key: ${{ runner.os }}-primes + key: ${{ runner.os }}-node-v${{ env.NODE_VERSION_MAJOR }}-${{ env.GITHUB_SHA }} - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} cache: 'yarn' - - run: yarn install - - run: yarn test + - run: yarn --cwd test/build install + - run: yarn --cwd test/build test diff --git a/.nvmrc b/.nvmrc index dae199ae..6f7f377b 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v12 +v16 diff --git a/test/build/.gitignore b/test/build/.gitignore new file mode 100644 index 00000000..5349ee3c --- /dev/null +++ b/test/build/.gitignore @@ -0,0 +1,3 @@ +*.tgz +node_modules +yarn.lock diff --git a/test/build/README.md b/test/build/README.md new file mode 100644 index 00000000..6a467a64 --- /dev/null +++ b/test/build/README.md @@ -0,0 +1,3 @@ +This is just a folder where we'll simulate installing the built package as a dependency and making sure it runs on every Node engine we support. + +The `lint-and-test.yml` will package things up and put it here. \ No newline at end of file diff --git a/test/build/alive.js b/test/build/alive.js new file mode 100644 index 00000000..7629d51d --- /dev/null +++ b/test/build/alive.js @@ -0,0 +1,11 @@ +const { run } = require('spectaql') + +console.warn('Trying on Node ' + process.version) + +if (typeof run !== 'function') { + console.error("I didn't work.") + process.exit(1) +} + +console.log('I worked!') +process.exit() diff --git a/test/build/package.json b/test/build/package.json new file mode 100644 index 00000000..66ac6c37 --- /dev/null +++ b/test/build/package.json @@ -0,0 +1,14 @@ +{ + "name": "build", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "yarn node alive.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "spectaql": "file:spectaql.tgz" + } +}