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

ci: move pre-commit checks to CI #893

Merged
merged 18 commits into from
May 11, 2023
Merged
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
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ on:
- master
pull_request:

env:
FORCE_COLOR: "1"

jobs:

Build:
name: Build Editor
runs-on: ubuntu-latest
Expand All @@ -16,7 +20,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- run: yarn install
- run: yarn build-editor
env:
Expand All @@ -34,7 +37,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn install
- run: |
yarn build-types # typecheck
Expand All @@ -52,6 +54,10 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- run: yarn install
- run: yarn eslint src/ editor/
- name: ESLint
run: yarn eslint src/ editor/
- name: Assert schemas are all up to date
run: |
yarn schema
git diff --exit-code
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npx changelogithub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this action was added in #881. This action also won't work unless you set fetch-depth: 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it! Thanks for finding this

env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
19 changes: 3 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
"check": "tsc --noEmit",
"test": "vitest",
"coverage": "vitest run --coverage",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"format": "eslint src/ editor/ --fix && prettier 'editor/**/*.css' --write",
"schema": "ts-json-schema-generator -p src/index.ts -f tsconfig.json -t GoslingSpec --no-type-check --no-ref-encode > schema/gosling.schema.json",
"schema-higlass": "ts-json-schema-generator -p src/index.ts -f tsconfig.json -t HiGlassSpec --no-type-check --no-ref-encode > schema/higlass.schema.json",
"schema-theme": "ts-json-schema-generator -p src/index.ts -f tsconfig.json -t Theme --no-type-check --no-ref-encode > schema/theme.schema.json",
"schema-template": "ts-json-schema-generator -p src/index.ts -f tsconfig.json -t TemplateTrackDef --no-type-check --no-ref-encode > schema/template.schema.json",
"schema-versioning": "mkdir -p schema/history/$npm_package_version && cp schema/gosling.schema.json schema/history/$npm_package_version/gosling$npm_package_version.schema.json && cp src/core/gosling.schema.ts schema/history/$npm_package_version/gosling$npm_package_version.schema.ts",
"schema": "node scripts/generate-schemas.mjs",
"predeploy": "yarn build-editor; echo \"gosling.js.org\" >> build/CNAME",
"deploy": "gh-pages -d build"
"deploy": "gh-pages -d build",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
},
"peerDependencies": {
"pixi.js": "^6.3.0",
Expand Down Expand Up @@ -85,8 +81,6 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@testing-library/react": "^10.4.8",
"@testing-library/user-event": "^12.1.1",
"@types/d3-drag": "^2.0.0",
Expand Down Expand Up @@ -117,7 +111,6 @@
"fetch-jsonp": "^1.1.3",
"gh-pages": "^3.1.0",
"git-branch-is": "^4.0.0",
"husky": "^4.2.5",
"jest-canvas-mock": "^2.3.0",
"jsdom": "^19.0.0",
"jsoncrush": "^1.1.6",
Expand Down Expand Up @@ -152,11 +145,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"husky": {
"hooks": {
"pre-commit": "run-p changelog schema schema-higlass schema-theme schema-template format && git add .",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
34 changes: 34 additions & 0 deletions scripts/generate-schemas.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check
import * as fs from "node:fs";
import * as path from "node:path";
import * as url from "node:url";
import * as tsj from "ts-json-schema-generator";

// Copied from `ts-json-schema-generator` to create
// identical schemas to the one previously generated by CLI.
// @ref: https://github.com/vega/ts-json-schema-generator/blob/aec8a25f366fa32ba9539adc5a91f4ff3b14d1e9/ts-json-schema-generator.ts#LL67C1-L68C1
import stableStringify from "safe-stable-stringify";

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

const SCHEMAS = [
["GoslingSpec", "gosling.schema.json"],
["HiGlassSpec", "higlass.schema.json"],
["Theme", "theme.schema.json"],
["TemplateTrackDef", "template.schema.json"],
];

const generator = tsj.createGenerator({
path: path.resolve(__dirname, "../src/index.ts"),
tsconfig: path.resolve(__dirname, "../tsconfig.json"),
skipTypeCheck: true,
encodeRefs: false,
});
Comment on lines +21 to +26
Copy link
Member Author

@manzt manzt May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running ts-json-schema-generator from the command line multiple times is unnecessarily expensive, since it needs to run TS and parse the AST each time for the whole Gosling code base. We can re-use the same schema generator for each of our schemas in this single script.


for (const [type, filename] of SCHEMAS) {
const schema = generator.createSchema(type);
fs.promises.writeFile(
path.resolve(__dirname, `../schema/${filename}`),
stableStringify(schema, null, 2) + "\n",
);
}
Loading