Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automating the doc schema generation using husky. #2851

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Adding schema-eneration.yml
Suyash878 committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a6690d07e02eb8aaedbf0cb6888f22c88da48e66
68 changes: 68 additions & 0 deletions .github/workflows/schema-generation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Generate GraphQL Schema
Suyash878 marked this conversation as resolved.
Show resolved Hide resolved
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
generate-schema:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Start application and wait for server
run: |
# Start the server in the background
npm run start &

# Store the PID of the npm process
SERVER_PID=$!

# Wait for the server to be ready (max 60 seconds)
COUNTER=0
until $(curl --output /dev/null --silent --fail http://localhost:4000/graphql); do
if [ $COUNTER -gt 60 ]; then
echo "Server failed to start within 60 seconds"
exit 1
fi
echo "Waiting for server to be ready... ($COUNTER seconds)"
sleep 1
let COUNTER=COUNTER+1
done

echo "Server is ready!"

# Generate schemas
npm run generate:graphql-schema
npm run generate:graphql-markdown

# Kill the server
kill $SERVER_PID

- name: Commit and push if changes exist
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

if [[ -n "$(git status --porcelain)" ]]; then
git add docs/docs/Schema.md docs/github-actions/schema.json
git commit -m "chore: update GraphQL schema"
git push
else
echo "No changes to commit"
fi
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@
"format:check": "prettier --check \"**/*.{ts,tsx,json,scss,css}\"",
"check-tsdoc": "node .github/workflows/check-tsdoc.js",
"prepare": "husky",
"generate:graphql-markdown": "graphql-markdown http://localhost:4000/graphql > docs/Schema.md",
"generate:graphql-schema": "get-graphql-schema http://localhost:4000/graphql --json > docs/schema.json",
"generate:graphql-markdown": "graphql-markdown http://localhost:4000/graphql > docs/docs/Schema.md",
"generate:graphql-schema": "get-graphql-schema http://localhost:4000/graphql --json > docs/github-actions/schema.json",
"generate:ssl-private-key": "openssl req -x509 -nodes -days 1 -newkey rsa:2048 -keyout ./certs/key.pem -out ./certs/cert.pem -subj '/C=US/ST=State/L=City/O=Organization/CN=localhost'",
"import:sample-data": "tsx ./src/utilities/loadSampleData.ts",
"import:sample-data:prod": "node ./build/utilities/loadSampleData.js",
Loading