Created
August 2, 2023 19:53
-
-
Save tfluehr/a4588aea7f977bd5c99a393f63f3dd76 to your computer and use it in GitHub Desktop.
changesets status check for ci/cd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { execSync } = require("child_process"); | |
// get the reference to a common ancestor in this branch vs the origin/main branch | |
const ref = execSync(`git merge-base main HEAD`); | |
// get the list of files changed since the common ancestor | |
let fileList = execSync(`git diff --name-only ${ref}`).toString().split('\n'); | |
// used to test the script locally | |
// fileList.push('.changeset/odd-wombats-vanish.md'); | |
// check if any of the files changed are markdown from the changeset folder. | |
let hasChangeset = fileList.some((file) => file.match(/.changeset\/.*\.md$/)); | |
if (hasChangeset) { | |
process.exit(0); | |
} | |
else { | |
console.error('No changeset(s) found. Use "npm run changeset" to create one. \n\nIf no changeset is needed for this PR use "npm run changeset -- --empty" to create an empty changeset. '); | |
process.exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment