Skip to content

Commit

Permalink
Update README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
gleidi-suse committed Nov 8, 2023
1 parent a89846a commit b3bcb84
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
1 change: 1 addition & 0 deletions .img/license.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .img/python.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `pot`

[![Python package](https://github.com/fishinthecalculator/pot/actions/workflows/python-package.yml/badge.svg?branch=main)](https://github.com/fishinthecalculator/pot/actions/workflows/python-package.yml)
![Python versions](https://raw.githubusercontent.com/fishinthecalculator/pot/main/.img/python.svg)
![License](https://raw.githubusercontent.com/fishinthecalculator/pot/main/.img/license.svg)

## Contributing

All contributions are welcome. If you have commit access please remember to setup the authentication hook with
Expand Down
29 changes: 29 additions & 0 deletions scripts/generate_badges.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -eu

project_root="$(cd "$(dirname "$(dirname "$0")")" && pwd)"

get_version () {
cat "${project_root}/pot/res/VERSION"
}

python -m pybadges \
--left-text="python" \
--right-text="3.10, 3.11" \
--whole-link="https://www.python.org/" \
--browser \
--logo='https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/python.svg' \
--embed-logo=yes

python -m pybadges \
--left-text="pypi" \
--right-text="$(get_version)" \
--whole-link="https://pypi.org/project/pot/" \
--browser

python -m pybadges \
--left-text="LICENSE" \
--right-text="GPL 3.0+" \
--whole-link="https://choosealicense.com/licenses/gpl-3.0/" \
--browser
178 changes: 178 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/usr/bin/env bash

set -eu

myself="$(basename "$0")"
version_file="$(pwd)/pot/res/VERSION"
pyproject_toml="$(pwd)/pyproject.toml"

current_branch="$(git rev-parse --abbrev-ref HEAD)"
current_commit="$(git log -1 --format='%H')"
dryrun=0
verbose=0
publish=0
bump="INVALID"

required_commands=("getopt" "pysemver" "git")
valid_types=('major' 'minor' 'patch' 'prerelease' 'build')

error() {
echo -e "$@" >/dev/fd/2
}

crash() {
[ "$#" -gt 0 ] && error "$1"
exit 1
}

check-dependencies() {
for com in "${required_commands[@]}"; do
if ! command -v "$com" >/dev/null; then
error "$com not found but it's required! Please install it with your favourite package manager."
crash "\n\t\t\t\tOr just use Guix ;)\n"
fi
done
}

usage() {
cat <<EOF
Usage: ${myself} -b <bump-type> [-hpbvd]
Release a new version of pot according to https://semver.org
-h, --help Show this help message.
-b, --bump Select a version bump type
-p, --publish Publish current release to PyPI.
-d, --dryrun Show operations, instead of carrying them out.
--list-types List all valid version bump types.
-v, --verbose Run script in verbose mode. Will print out each step of execution.
EOF
}

validate-bump-type() {
if [[ ${valid_types[*]} =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
true
else
crash "Invalid bump type: $1"
fi
}

validate-pypi-token() {
if [ -z ${PYPI_TOKEN+x} ]; then
crash "The PYPI_TOKEN environment variable is required but unset. Please set it to upload the new release to PyPI."
fi
}

current-version() {
cat "${version_file}"
}

release-new-version() {
current="$(current-version)"
next="$(pysemver bump "$1" "$current")"
echo "RELEASING VERSION: ${next}"

[ "$verbose" = "1" ] && echo "Updating ${version_file}..."
[ "$dryrun" = "0" ] && printf "%s" "$next" >"$version_file"

[ "$verbose" = "1" ] && echo "Updating ${pyproject_toml}..."
[ "$dryrun" = "0" ] && sed -i -E "s/version.*=.*\"${current}\"$/version = \"${next}\"/" "$pyproject_toml"

[ "$verbose" = "1" ] && echo "Committing ${pyproject_toml} and ${version_file}"
[ "$dryrun" = "0" ] && git add "${pyproject_toml}" \
"${version_file}" && \
git commit -m "Release v${next}."

[ "$verbose" = "1" ] && echo "Tagging Git HEAD with v${next}"
[ "$dryrun" = "0" ] && git tag "v${next}"

[ "$verbose" = "1" ] && echo "Building package..."
[ "$dryrun" = "0" ] && poetry build

}

restore-git-state () {
# This way we can go back to a
# detached HEAD state as well.
if [ "${current_branch}" = "HEAD" ]; then
git checkout "${current_commit}"
else
git checkout "${current_branch}"
fi
}

parse-args() {
[ "$#" -eq 0 ] && crash "$(usage)"

options=$(getopt -l "help,publish,bump:,list-types,verbose,dryrun" -o "hpb:vd" -- "$@")

# set --:
# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters
# are set to the arguments, even if some of them begin with a ‘-’.
eval set -- "$options"

while true; do
case $1 in
-h | --help)
usage
exit 0
;;
--list-types)
echo "${valid_types[@]}"
exit 0
;;
-v | --verbose)
verbose=1
set -vx
;;
-d | --dryrun)
dryrun=1
verbose=1
;;
-p | --publish)
publish=1
;;
-b | --bump)
shift
bump="$1"
;;
--)
shift
break
;;
esac
shift
done

if [ "$bump" = "INVALID" ] && [ "$publish" = "0" ]; then
error "You can either build a new release or publish the current release to PyPI."
crash "See ${myself} -h for more information."
fi
}

parse-args "$@"

if [ "$bump" != "INVALID" ]; then
check-dependencies
validate-bump-type "$bump"
release-new-version "$bump"
fi

if [ "$publish" = "1" ]; then
validate-pypi-token

# We make sure to actually publish the tagged version
git checkout "v$(current-version)"
set +e
# If this command fails we still want to go back to the
# branch we were on.
poetry publish -u "__token__" -p "$PYPI_TOKEN"
set -e
restore-git-state
fi

exit 0

0 comments on commit b3bcb84

Please sign in to comment.