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: Add check to fail build if tag version doesn't match package.json #939

Merged
merged 2 commits into from
Jul 15, 2020

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Jul 14, 2020

Description

@nsakaimbo rightly noticed that when I pushed beta 1 for version 6.0.1, I used the wrong version. That is, package.json said 6.0.1 while the tag v6.0.1-beta1. Other than not being correct, this also causes issues with the auto-updater.

This PR adds a script to be run on CI when the build is from a tag that checks whether a given version matches the one from the package.json. If the versions don't match, the build will fail.

How Has This Been Tested

I pushed a test tag and verified the build doesn't get to the publish step.

image

When the build is not on a tag, the validation is skipped.

image

This way people like me who use Vim with an EditorConfig plugin will
indent YML file properly 😄
@mokagio mokagio force-pushed the validate-tag-in-ci branch 2 times, most recently from a36be3d to c1d4469 Compare July 14, 2020 11:18
Comment on lines +232 to +250
validate_version:
docker:
- image: circleci/node:12.16.2-browsers
environment:
VERSION: << pipeline.git.tag >>
steps:
- when:
condition: << pipeline.git.tag >>
steps:
- checkout
- run:
name: Ensure package.json Version And Tag Match
command: node ./validate_tag.js $VERSION
- unless:
condition: << pipeline.git.tag >>
steps:
- run:
name: Skip Validation
command: echo "Not on a tag. Skipping version validation."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new step runs before the build one and if the build started with a tag, checks that the version in package.json matches the tag.

I'm not happy that we now have to run this step on every build, but at the same time it adds less that 15s to a build that is in the order of minutes. It seems like a reasonable tradeoff to prevent future error tagging new versions.

I thought about adding the condition in the wp-desktop workflow, but it already uses one and from the docs it doesn't look like you can nest or compose them.

process.exit(1);
}

console.log(`Version in package.json matches expected value ${version}. 👍`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the root of the project the best location for this file? I was tempted to put it into .circleci but I didn't want to "bind it" to CircleCI, it should be usable under any CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think project root is totally fine here. 👍

This step runs before the build one, and if the build started from
a tag, checks that the version in package.json matches the tag.

I'm not happy that we now have to run this step on every build, but it
also adds less that 15s to a build that is in the order of minutes, so
it seems like a reasonable tradeoff to prevent future errors when
tagging new versions.
@mokagio mokagio marked this pull request as ready for review July 14, 2020 11:25
Copy link
Contributor

@nsakaimbo nsakaimbo left a comment

Choose a reason for hiding this comment

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

This is fantastic! 🎉 Thank you for adding, @mokagio!

@mokagio mokagio merged commit 03f69ac into develop Jul 15, 2020
@mokagio mokagio deleted the validate-tag-in-ci branch July 15, 2020 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants