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

feat: add check to prevent publishing without annotated tag #1264

Merged
merged 1 commit into from May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -57,7 +57,7 @@
"scripts": {
"build:assets": "gulp --gulpfile scripts/build/gulp/gulpfile.js build:assets",
"build": "gulp --gulpfile scripts/build/gulp/gulpfile.js --release",
"check:dist": "node scripts/publish/check.js",
"check:version": "node scripts/publish/check.js",
"ci": "yarn build && yarn test:saucelabs",
"dev": "gulp --gulpfile scripts/build/gulp/gulpfile.js",
"format": "prettier --write -- '*.{js,json}' '{scripts,src,test}/**/*.{js,jsx}'",
Expand All @@ -67,7 +67,7 @@
"lint:changed": "git ls-files -mz 'src/*.js' 'src/*.jsx' | xargs -0 eslint",
"lint:fix": "eslint --fix 'src/**/*.{js,jsx}'",
"lint:quiet": "eslint --quiet 'src/**/*.{js,jsx}'",
"prepublishOnly": "yarn check:dist && yarn format:check && yarn test",
"prepublishOnly": "yarn check:version && yarn format:check && yarn test",
"start": "webpack-dev-server --config webpack.dev.js",
"test": "karma start karma.js",
"test:debug": "karma start karma.js --debug",
Expand Down
36 changes: 33 additions & 3 deletions scripts/publish/check.js
@@ -1,7 +1,11 @@
/**
* Verifies that the built "dist" file has the correct version number.
* Pre-publish check script that verifies that:
*
* - The built "dist" file has the correct version number.
* - An annotated (not lightweight) tag exists pointing at the current commit.
*/

const child_process = require('child_process');
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -36,7 +40,7 @@ function log(...args) {
console.log(...args);
}

function check() {
function checkDistVersionNumber() {
if (!fs.existsSync(FILE)) {
throw new Error(`File ${FILE} does not exist`);
}
Expand Down Expand Up @@ -76,4 +80,30 @@ function check() {
throw new Error(`Failed to find version string in ${FILE}`);
}

check();
function checkAnnotatedTag() {
const {version} = require('../../package.json');

const {error, signal, status, stdout} = child_process.spawnSync('git', [
'describe',
'--exact-match',
]);

if (error || signal || status) {
const command = `git tag -m v${version} v${version}`;
throw new Error(
`Expected current HEAD to have an annotated tag; try running \`${command}\``
);
}

const tag = stdout.toString().trim();
if (tag !== version) {
throw new Error(
`Expected current HEAD to be tagged as v${version} but it was ${tag}`
);
}

log(`✅ Found annotated version tag v${version}`);
}

checkDistVersionNumber();
checkAnnotatedTag();