chore: implement strict phpstan rules and fix #140
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Schema Linter | |
on: | |
push: | |
branches: | |
- develop | |
- main | |
pull_request_target: | |
branches: | |
- develop | |
- main | |
types: [ opened, synchronize, reopened, labeled ] | |
# Cancel previous workflow run groups that have not completed. | |
concurrency: | |
# Group workflow runs by workflow name, along with the head branch ref of the pull request | |
# or otherwise the branch or tag ref. | |
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
name: Lint WPGraphQL Schema | |
if: contains(github.event.pull_request.labels.*.name, 'safe to test ✔') || ( github.event_name == 'push' && ( github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' ) ) | |
services: | |
mariadb: | |
image: mariadb:10 | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
# Ensure docker waits for mariadb to start | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Setup PHP w/ Composer & WP-CLI | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.1 | |
extensions: mbstring, intl, bcmath, exif, gd, mysqli, opcache, zip, pdo_mysql | |
coverage: none | |
tools: composer:v2, wp-cli | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- name: Setup GraphQL Schema Linter | |
run: npm install -g graphql-schema-linter@^3.0 graphql@^16 | |
- name: Install dependencies | |
uses: ramsey/composer-install@v3 | |
with: | |
composer-options: "--no-progress" | |
- name: Setup WordPress | |
run: | | |
cp .env.dist .env | |
echo GIT_TOKEN=${{ secrets.GIT_TOKEN }} >> .env | |
composer run install-test-env | |
- name: Register Facet to WPGraphQL | |
run: | | |
mkdir -p /tmp/wordpress/wp-content/mu-plugins/ | |
echo "<?php add_action( 'graphql_facetwp_init', function () { register_graphql_facet_type( 'post' ); } );" > /tmp/wordpress/wp-content/mu-plugins/test-facet.php | |
- name: Generate the Static Schema | |
run: | | |
cd /tmp/wordpress/ | |
# Output: /tmp/schema.graphql | |
wp graphql generate-static-schema | |
- name: Lint the Static Schema | |
run: | | |
graphql-schema-linter --except=relay-connection-types-spec,relay-page-info-spec --ignore '{"defined-types-are-used":["MenuItemsWhereArgs","PostObjectUnion","TermObjectUnion","TimezoneEnum"], "fields-have-descriptions":["WPGatsbyCompatibility","WPGatsbyPageNode","WPGatsbyPreviewStatus"], "enum-values-have-descriptions":["WPGatsbyRemotePreviewStatusEnum","WPGatsbyWPPreviewedNodeStatus"], "fields-are-camel-cased":["FacetPager"], "input-object-values-are-camel-cased":["PostFacetPager"]}' /tmp/schema.graphql | |
- name: Display ignored linting errors | |
run: | | |
graphql-schema-linter /tmp/schema.graphql || true | |
- name: Get Latest tag | |
uses: actions-ecosystem/action-get-latest-tag@v1 | |
id: get-latest-tag | |
- name: Test Schema for breaking changes | |
run: | | |
echo "Previous tagged schema ${{ steps.get-latest-tag.outputs.tag }}" | |
- name: Get Previous Released Schema | |
run: curl 'https://github.com/hsimah-services/wp-graphql-facetwp/releases/download/${{ steps.get-latest-tag.outputs.tag }}/schema.graphql' -L --output /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql | |
# https://github.com/marketplace/actions/graphql-inspector | |
- name: Install Schema Inspector | |
run: | | |
npm install @graphql-inspector/config @graphql-inspector/cli graphql | |
- name: Run Schema Inspector | |
run: | | |
# This schema and previous release schema | |
node_modules/.bin/graphql-inspector diff /tmp/${{ steps.get-latest-tag.outputs.tag }}.graphql /tmp/schema.graphql |