-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·93 lines (68 loc) · 2.42 KB
/
release.sh
File metadata and controls
executable file
·93 lines (68 loc) · 2.42 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
set -Eeuo pipefail
REPO_DIR="${REPO_DIR:-/home/jesse}"
DOCKER_IMAGE="${DOCKER_IMAGE:-salehmir/jesse}"
PYTHON_RELEASE_IMAGE="${PYTHON_RELEASE_IMAGE:-python:3.11-slim-bullseye}"
log() {
printf '[release] %s\n' "$*"
}
fail() {
printf '[release] error: %s\n' "$*" >&2
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || fail "missing required command: $1"
}
extract_setup_version() {
sed -nE 's/^VERSION = "([^"]+)"$/\1/p' setup.py
}
extract_package_version() {
sed -nE 's/^__version__ = "([^"]+)"$/\1/p' jesse/version.py
}
require_command git
require_command docker
cd "$REPO_DIR" || fail "cannot enter repo directory: $REPO_DIR"
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || fail "$REPO_DIR is not a git repository"
if ! git diff --quiet || ! git diff --cached --quiet; then
fail "git worktree is not clean; commit or discard local VPS changes first"
fi
log "pulling latest code"
git pull --ff-only
setup_version="$(extract_setup_version)"
package_version="$(extract_package_version)"
[ -n "$setup_version" ] || fail "could not read VERSION from setup.py"
[ -n "$package_version" ] || fail "could not read __version__ from jesse/version.py"
if [ "$setup_version" != "$package_version" ]; then
fail "version mismatch: setup.py=$setup_version, jesse/version.py=$package_version"
fi
VERSION="${VERSION:-$setup_version}"
if [ "$VERSION" != "$setup_version" ]; then
fail "VERSION=$VERSION does not match repository version $setup_version"
fi
if [ -z "${PYPI_TOKEN:-}" ]; then
fail "PYPI_TOKEN is not set"
fi
log "rebuilding package artifacts"
rm -rf dist build *.egg-info
log "building Docker image ${DOCKER_IMAGE}:${VERSION}"
docker build -t "${DOCKER_IMAGE}:${VERSION}" .
log "building Docker image ${DOCKER_IMAGE}:latest"
docker build -t "${DOCKER_IMAGE}:latest" .
log "publishing Python package to PyPI from ${PYTHON_RELEASE_IMAGE}"
docker run --rm \
-v "${REPO_DIR}:/app" \
-w /app \
-e TWINE_USERNAME=__token__ \
-e TWINE_PASSWORD="${PYPI_TOKEN}" \
"${PYTHON_RELEASE_IMAGE}" \
sh -eu -c '
python -m pip install --no-cache-dir --upgrade pip build twine
rm -rf dist build *.egg-info
python -m build
python -m twine upload dist/*
'
log "pushing Docker image ${DOCKER_IMAGE}:${VERSION}"
docker push "${DOCKER_IMAGE}:${VERSION}"
log "pushing Docker image ${DOCKER_IMAGE}:latest"
docker push "${DOCKER_IMAGE}:latest"
log "release completed for version ${VERSION}"