Skip to content

Commit

Permalink
Merge pull request #48 from postmanlabs/feature/automate-release-script
Browse files Browse the repository at this point in the history
Added script for automating release process
  • Loading branch information
VShingala authored Mar 17, 2023
2 parents 53bbe1d + 505ee8b commit ad7ab27
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 21 deletions.
69 changes: 69 additions & 0 deletions npm/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# ----------------------------------------------------------------------------------------------------------------------
# This script is intended to automate release process.
# Explanation: This script will pull all latest changes from master and develop and checkout release branch from develop
# with specified version and then bump up package version and add CHANGELOGS (input required) and commit them. After
# that merge release branch into master and develop with appropriate tags.
#
# Example: "npm run release 1.2.3"
# ----------------------------------------------------------------------------------------------------------------------

# Stop on first error
set -e;

# Ensure that the provided version is in valid semver format
if [[ ! $1 =~ ^v?[0-9]+(\.[0-9]+){2}(-[a-z]+\.\d+)?$ ]]; then
echo "A valid version must be provided as the first argument.";
exit 1;
fi

ver=${1/v/}; # Strip the leading v from the version (if it exists)
msg=$2;

[[ -z $msg ]] && msg="Released v${ver}";

# Update the master branch to the latest
git checkout master;
git pull origin master;

# Update develop to the latest, and create a release brach off of it.
git checkout develop;
git pull origin develop;
git checkout -b release/$ver;

# Bump version in package.json, but do not create a git tag
npm version $ver --no-git-tag-version;

# Inject the current release version and date into the CHANGELOG file
sed -i "" "3i\\
#### v${ver} (`date '+%B %d, %Y'`)\\
\\
" CHANGELOG.md;

# Find all commits between the HEAD on develop and the latest tag on master, and pipe their messages into the clipboard
git log $(git describe --tags master --abbrev=0)..HEAD --merges --pretty=format:'* %s' | pbcopy;

# Provision manual intervention for CHANGELOG.md
vi CHANGELOG.md

# Create the release
git add CHANGELOG.md package.json;
[[ -f package-lock.json ]] && git add package-lock.json;
git commit -am "$msg";

# Merge the release branch into develop and push
git checkout develop;
git merge --no-ff release/$ver;
git push origin develop;

# Merge the release branch into master, create a tag and push
git checkout master;
git merge --no-ff release/$ver;
git tag -a "$ver" -m "$msg";
git push origin master --follow-tags;

# Move back to develop
git checkout develop;
git branch -d release/$ver;

unset msg ver;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"test": "node npm/test.js",
"test-lint": "node npm/test-lint.js",
"test-system": "node npm/test-system.js",
"test-unit": "node npm/test-unit.js"
"test-unit": "node npm/test-unit.js",
"release": "./npm/release.sh"
},
"author": "Postman Labs <help@getpostman.com>",
"license": "Apache-2.0",
Expand Down
20 changes: 0 additions & 20 deletions test/system/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@ describe('project repository', function () {
});
});

describe('script definitions', function () {
it('files must exist', function () {
let scriptRegex = /^node\snpm\/.*\.js/;

expect(json.scripts).to.be.ok;
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
expect(scriptRegex.test(json.scripts[scriptName])).to.equal(true);
expect(fs.existsSync('npm/' + scriptName + '.js')).to.be.ok;
});
});

it('must have the hashbang defined', function () {
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
let fileContent = fs.readFileSync('npm/' + scriptName + '.js').toString();

expect(/^#!\/(bin\/bash|usr\/bin\/env\snode)[\r\n][\W\w]*$/g.test(fileContent)).to.be.ok;
});
});
});

describe('dependencies', function () {
it('must exist', function () {
expect(json.dependencies).to.be.a('object');
Expand Down

0 comments on commit ad7ab27

Please sign in to comment.