Skip to content

Commit

Permalink
chore: Split release script into "prepare_release" and "release"
Browse files Browse the repository at this point in the history
In between running the two scripts with the same version, a merge of the opened PR is required.

Signed-off-by: Niklas Eicker <[email protected]>
  • Loading branch information
NiklasEi committed Jul 16, 2021
1 parent 0c7544a commit 99c7502
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 22 deletions.
83 changes: 83 additions & 0 deletions prepare_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

UPSTREAM_URL='[email protected]:TNG/momo-scheduler.git'
# default: not dry-run
DRY_RUN=0
UPSTREAM_BRANCH=main

set -eux

for arg in "$@"; do
case $arg in
--version=*)
VERSION="${1#*=}"
VERSION_PREFIXED="v${1#*=}"
;;
--dry-run)
DRY_RUN=1
;;
*)
printf "***************************\n"
printf "* Error: Invalid argument.*\n"
printf "***************************\n"
exit 1
esac
shift
done

if [[ ! $VERSION =~ ^[0-9]*\.[0-9]*\.[0-9]*(-[A-Z0-9]*)?$ ]]; then
echo "You have to provide a version as first parameter (without v-prefix, e.g. 0.14.0)"
exit 1
fi

GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ ! $GIT_BRANCH =~ $UPSTREAM_BRANCH ]]; then
echo "You do not seem to be on the ${UPSTREAM_BRANCH} branch!"
exit 1
fi

if [ -n "$(git status --porcelain)" ]; then
echo "You have local changes!"
exit 1
fi

git pull "${UPSTREAM_URL}" "${UPSTREAM_BRANCH}"

RELEASE_BRANCH="${VERSION_PREFIXED}-release"
git branch "$RELEASE_BRANCH"
git checkout "$RELEASE_BRANCH"

if [[ $DRY_RUN ]]; then
echo "Preparing release of version $VERSION (dry-run)"
else
echo "Preparing release of version $VERSION"
fi

echo "Updating version in package.json"
sed -i -e "s/\"version\":.*/\"version\":\ \"$VERSION\"\,/" package.json
npm install

echo "Committing version change"
git add package.json
git add package-lock.json
git commit --signoff -m "Update version to $VERSION"

echo "Linting, building and testing"
npm run lint
npm run build
npm run test

echo "Creating Tag"
git tag -a -m "$VERSION_PREFIXED" "$VERSION_PREFIXED"

if [[ $DRY_RUN ]]; then
echo "Pushing version and tag to GitHub repository (dry-run)"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH" --dry-run
git push "$UPSTREAM_URL" "$VERSION_PREFIXED" --dry-run
else
echo "Pushing version and tag to GitHub repository"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH"
git push "$UPSTREAM_URL" "$VERSION_PREFIXED"

hub pull-request -b "$UPSTREAM_BRANCH" -m "Release version $VERSION"
fi
28 changes: 6 additions & 22 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,29 @@ fi

git pull "${UPSTREAM_URL}" "${UPSTREAM_BRANCH}"

RELEASE_BRANCH="${VERSION_PREFIXED}-release"
git branch "$RELEASE_BRANCH"
git checkout "$RELEASE_BRANCH"
echo "Checking version in package.json"
if [ ! -n "$(sed -n -e '/\"version\": \"$VERSION\"/ p' package.json)" ]; then
echo "Version in package.json is not $VERSION!"
exit 1
fi

if [[ $DRY_RUN ]]; then
echo "Releasing version $VERSION (dry-run)"
else
echo "Releasing version $VERSION"
fi

echo "Updating version in package.json"
sed -i -e "s/\"version\":.*/\"version\":\ \"$VERSION\"\,/" package.json
npm install

echo "Commiting version change"
git add package.json
git add package-lock.json
git commit --signoff -m "Update version to $VERSION"
npm ci

echo "Linting, building and testing"
npm run lint
npm run build
npm run test

echo "Creating Tag"
git tag -a -m "$VERSION_PREFIXED" "$VERSION_PREFIXED"

if [[ $DRY_RUN ]]; then
echo "Pushing version and tag to GitHub repository (dry-run)"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH" --dry-run
git push "$UPSTREAM_URL" "$VERSION_PREFIXED" --dry-run

echo "Publish to npmjs (dry-run)"
npm publish --access public --registry https://registry.npmjs.org/ --dry-run
else
echo "Pushing version and tag to GitHub repository"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH"
git push "$UPSTREAM_URL" "$VERSION_PREFIXED"

echo "Publish to npmjs"
npm publish --access public --registry https://registry.npmjs.org/
fi

0 comments on commit 99c7502

Please sign in to comment.