-
Notifications
You must be signed in to change notification settings - Fork 304
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
Conversation
This way people like me who use Vim with an EditorConfig plugin will indent YML file properly 😄
a36be3d
to
c1d4469
Compare
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." |
There was a problem hiding this comment.
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}. 👍`); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
c1d4469
to
3d2932c
Compare
There was a problem hiding this 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!
Description
@nsakaimbo rightly noticed that when I pushed beta 1 for version 6.0.1, I used the wrong version. That is,
package.json
said6.0.1
while the tagv6.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.
When the build is not on a tag, the validation is skipped.