Skip to content

Commit

Permalink
Merge pull request #3 from tim-s-ccs/add-release-scripts
Browse files Browse the repository at this point in the history
Add the release scripts
  • Loading branch information
tim-s-ccs authored Feb 2, 2022
2 parents 1178b3d + f054df5 commit 49745e0
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
44 changes: 44 additions & 0 deletions bin/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
set -e

# Check if there are unexpected changes. Changes to CHANGELOG.md and the
# package.json file are expected as part of the normal release process.
changes="$(git status --porcelain -- ':!CHANGELOG.md' ':!package/package.json')"
if [[ -n $changes ]]; then
echo "⚠ Unexpected changes in your working directory:"
echo "$changes"
exit 1
fi

echo "Starting to build release..."
echo " "
echo "This will:"
echo "- run the test suite"
echo "- build CCS Frontend into the 'dist/' directory"
echo "- commit all changes and push the branch to remote"
echo " "

read -r -p "Do you want to continue? [y/N] " continue_prompt

if [[ $continue_prompt != 'y' ]]; then
echo "Cancelling build, if this was a mistake, try again and use 'y' to continue."
exit 0
fi

npm run build

ALL_PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG="v$ALL_PACKAGE_VERSION"
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

if [ $(git tag -l "$TAG") ]; then
echo "⚠️ Git tag $TAG already exists. Check you have updated the version in package/package.json correctly."
exit 1;
else
git add .
git commit -m "Release $TAG"
# set upstream so that we can push the branch up
git push --set-upstream origin $CURRENT_BRANCH_NAME
git push
echo "πŸ—’ All done. Ready to create a pull request. Once approved, run npm run publish-release"
fi
57 changes: 57 additions & 0 deletions bin/publish-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh
set -e

echo "Starting a release..."
echo " "
echo "This will:"
echo "- check that you're logged in to npm as the correct user"
echo "- publish the package if it has not been published already"
echo "- check that there is not already a tag published"
echo "- create a new tag"
echo "- push the tag to remote origin"
echo "- create a zip file of the 'dist/' directory locally"
echo " "

read -r -p "Do you want to continue? [y/N] " continue_prompt

if [[ $continue_prompt != 'y' ]]; then
echo "Cancelling release, if this was a mistake, try again and use 'y' to continue."
exit 0
fi

# echo "Checking that you can publish to npm..."

# at some point we should create a team and check if user exists in a team
# ! npm team ls developers | grep -q $NPM_USER

NPM_USER=$(npm whoami)
if ! [ "tim-s-ccs" == "$NPM_USER" ]; then
echo "⚠️ FAILURE: You are not logged in with the correct user."
exit 1
fi

echo "πŸ“¦ Publishing package..."

# Try publishing
cd package
npm publish
echo "πŸ—’ Package published!"
cd ..

# Extract tag version from ./package/package.json
ALL_PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG="v$ALL_PACKAGE_VERSION"

if [ $(git tag -l "$TAG") ]; then
echo "⚠️ Tag $TAG already exists"
exit 1
else
echo "πŸ—’ Tagging repo using tag version: $TAG ..."
git tag $TAG -m "CCS Frontend release $TAG"
git push --tags
echo "πŸ—’ Tag $TAG created and pushed to remote."

echo "πŸ—’ Creating a release artifact..."
git archive -o ./release-$TAG.zip HEAD:dist
echo "πŸ—’ Artifact created. Now create a release on GitHub and attach this."
fi

0 comments on commit 49745e0

Please sign in to comment.