const fs = require('fs-extra');
const path = require('path');
const { execSync } = require('child_process');
const semver = require('semver'); // eslint-disable-line import/no-extraneous-dependencies

const VERSION = require('../package.json').version;

log('Checking if current branch is master branch.');
const currentBranch = execSync('git branch | grep "*"', { encoding: 'utf8' }).substr(2);
if (currentBranch !== 'master') {
    log('Release can only be triggered from the master branch.');
    process.exit(1);
}

log('Checking if branch is up to date.');
const upToDate = execSync('git branch | grep "*"', { encoding: 'utf8' }).substr(2);

log('Fetching version of published beta.');
const betaVersion = fetchPackageJsonPropertyForTag('version', 'beta');

if (semver.gte(betaVersion, VERSION)) {
    log(`Cannot release version: ${VERSION} with version ${betaVersion} already released.`);
    process.exit(0);
}


function log(...messages) {
    /* eslint-disable no-console */
    console.log('release:', ...messages);
}

function fetchPackageJsonPropertyForTag(property, tag) {
    return execSync(`npm show apify@${tag} ${property}`, { encoding: 'utf8' }).trim();
}

@@ -306,29 +306,25 @@
 ;%0Aconst 
-currentBranch
+gitStatus
  = execS
@@ -336,94 +336,148 @@
 git 
-branch %7C grep %22*%22', %7B encoding: 'utf8' %7D).substr(2);%0Aif (currentBranch !== 'master
+status --porcelain --branch', %7B encoding: 'utf8' %7D);%0Aif (!gitStatus.startsWith('## feature/
 ')
+)
  %7B
+ // TODO for testing, dont forget to replace
 %0A   
@@ -531,24 +531,48 @@
 ster branch.
+ Please checkout master.
 ');%0A    proc
@@ -608,28 +608,33 @@
  if 
-branch is up to da
+all changes are commit
 te
+d
 .');
@@ -644,85 +644,431 @@
 nst 
-upToDate = execSync('git branch %7C grep %22*%22', %7B encoding: 'utf8' %7D).substr(2);
+statusLines = gitStatus.split('%5Cn');%0Aif (statusLines.length %3E 1 && statusLines%5B1%5D.length) %7B%0A    log('You have uncommitted changes. Please commit them and run the script again.');%0A    process.exit(1);%0A%7D%0A%0Alog('Checking if branch is up to date.');%0Aif (/%5C%5Bahead%7Cbehind %5Cd+%5C%5D/.test(gitStatus)) %7B%0A    log('Your local copy of master branch is not up to date with the remote. Please push / pull changes.');%0A    process.exit(1);%0A%7D%0A%0A
 %0A%0Alo

Add validation to release script