Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 64845b9

Browse files
authored
chore: add release ready script (#315)
* chore: add release ready * docs
1 parent c051b12 commit 64845b9

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,30 @@ dart analyze --fatal-infos --fatal-warnings .
121121
9. Verify that all [status checks](https://github.com/VeryGoodOpenSource/very_good_core/actions/) are passing for your Pull Request once they have been approved to run by a maintainer.
122122

123123
💡 **Note**: While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete additional work, tests, or other changes before your pull request can be accepted.
124+
125+
126+
## Releasing a new version
127+
128+
1. Ensure your local `main` branch is up to date with the remote `main` branch:
129+
130+
```sh
131+
git checkout main
132+
git pull origin main
133+
git status
134+
```
135+
136+
2. Ensure the current pipeline is passing on the `main` branch, [here](https://github.com/VeryGoodOpenSource/very_good_core/actions/workflows/very_good_core.yaml?query=branch%3Amain).
137+
138+
3. From the repository, run the script to release a new version:
139+
140+
```sh
141+
./tool/release_ready.sh <new-version>
142+
143+
git commit -m "chore: v<new-version>"
144+
```
145+
146+
This script will:
147+
- Create a new branch named `chore/v<new-version>`
148+
- Update the version info on `brick/brick.yaml`
149+
- Update the version info on `brick/CHANGELOG.md`
150+
- Then commit those changes with the message `chore: v<new-version>`

tool/release_ready.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Ensures that the package or brick is ready for a release.
2+
#
3+
# Set it up for a new version:
4+
# `./release_ready.sh <version>
5+
6+
# Check if current directory is usable for this script, if so we assume it is correctly set up.
7+
if [ ! -f "brick/brick.yaml" ]; then
8+
echo "$(pwd) is not a valid brick."
9+
exit 1
10+
fi
11+
12+
currentBranch=$(git symbolic-ref --short -q HEAD)
13+
if [[ ! $currentBranch == "main" ]]; then
14+
echo "Releasing is only supported on the main branch."
15+
exit 1
16+
fi
17+
18+
# Get information
19+
old_version=""
20+
current_name=""
21+
if [ -f "brick/brick.yaml" ]; then
22+
old_version=$(cat brick/brick.yaml | pcregrep 'version: (.*?)' | tr " " "\n" | tail -1)
23+
current_name=$(cat brick/brick.yaml | pcregrep 'name: (.*?)' | tr " " "\n" | tail -1)
24+
fi
25+
26+
if [ -z "$old_version" ] || [ -z "$current_name" ]; then
27+
echo "Current version or name was not resolved."
28+
exit 1
29+
fi
30+
31+
# Get new version
32+
new_version="$1";
33+
34+
if [[ "$new_version" == "" ]]; then
35+
echo "No new version supplied, please provide one"
36+
exit 1
37+
fi
38+
39+
if [[ "$new_version" == "$old_version" ]]; then
40+
echo "Current version is $old_version, can't update."
41+
exit 1
42+
fi
43+
44+
# Retrieving all the commits in the current directory since the last tag.
45+
previousTag="v${old_version}"
46+
raw_commits="$(git log --pretty=format:"%s" --no-merges --reverse $previousTag..HEAD -- .)"
47+
markdown_commits=$(echo "$raw_commits" | sed -En "s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/very_good_core\/pull\/\1))/p")
48+
49+
if [[ "$markdown_commits" == "" ]]; then
50+
echo "No commits since last tag, can't update."
51+
exit 0
52+
fi
53+
commits=$(echo "$markdown_commits" | sed -En "s/^/- /p")
54+
55+
echo "Updating version to $new_version"
56+
if [ -f "brick/brick.yaml" ]; then
57+
sed -i '' "s/version: $old_version/version: $new_version/g" brick/brick.yaml
58+
fi
59+
60+
# Update dart file with new version.
61+
dart run build_runner build --delete-conflicting-outputs > /dev/null
62+
63+
if grep -q $new_version "brick/CHANGELOG.md"; then
64+
echo "CHANGELOG already contains version $new_version."
65+
exit 1
66+
fi
67+
68+
# Add a new version entry with the found commits to the brick/CHANGELOG.md.
69+
echo "# ${new_version}\n\n${commits}\n\n$(cat brick/CHANGELOG.md)" > brick/CHANGELOG.md
70+
echo "CHANGELOG for $current_name generated, validate entries here: $(pwd)/brick/CHANGELOG.md"
71+
72+
echo "Creating git branch for $current_name@$new_version"
73+
git checkout -b "chore/v$new_version" > /dev/null
74+
75+
git add brick/brick.yaml brick/CHANGELOG.md
76+
77+
echo ""
78+
echo "Run the following command if you wish to commit the changes:"
79+
echo "git commit -m \"chore: v$new_version\""

0 commit comments

Comments
 (0)