diff --git a/.github/workflows/npm-publish-specification.yaml b/.github/workflows/npm-publish-specification.yaml new file mode 100644 index 0000000..af7706b --- /dev/null +++ b/.github/workflows/npm-publish-specification.yaml @@ -0,0 +1,104 @@ +name: Publish Specification + +on: + push: + tags: + - "spec/v*" + +permissions: + contents: read + id-token: write + +jobs: + publish: + name: Publish @openclidev/specification + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + + - name: Extract version + id: version + env: + TAG: ${{ github.ref_name }} + run: | + if [[ ! "$TAG" =~ ^spec/v.+$ ]]; then + echo "ERROR: Invalid specification tag: $TAG" + exit 1 + fi + + VERSION="${TAG#spec/v}" + + SCHEMA_VERSION="$(jq -r ' + .properties.opencliVersion.enum as $versions + | if ($versions | type) == "array" and ($versions | length) == 1 and ($versions[0] | type) == "string" + then $versions[0] + else empty + end + ' spec.schema.json)" + + if [[ -z "$SCHEMA_VERSION" ]]; then + echo "ERROR: Could not determine the schema version from spec.schema.json" + exit 1 + fi + + if [[ "$VERSION" != "$SCHEMA_VERSION" ]]; then + echo "ERROR: Tag version $VERSION does not match schema version $SCHEMA_VERSION" + exit 1 + fi + + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + if [[ "$VERSION" =~ -([a-zA-Z]+)\.[0-9]+$ ]]; then + DIST_TAG="${BASH_REMATCH[1]}" + else + DIST_TAG="latest" + fi + + echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" + + echo "Version: $VERSION" + echo "Dist tag: $DIST_TAG" + + - name: Prepare package + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + mkdir -p npm/specification/schema + + cp spec.schema.json \ + npm/specification/schema/opencli.schema.json + + cp LICENSE npm/specification/LICENSE + + sed "s|{{VERSION}}|$VERSION|g" \ + npm/specification/package.json.tmpl \ + > npm/specification/package.json + + - name: Verify package + working-directory: npm/specification + run: | + echo "Generated package.json:" + cat package.json + + echo + echo "Package contents:" + npm pack --dry-run + + test -f schema/opencli.schema.json + test -f LICENSE + + - name: Publish + working-directory: npm/specification + env: + DIST_TAG: ${{ steps.version.outputs.dist_tag }} + run: npm publish --provenance --access public --tag "$DIST_TAG" \ No newline at end of file diff --git a/npm/specification/README.md b/npm/specification/README.md new file mode 100644 index 0000000..d41ac5e --- /dev/null +++ b/npm/specification/README.md @@ -0,0 +1,39 @@ +# @openclidev/specification + +The canonical JSON Schema for the [OpenCLI](https://opencli.dev) specification. + +Use this package to validate OpenCLI documents or build tools and integrations that consume the specification. + +## Installation + +```bash +npm install @openclidev/specification +``` + +## Usage + +Import the schema directly: + +```typescript +import schema from "@openclidev/specification"; +``` + +Or reference the schema file: + +```text +@openclidev/specification/schema/opencli.schema.json +``` + +The schema is also available via the `schema` export: + +```typescript +import schema from "@openclidev/specification/schema"; +``` + +## Source of Truth + +The OpenCLI specification and its JSON Schema are maintained in the [OpenCLI repository](https://github.com/bcdxn/opencli). This package is a distribution of the canonical schema for use by tools and implementations across the [ecosystem](https://github.com/bcdxn/opencli#ecosystem). + +## License + +MIT diff --git a/npm/specification/package.json.tmpl b/npm/specification/package.json.tmpl new file mode 100644 index 0000000..ba019e3 --- /dev/null +++ b/npm/specification/package.json.tmpl @@ -0,0 +1,27 @@ +{ + "name": "@openclidev/specification", + "version": "{{VERSION}}", + "description": "The canonical JSON Schema for the OpenCLI specification.", + "license": "MIT", + "files": [ + "schema", + "README.md", + "LICENSE" + ], + "exports": { + ".": "./schema/opencli.schema.json", + "./schema": "./schema/opencli.schema.json", + "./schema/opencli.schema.json": "./schema/opencli.schema.json", + "./package.json": "./package.json" + }, + "keywords": [ + "opencli", + "cli", + "specification", + "json-schema", + "cli-specification" + ], + "publishConfig": { + "access": "public" + } +}