-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnotify-registry.sh
More file actions
executable file
·199 lines (166 loc) · 4.67 KB
/
Copy pathnotify-registry.sh
File metadata and controls
executable file
·199 lines (166 loc) · 4.67 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
set -euo pipefail
IMAGE_NAME=${IMAGE_NAME:-transloadit-python-sdk-dev}
CACHE_ROOT=${CACHE_ROOT:-.docker-cache}
POETRY_CACHE_DIR="$CACHE_ROOT/pypoetry"
PIP_CACHE_DIR="$CACHE_ROOT/pip"
HOME_DIR="$CACHE_ROOT/home"
usage() {
cat <<'EOF'
Usage: scripts/notify-registry.sh [options]
Options:
--dry-run Build the package but skip publishing to PyPI
-h, --help Show this help text
Environment:
PYPI_TOKEN API token with upload rights for pypi.org. This variable can
optionally be defined in .env
EOF
}
err() {
echo "notify-registry: $*" >&2
}
ensure_docker() {
if ! command -v docker >/dev/null 2>&1; then
err "Docker is required to run this script."
exit 1
fi
if ! docker info >/dev/null 2>&1; then
if [[ -z "${DOCKER_HOST:-}" && -S "$HOME/.colima/default/docker.sock" ]]; then
export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"
fi
fi
if ! docker info >/dev/null 2>&1; then
err "Docker daemon is not reachable. Start Docker (or Colima) and retry."
exit 1
fi
}
configure_platform() {
if [[ -z "${DOCKER_PLATFORM:-}" ]]; then
local arch
arch=$(uname -m)
if [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
DOCKER_PLATFORM=linux/amd64
fi
fi
}
run_outside_container() {
ensure_docker
configure_platform
mkdir -p "$CACHE_ROOT" "$POETRY_CACHE_DIR" "$PIP_CACHE_DIR" "$HOME_DIR"
local build_args=()
if [[ -n "${DOCKER_PLATFORM:-}" ]]; then
build_args+=(--platform "$DOCKER_PLATFORM")
fi
build_args+=(-t "$IMAGE_NAME" -f Dockerfile .)
docker build "${build_args[@]}"
local docker_args=(
--rm
--user "$(id -u):$(id -g)"
-e HOME=/workspace/$HOME_DIR
-e POETRY_CACHE_DIR=/workspace/$POETRY_CACHE_DIR
-e PIP_CACHE_DIR=/workspace/$PIP_CACHE_DIR
-v "$PWD":/workspace
-v "$PWD/$POETRY_CACHE_DIR":/workspace/"$POETRY_CACHE_DIR"
-v "$PWD/$PIP_CACHE_DIR":/workspace/"$PIP_CACHE_DIR"
-v "$PWD/$HOME_DIR":/workspace/"$HOME_DIR"
-w /workspace
)
if [[ -n "${DOCKER_PLATFORM:-}" ]]; then
docker_args+=(--platform "$DOCKER_PLATFORM")
fi
if [[ -f .env ]]; then
docker_args+=(--env-file "$PWD/.env")
fi
if [[ -n "${PYPI_TOKEN:-}" ]]; then
docker_args+=(-e "PYPI_TOKEN=${PYPI_TOKEN}")
fi
if [[ $# -gt 0 ]]; then
exec docker run "${docker_args[@]}" "$IMAGE_NAME" scripts/notify-registry.sh --inside-container "$@"
else
exec docker run "${docker_args[@]}" "$IMAGE_NAME" scripts/notify-registry.sh --inside-container
fi
}
load_env_var() {
local var_name=$1
if [[ -n "${!var_name:-}" ]]; then
return 0
fi
if [[ -f .env ]]; then
# shellcheck disable=SC1091
source .env || err "Failed to source .env"
fi
}
verify_repo_state() {
if [[ -n "$(git status --porcelain)" ]]; then
err "Git working tree is not clean. Commit or stash changes before publishing."
exit 1
fi
}
verify_versions_consistent() {
local version python_version header_version
version=$(poetry version -s)
python_version=$(python -c "import transloadit; print(transloadit.__version__)")
header_version=$(grep -oE 'python-sdk:[0-9]+\.[0-9]+\.[0-9]+' tests/test_request.py | tail -n1 | cut -d: -f2)
if [[ "$version" != "$python_version" ]]; then
err "Version mismatch: pyproject.toml=$version but transloadit/__init__.py=$python_version"
exit 1
fi
if [[ "$version" != "$header_version" ]]; then
err "Version mismatch: tests/test_request.py expects $header_version but pyproject.toml has $version"
exit 1
fi
if ! grep -Eq "^### ${version}([[:space:]/]|$)" CHANGELOG.md; then
err "CHANGELOG.md does not contain an entry for ${version}"
exit 1
fi
}
publish_inside_container() {
local dry_run=0
while [[ $# -gt 0 ]]; do
case "$1" in
--inside-container)
shift
;;
--dry-run)
dry_run=1
shift
;;
--inside-container)
shift
;;
-h|--help)
usage
exit 0
;;
*)
err "Unknown option: $1"
usage
exit 1
;;
esac
done
load_env_var "PYPI_TOKEN"
if [[ -z "${PYPI_TOKEN:-}" ]]; then
err "PYPI_TOKEN is not set. Export it or add it to .env before publishing."
exit 1
fi
export POETRY_PYPI_TOKEN_PYPI="$PYPI_TOKEN"
verify_repo_state
verify_versions_consistent
rm -rf dist
poetry build
if [[ "$dry_run" == "1" ]]; then
err "Dry run complete. Built artifacts in dist/ but skipped publishing."
exit 0
fi
poetry publish --no-interaction --no-ansi
err "Published package to pypi.org."
}
main() {
if [[ "${1:-}" != "--inside-container" ]]; then
run_outside_container "$@"
return
fi
publish_inside_container "$@"
}
main "$@"