From 180a97774427a1e2920eb90b43fb332d0c21ffb0 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Tue, 21 Nov 2023 15:48:47 +0100 Subject: [PATCH 1/2] Implement release scripts --- Makefile | 4 ++ scripts/helpers.sh | 148 +++++++++++++++++++++++++++++++++++++++++++++ scripts/release.sh | 29 +++++++++ 3 files changed, 181 insertions(+) create mode 100755 scripts/helpers.sh create mode 100755 scripts/release.sh diff --git a/Makefile b/Makefile index f436b12..634da47 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ pip=`which pip` pc=`which pip-compile` ps=`which pip-sync` openssl=`which openssl` +type=patch ############################################################################ # container targets @@ -74,6 +75,9 @@ shell: setup-venv: virtualenv --python=/usr/bin/python3.9 venv +release: + scripts/release.sh $(type) + ############################################################################ # utility targets ############################################################################ diff --git a/scripts/helpers.sh b/scripts/helpers.sh new file mode 100755 index 0000000..9300253 --- /dev/null +++ b/scripts/helpers.sh @@ -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 +} diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..5316794 --- /dev/null +++ b/scripts/release.sh @@ -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 From d5698b2910a062d6daf2dbfa7cf6571ea6393b59 Mon Sep 17 00:00:00 2001 From: Jakub Frejlach Date: Tue, 21 Nov 2023 16:02:35 +0100 Subject: [PATCH 2/2] Update operations docs release section --- docs/operations.md | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/operations.md b/docs/operations.md index a53b095..f6804b6 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -4,13 +4,13 @@ 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 @@ -18,26 +18,32 @@ Follow this procedure when performing Griffon version X.Y.Z release. $ 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= + ``` + 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.