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 11 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
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ on:
- master
pull_request:

env:
FORCE_COLOR: "1"

jobs:
LintRepo:
name: Lint Repo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16
- run: |
yarn install
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.

I think ideally this action can run very quickly, and fail early (to prevent other jobs from running).

Maybe we could use npx here (rather than yarn installing everything for the repo).

yarn pre-commit
- name: Assert no unstaged changes
run: git diff --exit-code

Build:
name: Build Editor
runs-on: ubuntu-latest
Expand All @@ -16,7 +35,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 +52,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 +69,5 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- run: yarn install
- run: yarn eslint src/ editor/
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
"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": "node scripts/generate-schemas.mjs",
"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",
"predeploy": "yarn build-editor; echo \"gosling.js.org\" >> build/CNAME",
"deploy": "gh-pages -d build"
"deploy": "gh-pages -d build",
"pre-commit": "run-p changelog schema format"
},
"peerDependencies": {
"pixi.js": "^6.3.0",
Expand Down Expand Up @@ -155,7 +153,6 @@
},
"husky": {
"hooks": {
"pre-commit": "run-p changelog schema schema-higlass schema-theme schema-template format && git add .",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
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.

Also, since our "git flow" is squash & merge PRs, idk if it makes sense to lint every commit for conventional commits.

Instead, something like a GitHub action to lint the PR title would probably make more sense

Not sure if either of you have thoughts on this: @etowahadams @sehilyi

Copy link
Member

Choose a reason for hiding this comment

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

It would make sense to use the semantic-pull-request you shared and remove the commitlint we use for every commit.

We were using another semantic PR which is deprecated and does not work anymore. We were using commitlit to handle a case where there is only one commit in a PR because in this case GitHub used the commit message and ignored the PR title. But, using PR title by default is now supported, so I don't think we need commitlint anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree! No need to have every conventional commit name be linted.

}
}
Expand Down
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",
);
}