fetchurl-sdk 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,12 +18,10 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  permissions:
20
20
  contents: write
21
- # Trusted publishing (PyPI) — enable if you configure OIDC on PyPI instead of UV_PUBLISH_TOKEN
22
21
  id-token: write
23
22
  steps:
24
23
  - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
25
24
  with:
26
- # svu needs full history + tags
27
25
  fetch-depth: 0
28
26
 
29
27
  - name: Setup git config
@@ -46,25 +44,14 @@ jobs:
46
44
  run: uv run --extra test python -m unittest test_fetchurl_integration.py
47
45
  continue-on-error: true
48
46
 
49
- - name: Bump version (svu)
47
+ - name: Prepare release (svu, commit, local tag)
50
48
  if: github.event_name == 'workflow_dispatch'
51
49
  env:
52
50
  NEW_VERSION: ${{ github.event.inputs.new_version }}
53
51
  run: |
54
- VERSION="$(NO_TAG=1 ./make_release "$NEW_VERSION")"
52
+ VERSION="$(./make_release prepare "$NEW_VERSION")"
55
53
  echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
56
- echo "New version: $VERSION (from svu $NEW_VERSION)" >> "$GITHUB_STEP_SUMMARY"
57
-
58
- - name: Create GitHub release
59
- if: env.RELEASE_VERSION != ''
60
- env:
61
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62
- TAG: ${{ env.RELEASE_VERSION }}
63
- run: |
64
- git tag "$TAG"
65
- git push origin "$TAG"
66
- git push origin HEAD:main
67
- gh release create "$TAG" --title "Release $TAG" --generate-notes
54
+ echo "Prepared $VERSION (not pushed until publish succeeds)" >> "$GITHUB_STEP_SUMMARY"
68
55
 
69
56
  - name: Build
70
57
  if: env.RELEASE_VERSION != ''
@@ -81,3 +68,9 @@ jobs:
81
68
  else
82
69
  uv publish --token "$UV_PUBLISH_TOKEN"
83
70
  fi
71
+
72
+ - name: Push commit, tag, and GitHub release
73
+ if: env.RELEASE_VERSION != ''
74
+ env:
75
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
+ run: ./make_release push "$RELEASE_VERSION"
@@ -0,0 +1 @@
1
+ __pycache__/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fetchurl-sdk
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Protocol-level client SDK for fetchurl content-addressable cache servers
5
5
  Project-URL: Homepage, https://pypi.org/project/fetchurl-sdk/
6
6
  Project-URL: Repository, https://github.com/fetchurl/sdk-python
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env -S python3 -u
2
+ """Bump version (svu), commit + tag locally. Push only via `push` after publish succeeds."""
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import re
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ ROOT = Path(__file__).resolve().parent
12
+ MANIFEST = ROOT / "pyproject.toml"
13
+ MANIFEST_PATHS = [str(MANIFEST.relative_to(ROOT))]
14
+ SVU_MODES = frozenset({"next", "major", "minor", "patch"})
15
+ UPLOAD_GLOB: str | None = None
16
+ VERSION_RE = re.compile(r'^version\s*=\s*"[^"]*"', re.M)
17
+
18
+
19
+ def log(msg: str) -> None:
20
+ print(msg, file=sys.stderr)
21
+
22
+
23
+ def run(cmd: list[str], *, check: bool = True, capture: bool = False) -> subprocess.CompletedProcess:
24
+ return subprocess.run(cmd, cwd=ROOT, check=check, text=True, capture_output=capture)
25
+
26
+
27
+ def run_out(cmd: list[str]) -> str:
28
+ return run(cmd, capture=True).stdout.strip()
29
+
30
+
31
+ def resolve_version(mode: str) -> str:
32
+ mode = mode.lstrip("v")
33
+ if mode in SVU_MODES:
34
+ return run_out(["svu", mode]).lstrip("v")
35
+ return mode
36
+
37
+
38
+ def write_manifest(version: str) -> None:
39
+ text = MANIFEST.read_text(encoding="utf-8")
40
+ if not VERSION_RE.search(text):
41
+ raise SystemExit('version = "..." not found in pyproject.toml')
42
+ MANIFEST.write_text(VERSION_RE.sub(f'version = "{version}"', text, count=1), encoding="utf-8")
43
+
44
+
45
+ def read_manifest_version() -> str:
46
+ m = re.search(r'^version\s*=\s*"([^"]+)"', MANIFEST.read_text(encoding="utf-8"), re.M)
47
+ if not m:
48
+ raise SystemExit("could not read version from pyproject.toml")
49
+ return m.group(1)
50
+
51
+ def git_commit_and_tag(version: str, paths: list[str]) -> None:
52
+ # Never let git write to stdout — CI captures only the version line from prepare.
53
+ if paths:
54
+ run(["git", "add", *paths], capture=True)
55
+ else:
56
+ run(["git", "add", "-A"], capture=True)
57
+ staged = run(["git", "diff", "--cached", "--quiet"], check=False, capture=True)
58
+ if staged.returncode != 0:
59
+ cp = run(["git", "commit", "-sm", f"bump to {version}"], capture=True)
60
+ if cp.stdout:
61
+ log(cp.stdout.rstrip())
62
+ if cp.stderr:
63
+ log(cp.stderr.rstrip())
64
+ else:
65
+ log("nothing to commit (manifest unchanged?)")
66
+ exists = run(["git", "rev-parse", "-q", "--verify", f"refs/tags/{version}"], check=False, capture=True)
67
+ if exists.returncode == 0:
68
+ run(["git", "tag", "-f", version], capture=True)
69
+ log(f"moved local tag {version}")
70
+ else:
71
+ run(["git", "tag", version], capture=True)
72
+ log(f"created local tag {version}")
73
+
74
+
75
+ def push_release(version: str, *, upload_glob: str | None = None) -> None:
76
+ """Push branch + tag and create GitHub release. Call only after registry publish succeeds."""
77
+ branch = run_out(["git", "rev-parse", "--abbrev-ref", "HEAD"])
78
+ for cmd in (
79
+ ["git", "push", "origin", f"HEAD:{branch}"],
80
+ ["git", "push", "origin", version],
81
+ ):
82
+ cp = run(cmd, capture=True)
83
+ if cp.stdout:
84
+ log(cp.stdout.rstrip())
85
+ if cp.stderr:
86
+ log(cp.stderr.rstrip())
87
+ chk = run(["gh", "release", "view", version], check=False, capture=True)
88
+ if chk.returncode == 0:
89
+ log(f"GitHub release {version} already exists")
90
+ else:
91
+ cp = run(
92
+ [
93
+ "gh",
94
+ "release",
95
+ "create",
96
+ version,
97
+ "--title",
98
+ f"Release {version}",
99
+ "--generate-notes",
100
+ ],
101
+ capture=True,
102
+ )
103
+ if cp.stdout:
104
+ log(cp.stdout.rstrip())
105
+ if cp.stderr:
106
+ log(cp.stderr.rstrip())
107
+ if upload_glob:
108
+ paths = sorted(ROOT.glob(upload_glob))
109
+ if paths:
110
+ cp = run(
111
+ ["gh", "release", "upload", version, *[str(p) for p in paths], "--clobber"],
112
+ capture=True,
113
+ )
114
+ if cp.stdout:
115
+ log(cp.stdout.rstrip())
116
+ if cp.stderr:
117
+ log(cp.stderr.rstrip())
118
+ log(f"pushed commit + tag + release {version}")
119
+
120
+
121
+ def build_parser() -> argparse.ArgumentParser:
122
+ p = argparse.ArgumentParser(
123
+ prog="./make_release",
124
+ description=(
125
+ "Bump version with svu, commit and tag locally. "
126
+ "Push commit/tag/GitHub release only via the push subcommand "
127
+ "(run after a successful registry publish)."
128
+ ),
129
+ )
130
+ sub = p.add_subparsers(dest="command", required=True)
131
+
132
+ prep = sub.add_parser(
133
+ "prepare",
134
+ help="svu → write manifest → local commit + local tag (no remote push)",
135
+ )
136
+ prep.add_argument(
137
+ "mode",
138
+ nargs="?",
139
+ default="next",
140
+ help="svu mode (next|major|minor|patch) or explicit x.y.z (default: next)",
141
+ )
142
+
143
+ push_p = sub.add_parser(
144
+ "push",
145
+ help="push branch + tag and create GitHub release (after successful publish)",
146
+ )
147
+ push_p.add_argument(
148
+ "version",
149
+ nargs="?",
150
+ default=None,
151
+ help="semver to push (default: version from manifest)",
152
+ )
153
+
154
+ for mode in sorted(SVU_MODES):
155
+ sp = sub.add_parser(mode, help=f"shorthand for: prepare {mode}")
156
+ sp.set_defaults(command="prepare", mode=mode)
157
+
158
+ return p
159
+
160
+
161
+ def main(argv: list[str] | None = None) -> int:
162
+ parser = build_parser()
163
+ args_list = list(sys.argv[1:] if argv is None else argv)
164
+ # Bare semver → prepare <semver>
165
+ if (
166
+ args_list
167
+ and args_list[0] not in ("prepare", "push", "-h", "--help")
168
+ and args_list[0] not in SVU_MODES
169
+ and re.fullmatch(r"v?\d+\.\d+\.\d+", args_list[0])
170
+ ):
171
+ args_list = ["prepare", args_list[0].lstrip("v"), *args_list[1:]]
172
+
173
+ args = parser.parse_args(args_list)
174
+
175
+ if args.command == "prepare":
176
+ version = resolve_version(args.mode)
177
+ write_manifest(version)
178
+ git_commit_and_tag(version, MANIFEST_PATHS)
179
+ print(version)
180
+ return 0
181
+
182
+ if args.command == "push":
183
+ version = (args.version or read_manifest_version()).lstrip("v")
184
+ push_release(version, upload_glob=UPLOAD_GLOB)
185
+ print(version)
186
+ return 0
187
+
188
+ parser.error(f"unknown command {args.command!r}")
189
+ return 2
190
+
191
+
192
+ if __name__ == "__main__":
193
+ sys.exit(main())
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "fetchurl-sdk"
7
- version = "0.2.1"
7
+ version = "0.2.2"
8
8
  description = "Protocol-level client SDK for fetchurl content-addressable cache servers"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- # Usage: ./make_release [next|major|minor|patch|<x.y.z>]
5
- # Only the semver is printed on stdout; everything else goes to stderr.
6
- MODE="${1:-next}"
7
-
8
- case "$MODE" in
9
- next|major|minor|patch)
10
- VERSION="$(svu "$MODE")"
11
- ;;
12
- *)
13
- VERSION="${MODE#v}"
14
- ;;
15
- esac
16
- VERSION="${VERSION#v}"
17
-
18
- sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
19
- git add pyproject.toml
20
-
21
- git commit -sm "bump to $VERSION" 1>&2 || true
22
- if [[ ! -v NO_TAG ]]; then
23
- git tag "$VERSION"
24
- git push origin "$VERSION" 1>&2
25
- fi
26
- git push origin HEAD 1>&2
27
-
28
- printf '%s\n' "$VERSION"
File without changes
File without changes
File without changes
File without changes
File without changes