Skip to content

Commit

Permalink
Merge branch 'release-0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecentola committed Jul 22, 2022
2 parents 480aabf + 100f99b commit 3401154
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 52 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '16 10 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'typescript' ]

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
27 changes: 27 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# You can adjust the behavior by modifying this file.
# For more information, see:
# https://github.com/actions/stale
name: Mark stale issues and pull requests

on:
schedule:
- cron: '18 7 * * *'

jobs:
stale:

runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@

All changes to the CNC Codes JSON Schema will be documented here.

## v0.2. [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.2.2)
## v0.3.0 [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.3.0)

### New Features

- *BREAKING* Added `remove` array property to `variant` (Now an object) for modifying JSON for which it is a variant

### Fixes

- Fixed tests to provide more information if the schema is invalid

### Other

- Updated dependencies
- Updated [README](README.md)
- `variant` is now object with `name` property and `remove` array.

## v0.2.2 [#](https://github.com/appliedengdesign/cnccodes-json-schema/releases/tag/v0.2.2)

### Fixes

Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

This project is a schema definition for using JSON to store description and usage information about G & M codes. It was developed out of a necessity for [G-Code Reference](https://github.com/appliedengdesign/gcode-reference). It will be updated as the needs arise for the various types of G/M codes and various Machine Tools or 3D Printers.

Latest NPM Version: v0.2.2
Latest NPM Version: v0.3.0

Latest Draft Schema Version: 2022-07

Expand Down Expand Up @@ -69,10 +69,22 @@ Previous Versions: [2022-06](https://appliedengdesign.github.io/cnccodes-json-sc
},
"variant": {
"description": "Defined if G/M Codes are for specific MTB/3DP Variant. (Must be lower case, 3-8 characters)",
"type": "string",
"minLength": 3,
"maxLength": 8,
"pattern": "[A-Za-z0-9]"
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 8,
"pattern": "[a-z0-9]"
},
"remove": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
}
},
"codes": {
"description": "Individual G/M Codes",
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appliedengdesign/cnccodes-json-schema",
"version": "0.2.2",
"version": "0.3.0",
"description": "JSON Schema for CNC G & M Codes",
"author": "Mike Centola",
"license": "MIT",
Expand Down Expand Up @@ -34,11 +34,14 @@
"access": "public"
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"build": "npm run test && tsc --project tsconfig.build.json",
"build-ghp": "npx ts-node ./scripts/build-ghpages.ts",
"clean": "shx rm -rf dist/*",
"compile": "tsc",
"lint": "eslint src/**/*.ts --fix",
"refresh": "shx rm -rf ./node_modules ./package-lock.json && npm install",
"prepack": "npm run clean && npm run build",
"pretty": "prettier --config .prettierrc --loglevel warn --write",
"test": "mocha --require ts-node/register test/**/*.ts"
},
"devDependencies": {
Expand Down
20 changes: 16 additions & 4 deletions src/schema/cnccodes.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@
},
"variant": {
"description": "Defined if G/M Codes are for specific MTB/3DP Variant. (Must be lower case, 3-8 characters)",
"type": "string",
"minLength": 3,
"maxLength": 8,
"pattern": "[A-Za-z0-9]"
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 8,
"pattern": "[a-z0-9]"
},
"remove": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
}
},
"codes": {
"description": "Individual G/M Codes",
Expand Down
1 change: 1 addition & 0 deletions test/sample/g-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "gcode",
"machineType": "mill",
"title": "G Code Milling Reference",
"description": "G-Code Reference for Milling Machine Tools",
"codes": {
"G00": {
"category": "motion",
Expand Down
1 change: 1 addition & 0 deletions test/sample/m-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "mcode",
"machineType": "mill",
"title": "M Code Milling Reference",
"description": "M Code Reference for Milling Machine Tools",
"codes": {
"M00": {
"category": "mcode",
Expand Down
36 changes: 36 additions & 0 deletions test/sample/variant-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "../../src/schema/cnccodes.schema.json",
"type": "gcode",
"machineType": "mill",
"title": "G Code Milling Reference",
"description": "G-Code Reference for Milling Machine Tools",
"variant": {
"name": "snpmaker",
"remove": [
"M07",
"M08"
]
},
"codes": {
"G00": {
"category": "motion",
"shortDesc": "Rapid Motion Positioning",
"desc": "G00 is used to move the machine axes at the maximum speed. This G code is modal.",
"modal": true,
"parameters": {
"X": {
"shortDesc": "X-Axis motion command",
"optional": true
},
"Y": {
"shortDesc": "Y-Axis motion command",
"optional": true
},
"Z": {
"shortDesc": "Z-Axis motion command",
"optional": true
}
}
}
}
}
119 changes: 79 additions & 40 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,97 @@ import { cncCodesJSONSchema } from '../src';
import Ajv from 'ajv/dist/2020';
import gsample from './sample/g-sample.json';
import msample from './sample/m-sample.json';
import variant from './sample/variant-sample.json';

describe('Schema Definition', () => {
it('Should return correct json-schema.org spec (2020-12)', () => {
const sd = cncCodesJSONSchema.$schema;
expect(sd).to.equal('https://json-schema.org/draft/2020-12/schema');
});
});
const defaultOptions = {
allErrors: true,
verbose: true,
};

describe('Validate Schema', () => {
it('Should return true for valid schema', () => {
const ajv = new Ajv({ allErrors: true, verbose: true });
const validate = ajv.getSchema(cncCodesJSONSchema.$schema);
if (validate) {
expect(validate(cncCodesJSONSchema)).to.be.true;
}
});
});
describe('CNC Codes JSON Testing', () => {
describe('Validate Schema...', () => {
describe('Schema Definition', () => {
it('Should return correct json-schema.org spec (2020-12)', () => {
const sd = cncCodesJSONSchema.$schema;
expect(sd).to.equal('https://json-schema.org/draft/2020-12/schema');
});
});

describe('Test Schema Against Valid JSON', () => {
const ajv = new Ajv({ allErrors: true, verbose: true });
const validate = ajv.compile(cncCodesJSONSchema);
describe('Validate CNC Codes Schema', () => {
it('Should return true for valid schema', () => {
const ajv = new Ajv(defaultOptions);

if (validate) {
const valid = validate(msample);
it('Should return true for valid JSON', () => {
expect(valid).to.be.true;
const validate = ajv.getSchema(cncCodesJSONSchema.$schema);
if (validate) {
expect(validate(cncCodesJSONSchema)).to.be.true;
}
});
});
});

it('Validation Errors should be null', () => {
expect(validate.errors).to.be.null;
});
}
});
describe('Test Schema...', () => {
describe('Test Schema Against Valid JSON', () => {
const ajv = new Ajv(defaultOptions);
try {
const validate = ajv.compile(cncCodesJSONSchema);

describe('Test Schema Against Invalid JSON', () => {
const ajv = new Ajv({ allErrors: true, verbose: true });
const validate = ajv.compile(cncCodesJSONSchema);
if (validate) {
const valid = validate(msample);
it('Should return true for valid JSON', () => {
expect(valid).to.be.true;
});

if (validate) {
const valid = validate(gsample);
it('Should return true for valid JSON', () => {
expect(valid).to.be.false;
it('Validation Errors should be null', () => {
expect(validate.errors).to.be.null;
});
}
} catch (err) {
it('Schema did not validate... skipping');
}
});

it('Validation errors should not be null', () => {
expect(validate.errors).to.not.be.null;
describe('Test Schema Against Invalid JSON', () => {
const ajv = new Ajv(defaultOptions);

try {
const validate = ajv.compile(cncCodesJSONSchema);

if (validate) {
const valid = validate(gsample);
it('Should return true for valid JSON', () => {
expect(valid).to.be.false;
});

it('Validation errors should not be null', () => {
expect(validate.errors).to.not.be.null;
});

it('Validation error should be shortDesc missing', () => {
if (validate.errors) {
expect(validate.errors[0].params.missingProperty).to.be.equal('shortDesc');
}
});
}
} catch (err) {
it('Schema did not validate... skipping');
}
});

it('Validation error should be shortDesc missing', () => {
if (validate.errors) {
expect(validate.errors[0].params.missingProperty).to.be.equal('shortDesc');
describe('Test Schema Against Valid Variant JSON', () => {
const ajv = new Ajv(defaultOptions);

try {
const validate = ajv.compile(cncCodesJSONSchema);

if (validate) {
const valid = validate(variant);
it('Should return true for valid Variant JSON', () => {
expect(valid).to.be.true;
});
}
} catch (err) {
it('Schema did not validate... skipping');
}
});
}
});
});

0 comments on commit 3401154

Please sign in to comment.