Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/check-pretext-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Check PreTeXt Schema for Updates

on:
schedule:
# Runs every Monday at 08:00 UTC
- cron: "0 8 * * 1"
workflow_dispatch: {}

jobs:
check-schema:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download latest pretext-dev.rng
run: |
curl -fsSL \
"https://raw.githubusercontent.com/PreTeXtBook/pretext/refs/heads/master/schema/pretext-dev.rng" \
-o /tmp/pretext-dev-latest.rng

- name: Compare with stored schema
id: compare
run: |
STORED="extension/assets/schema/pretext-dev.rng"
LATEST="/tmp/pretext-dev-latest.rng"

if [ ! -f "$STORED" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "reason=Stored schema file not found" >> "$GITHUB_OUTPUT"
exit 0
fi

STORED_HASH=$(sha256sum "$STORED" | cut -d ' ' -f1)
LATEST_HASH=$(sha256sum "$LATEST" | cut -d ' ' -f1)

echo "Stored hash: $STORED_HASH"
echo "Latest hash: $LATEST_HASH"

if [ "$STORED_HASH" != "$LATEST_HASH" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "reason=SHA-256 hash mismatch" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Check for existing open schema update issue
if: steps.compare.outputs.changed == 'true'
id: existing-issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_NUMBER=$(gh issue list \
--label "schema-update" \
--state open \
--json number \
--jq '.[0].number // empty')
echo "issue_number=${ISSUE_NUMBER}" >> "$GITHUB_OUTPUT"

- name: Create issue for schema update
if: steps.compare.outputs.changed == 'true' && steps.existing-issue.outputs.issue_number == ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_COMMIT=$(curl -fsSL \
"https://api.github.com/repos/PreTeXtBook/pretext/commits?path=schema/pretext-dev.rng&per_page=1" \
| python3 -c "import sys,json; data=json.load(sys.stdin); print(data[0]['sha'][:7] if data else 'unknown')")

gh issue create \
--title "Schema update needed: pretext-dev.rng has changed upstream" \
--label "schema-update" \
--body "The PreTeXt schema file \`pretext-dev.rng\` in the [PreTeXtBook/pretext](https://github.com/PreTeXtBook/pretext) repository has changed since our last update.

**Latest upstream commit:** \`${LATEST_COMMIT}\`

## Steps to update

1. Run \`npm run refresh:schemas\` from the workspace root to download the latest schema and regenerate \`packages/schema/src/schema.ts\`.
2. Review the diff to understand what changed in the schema.
3. Update any element descriptions or extra metadata in \`packages/schema/src/schema.ts\` as needed.
4. Commit the updated \`extension/assets/schema/pretext-dev.rng\` and \`packages/schema/src/schema.ts\`.

This issue was created automatically by the [check-pretext-schema workflow](https://github.com/${{ github.repository }}/actions/workflows/check-pretext-schema.yml)."
Comment on lines +82 to +87
68 changes: 68 additions & 0 deletions .github/workflows/publish-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Publish Schema Package

on:
workflow_dispatch:
inputs:
level:
description: "Release level"
required: true
type: choice
default: "patch"
options:
- "patch"
- "minor"
- "major"

permissions:
id-token: write
contents: write

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: npm install

- name: Build Package
run: npx nx build schema

- name: Bump Version
run: |
cd packages/schema
npm version ${{ inputs.level }}
cd ../..

- name: Get Version
id: version
run: echo "VERSION=$(jq -r '.version' packages/schema/package.json)" >> $GITHUB_OUTPUT

- name: Publish to npm
run: |
cd packages/schema
npm publish --provenance

- name: Commit and Push
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add packages/schema/package.json
git commit -m "chore(schema): bump to v${{ steps.version.outputs.VERSION }}"
git push origin main

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "schema-v${{ steps.version.outputs.VERSION }}" \
--repo="$GITHUB_REPOSITORY" \
--title="Schema Package v${{ steps.version.outputs.VERSION }}"
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "nx build vscode-extension",
"build:dev": "nx build:dev vscode-extension",
"watch": "NX_TUI=false nx build:watch vscode-extension --outputStyle=stream",
"refresh:schemas": "node ./scripts/getSchemas.js && node ./packages/completions/scripts/generate-default-schema.mjs",
"refresh:schemas": "node ./scripts/getSchemas.js && node ./packages/schema/scripts/generate-schema.mjs",
"lint": "nx run-many -t eslint:lint",
"test": "nx run-many -t test"
},
Expand Down
7 changes: 2 additions & 5 deletions packages/completions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
"src/**/*",
"README.md"
],
"scripts": {
"fetch:dev-schema": "node ../../scripts/getSchemas.js --only-pretext-dev",
"generate:schema": "node ./scripts/generate-default-schema.mjs",
"prebuild": "npm run fetch:dev-schema && npm run generate:schema"
},
"scripts": {},
"dependencies": {
"@pretextbook/schema": "*",
"vscode-languageserver": "^9.0.1"
},
"publishConfig": {
Expand Down
10 changes: 1 addition & 9 deletions packages/completions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"targets": {
"build": {
"executor": "nx:run-commands",
"dependsOn": ["refresh-schema", "^build"],
"dependsOn": ["^build"],
"options": {
"cwd": "packages/completions",
"command": "tsc --build tsconfig.lib.json"
Expand All @@ -27,14 +27,6 @@
"cache": true,
"inputs": ["default", "^default"]
},
"refresh-schema": {
"executor": "nx:run-commands",
"options": {
"cwd": "packages/completions",
"command": "npm run fetch:dev-schema && npm run generate:schema"
},
"cache": false
},
"test": {
"executor": "nx:run-commands",
"options": {
Expand Down
Loading
Loading