-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #495 from garden-io/release-script
chore(release): add a release script
- Loading branch information
Showing
5 changed files
with
100 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
# Performs the following steps to prepare for a release: | ||
# | ||
# 1. Updates the version field in garden-service/package.json. | ||
# 2. Updates garden-service/package-lock.json by doing npm install. | ||
# 3. Creates a tag for the version (we need this for the changelog). | ||
# 4. Generates the changelog, based on the tag from the previous step. TODO: Use --next-tag flag when no longer experimental | ||
# and skip step 3. | ||
# 5. Adds and commits CHANGELOG.md, garden-service/package.json and garden-service/package-lock.json | ||
# 6. Updates the tag after the commit | ||
# 7. Pushes the tag. This triggers CircleCI process that creates the release artifacts | ||
|
||
# Bumps garden-service/package.json version. Adapted from here: https://gist.github.com/timseverien/5c1ba6548df32ca3a16b | ||
function bump { | ||
version=$1 | ||
search='("version":[[:space:]]*").+(")' | ||
replace="\1${version}\2" | ||
|
||
sed -i ".tmp" -E "s/${search}/${replace}/" "garden-service/package.json" | ||
rm "garden-service/package.json.tmp" | ||
} | ||
|
||
# Runs the release steps documented above. | ||
function release { | ||
echo " | ||
Preparing to release version ${version}... | ||
" | ||
|
||
# Updating garden-service/package.json version | ||
bump ${version} | ||
|
||
# Updating package-lock.json version | ||
cd garden-service && npm install && cd .. | ||
|
||
# Creating tag ${tag_name} | ||
git tag -a ${tag_name} -m "chore(release): release ${tag_name}" | ||
|
||
# Updating changelog | ||
changelog=$(git-chglog ${tag_name}) | ||
printf '%s\n\n%s\n' "${changelog}}" "$(cat CHANGELOG.md)" > CHANGELOG.md | ||
|
||
# Commiting changes | ||
git add CHANGELOG.md garden-service/package.json garden-service/package-lock.json && git commit -m "chore(release): bump version to ${version}" | ||
|
||
# Pushing tag | ||
git push origin ${tag_name} --no-verify | ||
|
||
echo " | ||
*** | ||
Version ${version} has been tagged, committed, and pushed to Github! 🎉 | ||
A CI job that creates the release artifcats is currently in process. | ||
Please refer to our contributing docs for the next steps: https://github.com/garden-io/garden/blob/master/CONTRIBUTING.md | ||
*** | ||
" | ||
} | ||
|
||
# Set variables and prompt user | ||
garden_root=$(cd `dirname $0` && cd .. && pwd) | ||
cd ${garden_root} | ||
|
||
version=$1 | ||
tag_name="v${version}" | ||
|
||
if [[ -z $version ]]; then | ||
echo "Error: Version missing" | ||
exit 1 | ||
fi | ||
|
||
while true; do | ||
read -p "Running this script will create a version tag for ${tag_name} and push it to Github. | ||
This triggers a CI process that creates the release artifacts. | ||
Are you sure you want to continue? " yn | ||
case $yn in | ||
[Yy]* ) release; break;; | ||
[Nn]* ) exit;; | ||
* ) echo "Please answer yes or no.";; | ||
esac | ||
done |