Skip to content

Commit 7ce8192

Browse files
committed
feat(scripts): adds scripts for managing releases
1 parent 54ee716 commit 7ce8192

File tree

8 files changed

+392
-1
lines changed

8 files changed

+392
-1
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gomodtidy: gomods
77

88
.PHONY: install-protoc
99
install-protoc:
10-
script/install-protoc.sh 29.3 /
10+
scripts/install-protoc.sh 29.3 /
1111
go install google.golang.org/protobuf/cmd/protoc-gen-go@`go list -m -json google.golang.org/protobuf | jq -r .Version`
1212
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
1313

@@ -87,3 +87,12 @@ standard_tests:
8787
( cd $$mod_dir/pkg/workflows/wasm/host && go test -c -o $$abs_dir/host.test . ); \
8888
echo "Running standard tests"; \
8989
$$abs_dir/host.test -test.v -test.run ^TestStandard -path=standard_tests
90+
91+
92+
.PHONY: init_release
93+
init_release:
94+
cd ./scripts/release && bash init.sh
95+
96+
.PHONE: publish_release
97+
publish_release:
98+
cd ./scripts/release && bash publish.sh
File renamed without changes.

scripts/release/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### Release Process
2+
3+
Releases are created from a candidate branch. Create a candidate branch by running:
4+
5+
```bash
6+
$ make init_release
7+
```
8+
9+
Follow the prompts.
10+
11+
Once the release is ready to be tagged execute the publish flow:
12+
13+
```bash
14+
$ make publish_release
15+
```
16+
17+
Follow the prompts to tag either a `beta` pre-release set of tags or a `stable` tag without a pre-release suffix.
18+
19+
The following packages will be tagged:
20+
- generator/protoc-gen-cre
21+
- capabilities/scheduler/cron
22+
- capabilities/networking/http
23+
- capabilities/blockchain/evm
24+
25+
Merge and delete the release branch once tags are accepted and verified.

scripts/release/fix_release.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
source ./print.sh
4+
5+
describe "Fixing release branch"
6+
read -p "Release Version (X.Y.Z): " version
7+
8+
if [[ ! $version =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]
9+
then
10+
error "Release version must be in semantic versioning format (X.Y.Z)"
11+
exit 1
12+
fi
13+
14+
# Get the cherry-pick commit hash
15+
read -p "Enter the commit hash to cherry pick: " commitHash
16+
17+
git show $commitHash
18+
19+
current_branch=$(git rev-parse --abbrev-ref HEAD)
20+
release_branch="release/v$version"
21+
fix_branch="fix/v$version/$commitHash"
22+
23+
# Check that the branch exists
24+
describe "Checking remote origin for release branch..."
25+
if git ls-remote --exit-code --heads origin $release_branch > /dev/null; then
26+
echo "Found release branch"
27+
else
28+
error "Failed to find release branch"
29+
exit 1
30+
fi
31+
32+
# Checkout the release branch
33+
describe "Updating remote tracking branches..."
34+
git fetch origin
35+
36+
# Create a new branch from the release branch
37+
describe "Creating fix branch..."
38+
git checkout -B $fix_branch origin/$release_branch
39+
40+
# Cherry pick the commit
41+
describe "Cherry picking commit onto fix branch..."
42+
if git cherry-pick -S $commitHash > /dev/null; then
43+
echo "Cherry pick successful"
44+
else
45+
error "Failed to cherry pick commit. Rolling back..."
46+
47+
git cherry-pick --abort
48+
git checkout $current_branch
49+
git branch -D $fix_branch
50+
51+
exit 1
52+
fi
53+
54+
# Push the fix branch
55+
describe "Pushing fix branch to origin..."
56+
git push origin $fix_branch
57+
58+
# Create a pull request
59+
describe "Creating pull request to merge fix branch into release branch..."
60+
gh pr create --fill --base $release_branch --head $fix_branch --label "release-fix"
61+
62+
# Reset the branch back to the user's current branch
63+
describe "Reset local branch back to original branch..."
64+
git checkout $current_branch

scripts/release/helpers.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
source ./print.sh
2+
3+
# Fetches remote branches from origin
4+
function fetch_remote_branches() {
5+
# Update remote tracking branches
6+
describe "Updating remote tracking branches..."
7+
git fetch origin
8+
}
9+
10+
# Verify that the branch exists
11+
function verify_remote_release_branch() {
12+
release_branch=$1
13+
14+
describe "Checking remote origin for release branch..."
15+
if git ls-remote --exit-code --heads origin $release_branch > /dev/null; then
16+
echo "Found release branch"
17+
else
18+
error "Failed to find release branch"
19+
exit 1
20+
fi
21+
}
22+
23+
function ask_version {
24+
question=$1
25+
26+
read -p "$question " version
27+
28+
if [[ ! $version =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]
29+
then
30+
echo "Failed to give a proper semver version number, exiting"
31+
exit 1
32+
fi
33+
34+
echo $version
35+
}

scripts/release/init.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Initializes a new release branch from the trunk branch
4+
5+
readonly TRUNK_BRANCH="main"
6+
7+
source ./print.sh
8+
source ./helpers.sh
9+
10+
# accept a version from the user
11+
describe "Initializing a new release branch..."
12+
read -p "Release Version (X.Y.Z): " version
13+
14+
if [[ ! $version =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]
15+
then
16+
error "Release version must be in semantic versioning format (X.Y.Z)"
17+
exit 1
18+
fi
19+
20+
# Ensure we don't have any tags which match the provided version
21+
describe "Checking for existing tags..."
22+
if git ls-remote --tags origin | grep -q "v$version"; then
23+
error "A tag for v$version already exists. Please use a different version number"
24+
exit 1
25+
fi
26+
27+
current_branch=$(git rev-parse --abbrev-ref HEAD)
28+
release_branch="release/v$version"
29+
remote_trunk_branch="origin/$TRUNK_BRANCH"
30+
31+
# Define the target branch for the release. By default we use the remote trunk, but if the hotfix
32+
# flag is provided, we prompt for a tag to base the release on.
33+
release_target=$remote_trunk_branch
34+
while [[ $# -gt 0 ]]; do
35+
case "$1" in
36+
--hotfix)
37+
describe "Hotfix flag detected. Please provide a tag to base the release on"
38+
read -p "Tag: " tag
39+
release_target="tags/v$tag"
40+
41+
describe "Fetching all remote tags"
42+
git fetch --all --tags
43+
;;
44+
esac
45+
shift
46+
done
47+
48+
# Update remote tracking branches
49+
fetch_remote_branches
50+
51+
# Create a release branch from the tip of the remote main branch
52+
describe "Creating $release_branch targeting $release_target..."
53+
git checkout -b $release_branch $release_target
54+
if [ $? -ne 0 ]; then
55+
error "Failed to create release branch $release_branch"
56+
exit 1
57+
fi
58+
59+
# Push the release branch to origin
60+
describe "Pushing $release_branch to origin..."
61+
git push -u origin $release_branch
62+
if [ $? -ne 0 ]; then
63+
error "Failed to publish $release_branch. Rolling back..."
64+
65+
git checkout $current_branch;
66+
git branch -D $release_branch;
67+
exit 1
68+
fi
69+
70+
# Reset the branch back to the user's current branch
71+
describe "Reset local branch back to original branch..."
72+
git checkout $current_branch
73+
74+
describe "Successfully initialized $release_branch!"

scripts/release/print.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Echos the given string in green
2+
function describe {
3+
echo -e "\033[0;32m$1\033[0m"
4+
}
5+
6+
# Echos the given string in red
7+
function error {
8+
echo -e "\033[0;31m$1\033[0m"
9+
}

0 commit comments

Comments
 (0)