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

ci: move pre-commit checks to CI #893

merged 18 commits into from
May 11, 2023

Conversation

manzt
Copy link
Member

@manzt manzt commented May 5, 2023

Implements #877 (comment)

Change List

  • move schema generation to a separate script (scripts/generate-schemas.mjs)

Checklist

  • Ensure the PR works with all demos on the online editor
  • Unit tests added or updated
  • Examples added or updated
  • Documentation updated (e.g., added API functions)
  • Screenshots for visual changes (e.g., new encoding support or UI change on Editor)

@manzt manzt requested a review from sehilyi May 6, 2023 15:23
@manzt
Copy link
Member Author

manzt commented May 6, 2023

Hmm, can't quite figure it out but now when I run yarn changelog locally, there are no changes (but it is working in CI).

node-version: 16
cache: 'yarn'
- 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).

Comment on lines +21 to +26
const generator = tsj.createGenerator({
path: path.resolve(__dirname, "../src/index.ts"),
tsconfig: path.resolve(__dirname, "../tsconfig.json"),
skipTypeCheck: true,
encodeRefs: false,
});
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.

@manzt
Copy link
Member Author

manzt commented May 6, 2023

Ah, actually I see what's going on. We needed to use fetch-depth: 0 with the actions/checkout to get the whole git history in order for conventional-changelog to work. It relies on the previous tags to understand what need to be written to the CHANGELOG.md.

Everything is working as it should now, it's just this action is extremely slow because:

  • It needs to checkout the entire gosling history to correctly run conventional-changelog, and the repo is massive (1.37GB) Git repo size #650
  • It needs to install all of the yarn dependencies for gosling.js to run these commands (really it just needs contentional-changelog and ts-json-schema-generator)

In theory, this "Lint Repo" job should be extremely fast and fail early since it's so minimal, but as it stands it takes the longest out of all the other jobs (including tests and building the editor).

Not sure how to proceed because although this is kind of nicer than pre-commit hooks, its very costly in CI.

EDIT: I guess 2.5 minutes isn't horrible, but reducing the size of the repo and making the yarn install much faster would probably make the job take seconds.

package.json Outdated
@@ -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.

@@ -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

@sehilyi
Copy link
Member

sehilyi commented May 6, 2023

Regarding the costly CI, would the CI speed be more reasonable if we remove conventional-changelog from the CI? Since I think we can check conventional-changelog only at the release and not in every PR

Copy link
Member

@sehilyi sehilyi left a comment

Choose a reason for hiding this comment

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

I am open to merging this unless this will likely surpass the available usage of GitHub actions.

@manzt
Copy link
Member Author

manzt commented May 11, 2023

I don't think we are likely to surpass available usage of GitHub actions (famous last words), but it does mean that currently it will take CI longer to pass (which is annoying for PRs).

I like the idea of only running the contentional-changelog in the release action. However, we then need to make sure the CHANGELOG.md is checked into the repo. Right now it will just be generated in the action and never added with git commit.

@manzt manzt changed the title ci: try changelog and schema checks in CI ci: move pre-commit checks to CI May 11, 2023
@manzt
Copy link
Member Author

manzt commented May 11, 2023

Should be all good to merge. The main change now is that when you bump the version npm version patch|minor|major, the package.json "version" script will run, executing conventional-changelog and checking in the updated CHANGELOG.md.

The release "flow" is as described in the conventional-changelog docs: https:/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-cli/README.md#with-npm-version

concretely,

npm version patch
git push --follow-tags

@manzt manzt merged commit 75f4233 into master May 11, 2023
@manzt manzt deleted the manzt/pre-commit branch May 11, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants