File: release

package info (click to toggle)
pytile 2024.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 428 kB
  • sloc: python: 848; sh: 46; makefile: 7
file content (54 lines) | stat: -rwxr-xr-x 1,331 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -e

REPO_PATH="$( dirname "$( cd "$(dirname "$0")" ; pwd -P )" )"

if [ "$(git rev-parse --abbrev-ref HEAD)" != "dev" ]; then
    echo "Refusing to publish a release from a branch other than dev"
    exit 1
fi

if [ -z "$(command -v poetry)" ]; then
    echo "Poetry needs to be installed to run this script: pip3 install poetry"
    exit 1
fi

function generate_version {
    latest_tag="$(git tag --sort=committerdate | tail -1)"
    month="$(date +'%Y.%m')"

    if [[ "$latest_tag" =~ "$month".* ]]; then
        patch="$(echo "$latest_tag" | cut -d . -f 3)"
        ((patch=patch+1))
        echo "$month.$patch"
    else
        echo "$month.0"
    fi
}

# Temporarily uninstall pre-commit hooks so that we can push to dev and main:
pre-commit uninstall

# Pull the latest dev:
git pull origin dev

# Generate the next version (in the format YEAR.MONTH.RELEASE_NUMER):
new_version=$(generate_version)

# Update the PyPI package version:
sed -i "" "s/^version = \".*\"/version = \"$new_version\"/g" "$REPO_PATH/pyproject.toml"
git add pyproject.toml

# Commit, tag, and push:
git commit -m "Bump version to $new_version"
git tag "$new_version"
git push && git push --tags

# Merge dev into main:
git checkout main
git merge dev
git push
git checkout dev

# Re-initialize pre-commit:
pre-commit install