Skip to content

Instantly share code, notes, and snippets.

@dmitrymatveev
Last active September 29, 2017 02:52
Show Gist options
  • Save dmitrymatveev/5fa01a9a30873c790487927805523519 to your computer and use it in GitHub Desktop.
Save dmitrymatveev/5fa01a9a30873c790487927805523519 to your computer and use it in GitHub Desktop.
Scripts to manage projects version updates
#!/bin/bash
# ==================================================================================================
# Makes an archive of a pre-built distributable and
# using github REST apiV3 create a release on the current tag and uploads archive.
# This will assume the tag was created with the same name as current version in package.json
#
# Usage:
# github-deploy <archive file path>
# ==================================================================================================
if [ -z "${1}" ]; then
echo Aborting github release/upload
exit 0
fi
PACKAGE_VERSION="v"$(cut -d "=" -f 2 <<< $(npm run env | grep "npm_package_version"))
REPO=$(cut -d ":" -f 2 <<< $(git remote get-url origin))
USER=$(cut -d "/" -f 1 <<< $REPO)
REPO=$(cut -d "/" -f 2 <<< $REPO | cut -d "." -f 1)
cd ${2}
zip -r ./archive.zip *
# https://github.com/aktau/github-release
github-release release -u ${USER} -r ${REPO} -t ${PACKAGE_VERSION}
github-release upload -u ${USER} -r ${REPO} -t ${PACKAGE_VERSION} -n archive.zip -f ./archive.zip
# ==================================================================================================
#!/bin/bash
# ==================================================================================================
# Use generate-changelog npm module to update CHANGELOG file, push changes to master and bump
# version
# ==================================================================================================
case "${1}" in
major)
FLAG="-M"
VER="major"
;;
minor)
FLAG="-m"
VER="minor"
;;
patch)
FLAG="-p"
VER="patch"
;;
*)
echo "No version specified"
exit 1
esac
# https://www.npmjs.com/package/changelog
changelog ${FLAG} &&
git add CHANGELOG.md &&
git commit -m 'updated CHANGELOG.md' &&
npm version ${VER} &&
git push origin &&
git push origin --tags
# ==================================================================================================
@dmitrymatveev
Copy link
Author

dmitrymatveev commented Sep 29, 2017

Example package.json to go with the scripts

Prerequisites:

https://www.npmjs.com/package/changelog
https://github.com/aktau/github-release

{
  "name": "my-app",
  "version": "15.0.0",
  "main": "index.js",
  "scripts": {
    "release:major": "bash ./bin/make_release.sh major && bash ./bin/upload.sh ./dist"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/user/my-app.git"
  }
}

npm run release:major

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment