Skip to content

Commit

Permalink
chore: add release script to generate changelogs (#145)
Browse files Browse the repository at this point in the history
* chore: add release script

* must be main

* spell
  • Loading branch information
renancaraujo authored Sep 28, 2023
1 parent b7d3a7d commit 3ab53d9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
23 changes: 21 additions & 2 deletions .github/cspell.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": "0.2",
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"dictionaries": ["vgv_allowed", "vgv_forbidden"],
"dictionaries": ["vgv_allowed",
"vgv_forbidden"],
"dictionaryDefinitions": [
{
"name": "vgv_allowed",
Expand All @@ -15,5 +16,23 @@
}
],
"useGitignore": true,
"words": ["endtemplate", "APPDATA", "brickhub", "noopener", "typecheck", "clsx", "Infima", "Csvg", "clsx", "xlink", "linecap", "Contador", "localizable", "mostrado", "página", "Texto"]
"words": [
"endtemplate",
"APPDATA",
"brickhub",
"noopener",
"typecheck",
"clsx",
"Infima",
"Csvg",
"clsx",
"xlink",
"linecap",
"Contador",
"localizable",
"mostrado",
"página",
"Texto",
"creatordate"
]
}
64 changes: 64 additions & 0 deletions tool/release_ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Ensures that the package is ready for a release.
#
# Will update the version.dart file and update the CHANGELOG.md.
#
# Set it up for a new version:
# `./release_ready.sh <version>

currentBranch=$(git symbolic-ref --short -q HEAD)
if [[ ! $currentBranch == "main" ]]; then
echo "Releasing is only supported on the main branch."
exit 1
fi

# Get information
old_version=$(git for-each-ref --count=2 --format "%(refname:short)" --sort=-creatordate refs/tags | tail -n +2 | cut -c 2-)

if [ -z "$old_version" ]; then
echo "Current version was not resolved."
exit 1
fi

# Get new version
new_version="$1";

if [[ "$new_version" == "" ]]; then
echo "No new version supplied, please provide one"
exit 1
fi

if [[ "$new_version" == "$old_version" ]]; then
echo "Current version is $old_version, can't update."
exit 1
fi

# Retrieving all the commits in the current directory since the last tag.
previousTag="v${old_version}"
raw_commits="$(git log --pretty=format:"%s" --no-merges --reverse $previousTag..HEAD -- .)"
markdown_commits=$(echo "$raw_commits" | sed -En "s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/very_good_workflows\/pull\/\1))/p")

if [[ "$markdown_commits" == "" ]]; then
echo "No commits since last tag, can't update."
exit 0
fi
commits=$(echo "$markdown_commits" | sed -En "s/^/- /p")

if grep -q v$new_version "CHANGELOG.md"; then
echo "CHANGELOG already contains version $new_version."
exit 1
fi

# Add a new version entry with the found commits to the CHANGELOG.md.
echo "# ${new_version} \n\n ${commits}\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
echo "CHANGELOG generated, validate entries here: $(pwd)/CHANGELOG.md"

echo "Creating git branch for ver_good_cli@$new_version"
git checkout -b "chore/$new_version" > /dev/null

git add pubspec.yaml CHANGELOG.md

echo ""
echo "Run the following command if you wish to commit the changes:"
echo "git commit -m \"chore: v$new_version\""

0 comments on commit 3ab53d9

Please sign in to comment.