-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# (C) bswck | ||
# | ||
# Usage: | ||
# $ ./install && poetry shell | ||
poetry install --all-extras | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully installed dependencies." | ||
else | ||
echo "Failed to install dependencies." | ||
exit 1 | ||
fi | ||
|
||
PYTHON_VERSION="$(cat .python-version)" | ||
|
||
poetry env use $PYTHON_VERSION -q | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully set Python version to $PYTHON_VERSION." | ||
else | ||
echo "Failed to set Python version to $PYTHON_VERSION." | ||
exit 1 | ||
fi | ||
|
||
DIR="$(dirname "$(readlink -f "$0")")" | ||
CMD="export PATH=\$PATH:$DIR/scripts" | ||
APPEND="\n# Add repo scripts to PATH for convenience.\n$CMD\n" | ||
ACTIVATE="$(poetry env info -p)/bin/activate" | ||
|
||
echo $APPEND >> $ACTIVATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
# (C) bswck | ||
# A manual alias for long poetry commands ✨ | ||
# | ||
# Run this before pushing to ensure that package locks are up-to-date. | ||
# We update requirements-dev.txt in order to make sure that the CI environment | ||
# can install the dev dependencies without Poetry. | ||
# | ||
# Usage: | ||
# $ lock | ||
echo "✨ Doing the magic ✨" | ||
poetry lock | ||
poetry export --without=dev -f requirements.txt -o requirements.txt | ||
poetry export --with=dev --extras=all -f requirements.txt -o requirements-dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env python | ||
# (C) bswck | ||
# | ||
# Run this script to release a new version of the package. | ||
# | ||
# Usage: | ||
# $ release [major|minor|patch|<major>.<minor>.<patch>] | ||
""" | ||
Automate the release process by updating local files, creating and pushing a new tag. | ||
The actual release is made via GitHub Actions. | ||
""" | ||
|
||
import argparse | ||
import functools | ||
import logging | ||
import subprocess | ||
import sys | ||
|
||
_LOGGER = logging.getLogger("release") | ||
|
||
|
||
if __name__ == "__main__": | ||
_LOGGER.setLevel(logging.INFO) | ||
(_LOGGER_HANDLER := logging.StreamHandler()).setFormatter( | ||
logging.Formatter("%(levelname)s: %(message)s"), | ||
) | ||
_LOGGER.addHandler(_LOGGER_HANDLER) | ||
|
||
cmd, shell = str.split, functools.partial(subprocess.run, check=True) | ||
|
||
def abort(msg: str, /) -> None: | ||
"""Display an error message and exit the script process with status code -1.""" | ||
_LOGGER.critical(msg) | ||
sys.exit(-1) | ||
|
||
parser = argparse.ArgumentParser(description="Release a semver version.") | ||
parser.add_argument( | ||
"version", | ||
type=str, | ||
nargs=1, | ||
) | ||
args: argparse.Namespace = parser.parse_args() | ||
version: str = args.version.pop() | ||
|
||
files_changed = shell( | ||
cmd("git diff --name-only HEAD"), | ||
capture_output=True, | ||
).stdout.decode() | ||
|
||
if files_changed: | ||
msg = ( | ||
"There are uncommitted changes in the working tree in these files:\n" | ||
f"{files_changed}\n" | ||
"Continue? They will be included in the release commit. (y/n) [n]: " | ||
) | ||
continue_confirm = (input(msg).casefold().strip() or "n")[0] | ||
if continue_confirm != "y": | ||
abort("Uncommitted changes in the working tree.") | ||
|
||
# If we get here, we should be good to go | ||
# Let's do a final check for safety | ||
msg = f"You are about to release {version!r} version. Are you sure? (y/n) [y]: " | ||
|
||
release_confirm = ((input(msg).casefold().strip()) or "y")[0] | ||
|
||
if release_confirm != "y": | ||
abort(f"You said no when prompted to bump the {version!r} version.") | ||
|
||
shell(cmd("poetry self add poetry-bumpversion@latest")) | ||
|
||
_LOGGER.info("Bumping the %r version", version) | ||
|
||
shell([*cmd("poetry version"), version]) | ||
|
||
new_version = "v" + ( | ||
shell(cmd("poetry version --short"), capture_output=True) | ||
.stdout.decode() | ||
.strip() | ||
) | ||
|
||
files_changed_for_release = shell( | ||
cmd("git diff --name-only HEAD"), | ||
capture_output=True, | ||
).stdout.decode() | ||
|
||
if files_changed_for_release: | ||
shell(cmd("git diff")) | ||
msg = ( | ||
"You are about to commit and push auto-changed files due " | ||
"to version upgrade, see the diff view above. " | ||
"Are you sure? (y/n) [y]: " | ||
) | ||
commit_confirm = ((input(msg).casefold().strip()) or "y")[0] | ||
|
||
if commit_confirm == "y": | ||
shell([*cmd("git commit -am"), f"Release {new_version}"]) | ||
shell(cmd("git push")) | ||
else: | ||
abort( | ||
"Changes made uncommitted. " | ||
"Commit your unrelated changes and try again.", | ||
) | ||
|
||
_LOGGER.info("Creating %s tag...", new_version) | ||
|
||
try: | ||
shell([*cmd("git tag -a"), new_version, "-m", f"Release {new_version}"]) | ||
except subprocess.CalledProcessError: | ||
abort(f"Failed to create {new_version} tag, probably already exists.") | ||
else: | ||
_LOGGER.info("Pushing local tags...") | ||
shell(cmd("git push --tags")) |