Skip to content

feat: decouple query engine (#144) #12

feat: decouple query engine (#144)

feat: decouple query engine (#144) #12

name: CI - Examples
on:
pull_request:
branches:
- main
- develop
paths:
- .github/workflows/pull_request_examples.yml
- examples/**
- packages/**
push:
branches:
- main
- develop
paths:
- .github/workflows/pull_request_examples.yml
- examples/**
- packages/**
# TODO: Remove and replace with real matrix.
workflow_dispatch:
inputs:
NODE_VERSIONS:
description: 'Node versions to test against. Need a JSON array of versions.'
required: true
default: '[20, 22]'
type: string
permissions:
contents: read
pull-requests: read
env:
NODE_VERSIONS: '[20, 22]'
PATHS: |
nextjs/starter:
- .github/workflows/pull_request_examples.yml
- examples/nextjs/starter/**
- packages/**
GRAPHQL_SCHEMA_FILE: '${{ github.workspace }}/schema.graphql'
SNAPWP_HELPER_REF: 'develop' # TODO: Get from PR description.
jobs:
path-filter:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Filter paths
id: filter
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
with:
filters: ${{ env.PATHS }}
outputs:
# TODO: the example shouldn't be hardcoded
changes: ${{ github.event_name == 'workflow_dispatch' && '["nextjs/starter"]' || steps.filter.outputs.changes }}
generate_schema:
name: Generate WPGraphQL schema
uses: './.github/workflows/generate-schema.yml'
with:
# TODO: Get from PR description.
ref: 'develop'
secrets: inherit
eslint:
name: ESLint
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run ESLint
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present lint
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
typecheck:
name: TS Typecheck
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run Codegen
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run codegen
- name: Run TypeScript type check
# TODO: Why are we catching the error?
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present typecheck
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
test-build:
name: Test Build (Node v${{ matrix.node-version }} | ${{ matrix.example }})
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
node-version: ${{ fromJSON('[20]') }}
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
services:
mariadb:
image: mariadb:10
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout SnapWP Helper
uses: actions/checkout@v4
with:
token: '${{ secrets.GITHUB_TOKEN }}'
repository: 'rtcamp/snapwp-helper'
path: snapwp-helper
ref: ${{ env.SNAPWP_HELPER_REF }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Setup PHP
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # 2.32.0
with:
php-version: '8.2'
extensions: mbstring, intl
coverage: none
tools: composer, wp-cli
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Install Composer deps for SnapWP Helper
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # 3.0.0
with:
working-directory: '${{ github.workspace }}/snapwp-helper'
composer-options: '--no-progress'
- name: Setup WordPress Test Environment
run: |
cd '${{ github.workspace }}/snapwp-helper'
cp .env.dist .env; set -a; source .env; set +a
npm run install-test-env
cd $WORDPRESS_ROOT_DIR
sudo php -S localhost:80 -t "${WORDPRESS_ROOT_DIR}" &
sleep 3
curl -IL http://localhost # Verify that the server is running; will fail and exit workflow if not
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Build assets
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present build
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
unit:
name: Unit Tests (Node v${{ matrix.node-version }} | ${{ matrix.example }})
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
node-version: ${{ fromJSON('[20]') }}
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run unit tests
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present test
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
security:
name: Dependencies Audit
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run npm audit
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm audit --audit-level=high
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app
prettier:
name: Check Formatting
runs-on: ubuntu-latest
needs:
- path-filter
- generate_schema
if: ${{ needs.path-filter.outputs.changes != '' && toJSON(fromJSON(needs.path-filter.outputs.changes)) != '[]' }}
strategy:
matrix:
example: ${{ fromJSON(needs.path-filter.outputs.changes) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Get generated schema
uses: actions/download-artifact@v4
with:
name: schema
path: /tmp/schema
- name: Move schema to workspace
run: |
cp /tmp/schema/schema.graphql ${{ github.workspace }}/schema.graphql
- name: Build local packages
run: |
cd '${{ github.workspace }}'
npm ci --workspaces --include-workspace-root
npm run --if-present local-registry:start
npm run --if-present build
# Ensure Verdaccio has the right permissions for CI
touch .verdaccio/conf/htpasswd
sudo chmod 666 .verdaccio/conf/htpasswd # Required so verdaccio container can add our user
mkdir -p .verdaccio/storage/
sudo chmod 777 .verdaccio/storage/
sudo chmod 777 .verdaccio/
npm run --if-present publish:local
# Create test app directory outside of workspace
mkdir -p ${{ runner.temp }}/snapwp-test-app
- name: Scaffold ${{ matrix.example }} App
working-directory: ${{ runner.temp }}/snapwp-test-app
run: |
cp '${{ github.workspace }}/examples/${{ matrix.example }}/.env.example' .env
sed -i 's|NEXT_PUBLIC_WP_HOME_URL=.*|NEXT_PUBLIC_WP_HOME_URL=http://localhost|' .env
# We use a local install because npm link is flaky in CI.
# @see https://github.com/rtCamp/snapwp/pull/
npm i '${{ github.workspace }}/packages/cli' --no-save
npx snapwp --proxy <<< '.'
npm i
- name: Run Prettier
working-directory: ${{ runner.temp }}/snapwp-test-app
run: npm run --if-present format-check
- name: Clean up
if: always()
continue-on-error: true
run: |
cd '${{ github.workspace }}'
npm run --if-present local-registry:stop
rm -rf ${{ runner.temp }}/snapwp-test-app