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

Commit

Permalink
Merge pull request #269 from RedHatProductSecurity/release-scripts
Browse files Browse the repository at this point in the history
GRIF-194: Release scripts
  • Loading branch information
JakubFrejlach authored Nov 22, 2023
2 parents 26324d8 + d5698b2 commit 33b349d
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pip=`which pip`
pc=`which pip-compile`
ps=`which pip-sync`
openssl=`which openssl`
type=patch

############################################################################
# container targets
Expand Down Expand Up @@ -74,6 +75,9 @@ shell:
setup-venv:
virtualenv --python=/usr/bin/python3.9 venv

release:
scripts/release.sh $(type)

############################################################################
# utility targets
############################################################################
Expand Down
34 changes: 20 additions & 14 deletions docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,46 @@

github actions

define secrets
define secrets

## Release

Follow this procedure when performing Griffon version X.Y.Z release.

1) Checkout main branch
1) Clone/update master branch

```
$ git checkout main
$ git fetch --all
$ git rebase origin/main
```
2) Create release branch
2) Start release script and follow instructions
* create a new release branch
```
$ git checkout -b vX.Y.Z
```
* bump version in griffon/__init__.py __version__ variable
* ensure CHANGELOG.md is updated accordingly
* commit / push changes to release branch
* raise PR
```
$ make release type=<major|minor|patch>
```
NOTE: if `type` is not specified, patch release will be performed
This will:
* create a new branch
* replace version on all places with new Griffon version based on the latest Griffon version and release type
* commit and push the changes
* open pull request creation in browser
3) Confirm PR creation opened by the relase script
4) Confirm checks passes
3) Review and merge PR
5) Merge PR
4) Create a new release and tag via [GitHub WebUI](https://github.com/RedHatProductSecurity/griffon/releases/new) - this will also trigger the build and upload to PyPI
6) Create a new release and tag via [GitHub WebUI](https://github.com/RedHatProductSecurity/griffon/releases/new) - this will also trigger the build and upload to PyPI
* Tag and release needs be in format x.x.x to comply with [semantic versioning](#version-policy)
* Tag needs to point to the latest commit
* Release description should include the newest section of the [CHANGELOG.md](CHANGELOG.md)
## Versioning
Griffon uses [Semantic Versioning](https://semver.org/).
Griffon uses [Semantic Versioning](https://semver.org/).
Griffon starts official versioning at v0.1.0.
148 changes: 148 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env bash
# helpers used across bash scripts

# Check before starting the release process
# $1: release type: major | minor | patch
check_are_you_serious() {
local release_type=${1}

echo "Starting the Griffon ${release_type} release process."
read -erp "Do you want to continue? [y/N]: " answer
echo
if [[ "${answer}" != "y" ]]; then
exit 1
fi
}

# Check if current branch is main
check_main_branch() {
current_branch=$( git branch | awk '/^* / {FS = " "; print $2}' )
if [[ "${current_branch}" != "main" ]]; then
echo "ERROR: Your branch is not 'main'. A new release has to be done from main."
echo
echo "Please switch the branch to main and start this script again."
echo
exit 1
fi
}

# Increments the part of the string
# $1: current version
# $2: release type: major | minor | patch
increment_version() {
local current_version=${1}
local release_type=${2}
case ${release_type} in
"major")
version_part=0
;;
"minor")
version_part=1
;;
"patch")
version_part=2
;;
*)
echo "Unknown release type $1, allowed is major/minor/patch"
exit 1
;;
esac

local version=($(echo "${current_version}" | tr "." '\n'))
version[${version_part}]=$((version[${version_part}]+1))

for (( part=${version_part} + 1; part<=2; part++ )) do
version[${part}]=0
done

echo $(local IFS="." ; echo "${version[*]}")
}

# Update the version in files
# $1: new version
update_version() {
local version=${1}

echo

echo "Replacing __version__ in griffon __init__.py to ${version}"
sed -i 's/__version__ = "[0-9]*\.[0-9]*\.[0-9]*"/__version__ = "'${version}'"/g' griffon/__init__.py

echo "Updating the CHANGELOG.md to ${version}"
sed -i 's/^## Unreleased.*/## Unreleased\n\n## ['"${version}"'] - '$(date '+%Y-%m-%d')'/' CHANGELOG.md

echo
}

# Create new git branch
# $1: branch name
create_new_branch() {
local branch_name=${1}

echo "New branch name is ${branch_name}"


echo "Creating new branch ${branch_name}"
echo

git checkout -b ${branch_name}
}

# Push branch
# $1: branch name
push_branch() {
local branch_name=${1}

echo "Pushing release branch"
read -erp "Push branch ${branch_name} to Git server? [y/N]: " answer
if [[ "$answer" != "y" ]]; then
exit 1
fi

git push --set-upstream origin ${branch_name}
echo
}

# Commit changed files
# $1: version
pull_request() {
local version="${1}"

base_link="https://github.com/RedHatProductSecurity/griffon/pull/new"
url_with_args="${base_link}/v${version}?pull_request%5Btitle%5D=preparation%20of%20${version}%20release"
echo "Trying to open the following link in browser to create a pull request into the master branch:"
echo
echo " ${url_with_args}"
echo
xdg-open "${url_with_args}" || (
echo "Failed to open URL to create pull request automatically."
echo "Please open URL manually in your browser"
echo
)
}

# Review changes
review() {
echo "Review of changes"
echo
echo "Please run command \"git diff\" in another terminal"
echo "to check if versions were updated properly."
read -erp "Are changes OK? [y/N]: " answer

if [[ "${answer}" != "y" ]]; then
exit 1
fi
echo
}

# Commit changed files
# $1: version
commit_version_changes() {
local version=${1}

echo "Committing version changes"

git add griffon/__init__.py CHANGELOG.md
git commit -m "Preparation of ${version} release"
echo
}
29 changes: 29 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# perform a release

source scripts/helpers.sh

# Get number of the new Griffon version
# $1: release type (major|minor|patch)
get_new_version() {
local release_type=${1}

# Parse current version from griffon __init__.py
current_version=$(cat griffon/__init__.py | grep -Po '(?<=__version__ = \")\d+\.\d+\.\d+')
new_version=$(increment_version ${current_version} ${release_type})
}

# Main section
check_are_you_serious ${1}
check_main_branch
get_new_version ${1}

create_new_branch "v${new_version}"
update_version ${new_version}
review
commit_version_changes ${new_version}

push_branch "v${new_version}"
pull_request ${new_version}

exit 0

0 comments on commit 33b349d

Please sign in to comment.