Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for release preparation #17

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# This workflow will run the full CI for the Horreum python library including the build and the tests execution
# This is going to be triggered on every pull request as well as on all stable branches (e.g., main and 0.12.x).
name: Python client ci

on:
push:
branches:
- main
- 0.12.x
- 0.13.x
pull_request:

jobs:
test:
name: test/${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: [ "3.9", "3.10", "3.11" ]
python: ["3.9", "3.10", "3.11"]
env:
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
Expand Down
92 changes: 56 additions & 36 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,93 @@ This document aims to describe how to perform a release of the Horreum python li
The versioning pattern should follow the [Horreum](https://github.com/Hyperfoil/Horreum)
versioning scheme to keep coherence among all Horreum-related projects versions.

## Prerequisites

In order to perform the following release procedure correctly, certain prerequisites must be met:

- Installed `git`.
- Installed `poetry` python package, refer to the [doc](https://pypi.org/project/poetry/) for more details.
- Installed `yq` linux tool, refer to its [doc](https://github.com/mikefarah/yq).
- Enough privileges to push new branches in this repository.
- Enough privileges to push new commit in the `main` branch (note this is temporary requirement,
in future direct pushes will be disallowed).

## Procedure

### Tag a new version
Note that releases (i.e., actual _git tags_) are performed from the corresponding _stable_ branch.

### Prepare the project for the next release cycle

Checkout to your branch, either a "stable" (e.g., `0.12.x`) or the `main` one.
This procedure should be executed from the `main` branch, thus, checkout that branch.

```bash
git checkout origin/main
git checkout main
```

Update the project version:
Update the project for the next development cycle by running:

```bash
poetry version patch
./scripts/next-dev-cycle.sh
```

This will bump your version, from `0.12-dev` to `0.12`.
This will create the new _stable_ branch given the current development version.
E.g., if the current version is `0.14.dev`, it will create `0.14.x` _stable_ branch.

After that, it will update the current `main` branch by updating to the next development cycle.

You should see a new commit like `Next is <VERSION>` highlight the next release cycle.
This commit adds the newly created _stable_ branch to the CICD jobs, i.e., `ci.yaml` and `backport.yaml`.

To double-check the version, run:
```bash
poetry version
# horreum 0.12
# horreum 0.15.dev
```

Commit the changes and tag a new version:
```bash
git add .
git commit -m "Tag version 0.12"
git tag v0.12
```

Ensure the tag is in the form of `v$(poetry version)`.

Push changes and tag:
All changes have been performed locally, you now need to push those changes remotely:
```bash
# push main branch
git push origin main
Comment on lines 52 to 54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command should fail, because the origin repo's main branch should be protected against direct pushes -- modifying main (and stable branches) really should require a PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's totally right, I am proceeding step-by-step and at the moment the main is not protected yet as this is still in development mode. Planning to follow your approach in the near future.

The only difference is that this git push origin main will be replaced by creating a new branch and then "create a pull request with those changes"

git push origin v0.12
```

If you are releasing a new patch from a _stable_ branch all previous operations must be performed
from _stable_ rather than from `main`.

### Create stable branch
# push newly created stable branch
STABLE_BRANCH=...
git push origin $STABLE_BRANCH
```

> **NOTE**: If the _stable_ branch already exists, simply skip this step, as this means the following steps have already been done.
### Tag a new version

To create a _stable_ branch from the `main` one, e.g., `0.12.x`, run the following commands.
Checkout the _stable_ branch from which you want to tag a new release.

```bash
git checkout origin/main -b 0.12.x
git checkout origin/main
STABLE_BRANCH=...
git checkout $STABLE_BRANCH
```

Update version to the next development one:
Update the version and create a git tag by running:
```bash
poetry version 0.13-dev
./scripts/update-version.sh -t -u
```

Commit the changes:
Where:
* `-t`, ensure the script creates a new tag.
* `-u`, update the HORREUM_BRANCH in the makefile.
* The scripts will output the new version, prefix it with `v` to obtain the tag.

Update to the next development version by running:
```bash
git add .
git commit -m "Next is 0.13"
./scripts/update-version.sh -d
```
Where:
* `-d`, marks the version as development one.
* The scripts will output the new version.

Commit and push changes:

Push changes:
```bash
git push origin 0.12.x
git push origin main
```
git commit -am "Next is <NEXT_DEV_VERSION>"

git push origin $STABLE_BRANCH

LATEST_TAG=...
git push origin $LATEST_TAG
```
81 changes: 81 additions & 0 deletions scripts/next-dev-cycle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

set -eo pipefail

# Default values
DEV_MODE=${DEV_MODE:-false}
MAIN_BRANCH=${MAIN_BRANCH:-main}
NEXT_VERSION=""

Help()
{
# Display Help
echo "This tool prepares the project to the next development cycle."
lampajr marked this conversation as resolved.
Show resolved Hide resolved
echo ""
echo "Syntax: ${0} [OPTIONS]"
echo "options:"
echo "-h Display this guide."
echo ""
}

while getopts "h" option; do
case $option in
h) Help
exit;;
*) echo "Unrecognized option: ${OPTARG}"
Help
exit 1;;
esac
done

if [ "$DEV_MODE" != "false" ]; then
echo "WARNING: Dev mode enabled..."
fi

if [ -n "$(git status --porcelain)" ]; then
echo "ERROR: You have uncommitted changes, exiting ..."
exit 1
fi

echo "Preparing for next development cycle"

# Compute release version if not provided
if [ -z "$NEXT_VERSION" ]; then
NEXT_VERSION=$(poetry version patch -s --dry-run)
fi

# Compute stable branch from next version
STABLE_BRANCH=$(sed -E -e 's/([^.]+\.[^.]+).*/\1.x/' <<< "$NEXT_VERSION")

echo "Next version will be: $NEXT_VERSION"

echo "Creating stable branch $STABLE_BRANCH ..."
# Check if stable branch exists and create if necessary
if ! git rev-parse --verify "$STABLE_BRANCH" >/dev/null 2>&1; then
git branch "$STABLE_BRANCH" "$MAIN_BRANCH"
echo "Stable branch $STABLE_BRANCH created"
else
echo "Stable branch $STABLE_BRANCH already existing"
fi

echo "Updating $MAIN_BRANCH to the next development cycle ..."
git checkout "$MAIN_BRANCH"

# Update to the next patch to remove the .dev
./scripts/update-version.sh -n "patch" >/dev/null 2>&1
# And then do minor release with dev
NEXT_DEV_VERSION=$(./scripts/update-version.sh -n "minor" -d | tail -n1)
NEXT_RELEASE_VERSION=$(poetry version patch -s --dry-run)

echo "Next release will be $NEXT_RELEASE_VERSION"
echo "Set next development version to $NEXT_DEV_VERSION"

# Update backport.yaml
sed -i "s/target-branch:.*/target-branch: $STABLE_BRANCH/" .github/workflows/backport.yaml

# Update ci.yaml
yq e -i ".on.push.branches += [\"$STABLE_BRANCH\"]" .github/workflows/ci.yaml

if [ "$DEV_MODE" != "true" ]; then
git commit -am "Next is $NEXT_RELEASE_VERSION"
fi
85 changes: 85 additions & 0 deletions scripts/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

set -eo pipefail

DEV_MODE=${DEV_MODE:-false}

Help()
{
# Display Help
echo "Update the project version."
echo ""
echo "Syntax: ${0} [OPTIONS]"
echo ""
echo "options:"
echo "-h Display this guide."
echo ""
echo "-n NEW_VERSION Update the project to this version."
echo " The new version should ideally be a valid semver string or a valid bump rule:"
echo " patch, minor, major, prepatch, preminor, premajor, prerelease."
echo " Run 'poetry version --help' for more details."
echo ""
echo "-d The next version will be a development one."
echo " It will append '-dev' to the version."
echo ""
echo "-t Do git tag with the new version."
echo ""
echo "-u Update the HORREUM_BRANCH in the Makefile."
}

IS_DEVEL_VERSION=false
DO_TAG=false
DEVEL_VERSION_SUFFIX=".dev"
UPDATE_HORREUM_BRANCH=false
NEW_VERSION=${NEW_VERSION:-"patch"}

while getopts "hn:dtu" option; do
case $option in
h) Help
exit;;
n) NEW_VERSION=${OPTARG}
;;
d) IS_DEVEL_VERSION=true
;;
t) DO_TAG=true
;;
u) UPDATE_HORREUM_BRANCH=true
;;
*) echo "Unrecognized option: ${OPTARG}"
Help
exit 1;;
esac
done

NEW_VERSION=$(poetry version "$NEW_VERSION" -s --dry-run)

if [ "$IS_DEVEL_VERSION" = "true" ]; then
NEW_VERSION="$NEW_VERSION$DEVEL_VERSION_SUFFIX"
fi

# Compute stable branch from next version
STABLE_BRANCH=$(sed -E -e 's/([^.]+\.[^.]+).*/\1.x/' <<< "$NEW_VERSION")

# Update HORREUM_BRANCH on Makefile
if [ "$UPDATE_HORREUM_BRANCH" = "true" ]; then
sed -i "s/HORREUM_BRANCH ?= \".*\"/HORREUM_BRANCH ?= \"$STABLE_BRANCH\"/" Makefile
fi

echo "Updating project version to $NEW_VERSION ..."
poetry version "$NEW_VERSION" -v

# Generate raw client
make generate

if [ "$DO_TAG" = "true" ] && [ "$IS_DEVEL_VERSION" = "false" ]; then
echo "Tagging version v$NEW_VERSION"
if [ "$DEV_MODE" != "true" ]; then
git commit -am "Tagging version $NEW_VERSION"
git tag "v$NEW_VERSION"
fi
else
echo "Skipping tag because disabled or this is a development version"
fi

# Print the new version
echo "$NEW_VERSION"