From 84c5eb571cfcd7af500e23c13ed0bfab12ecabf0 Mon Sep 17 00:00:00 2001 From: Aleksandr Bogomiakov Date: Fri, 20 Nov 2026 13:54:34 +0000 Subject: [PATCH] Release podcast crates and publish workspace versions from tag CI --- .github/workflows/ci.yml | 1 + .github/workflows/publish.yml | 48 +++++++++++++++++++++ CHANGELOG.md | 13 +++++- README.md | 39 +++++++++++++++-- scripts/publish_crates.py | 78 ++++++++++++++++++++++++++++++++++ scripts/test_publish_crates.py | 48 +++++++++++++++++++++ 6 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 scripts/publish_crates.py create mode 100644 scripts/test_publish_crates.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ceb2386..cece9b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: toolchain: "1.97" components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 + - run: python3 -m unittest discover -s scripts -p 'test_*.py' - run: cargo fmt --all -- --check - run: cargo check --workspace --all-targets --all-features - run: cargo clippy --workspace --all-targets --all-features -- -D warnings diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..71d6ff1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,48 @@ +name: Publish crates + +on: + push: + tags: + - "v[0-9]*" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: crates-io-publish + cancel-in-progress: false + +env: + CARGO_TERM_COLOR: always + CARGO_NET_RETRY: 10 + +jobs: + publish: + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + - name: Check registry credentials + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + if [ -z "$CARGO_REGISTRY_TOKEN" ]; then + echo "::error::Add the CARGO_REGISTRY_TOKEN repository Actions secret, then rerun this workflow." + exit 1 + fi + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: "1.97" + components: rustfmt, clippy + - uses: Swatinem/rust-cache@v2 + - run: python3 -m unittest discover -s scripts -p 'test_*.py' + - run: cargo fmt --all -- --check + - run: cargo check --workspace --all-targets --all-features --locked + - run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings + - run: cargo test --workspace --locked + - name: Publish unpublished workspace versions + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: python3 scripts/publish_crates.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c7d23..8196c14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Changelog -## Unreleased — podcast discovery (`podcast_dht`) +## v0.6.0 — 2026-11-20 + +Releases `music-dht 0.6.0` and `furumi-library 0.3.0`. +`federation-net` remains at `0.3.1`. + +- Tag-driven CI publishes every unpublished workspace crate version to + crates.io, in dependency order; already published versions are skipped on + retries. Authentication uses the `CARGO_REGISTRY_TOKEN` Actions secret. + +### Podcast discovery (`podcast_dht`) - `music-dht 0.6.0`: new `music_dht::podcast_dht` overlay for public podcast discovery on its own ALPN `furumi-fd/podcast-dht/1` (version 1) and its own @@ -38,7 +47,7 @@ - The music DHT (`music-dht-v5`), `federation-net` and device-sync protocol v4 are unchanged. See "Public discovery (podcast_dht)" in `PODCASTS.md`. -## Unreleased — podcast contract +### Podcast contract and storage - `music-dht 0.6.0` (breaking): new `music_dht::podcast` module with the shared podcast contract: canonical `FeedUrl`, `PodcastId`/`EpisodeId` derivation diff --git a/README.md b/README.md index f443ffa..d453d6f 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,13 @@ crates/ ## Using the libraries -Until crates are published to a registry, depend on the repository directly: +Use the published crates from crates.io: ```toml [dependencies] -federation-net = { git = "https://gt.hexor.cy/ab/frid.git" } -music-dht = { git = "https://gt.hexor.cy/ab/frid.git" } -furumi-library = { git = "https://gt.hexor.cy/ab/frid.git" } +federation-net = "0.3.1" +music-dht = "0.6.0" +furumi-library = "0.3.0" ``` Start with the crate documentation: @@ -80,6 +80,37 @@ The integration tests open real local sockets and establish iroh connections. Some rendezvous tests also use public discovery infrastructure, so a restricted sandbox may need explicit network permission. +## Publishing + +Add one repository Actions secret named `CARGO_REGISTRY_TOKEN`, containing a +crates.io API token with publish access to `federation-net`, `music-dht` and +`furumi-library`. No registry username or Gitea token secret is needed. + +Update changed crate versions, workspace dependency requirements, `Cargo.lock` +and `CHANGELOG.md`, then merge to `main`. Create `-v` tags for +the changed crates and one workspace release tag, for example: + +```bash +git tag -a music-dht-v0.6.0 -m 'music-dht 0.6.0' +git tag -a furumi-library-v0.3.0 -m 'furumi-library 0.3.0' +git tag -a v0.6.0 -m 'Frid podcast release' +git push origin music-dht-v0.6.0 furumi-library-v0.3.0 v0.6.0 +``` + +Only the `v*` workspace tag triggers `.github/workflows/publish.yml`; the +crate tags identify each package release without starting duplicate uploads. +The workflow runs the workspace checks, selects every publishable workspace +crate whose exact version is absent from the crates.io sparse index, and lets +Cargo verify and publish the selected packages in dependency order. Versions +already published are skipped, so rerunning a partially completed release is +safe. A registry lookup error fails the release instead of assuming absence. + +Preview the selection with `python3 scripts/publish_crates.py --plan`, or +verify the packages without uploading with `--dry-run`. If the secret was +missing or a publish failed, fix the cause and rerun the existing tag workflow; +do not move release tags. Manual dispatch must select the release tag as its +ref. Publication is performed by CI, not by the tagging commands above. + ## License Frid is released under the diff --git a/scripts/publish_crates.py b/scripts/publish_crates.py new file mode 100644 index 0000000..c8dee81 --- /dev/null +++ b/scripts/publish_crates.py @@ -0,0 +1,78 @@ +"""Publish missing workspace versions together; Cargo orders their dependencies.""" + +import argparse +import json +import os +import subprocess +import urllib.error +import urllib.request + + +def index_path(name): + name = name.lower() + if len(name) < 3: + return f"{len(name)}/{name}" + if len(name) == 3: + return f"3/{name[0]}/{name}" + return f"{name[:2]}/{name[2:4]}/{name}" + + +def is_published(name, version): + request = urllib.request.Request( + f"https://index.crates.io/{index_path(name)}", + headers={"User-Agent": "frid-release-ci", "Cache-Control": "no-cache"}, + ) + try: + with urllib.request.urlopen(request, timeout=60) as response: + versions = [json.loads(line) for line in response.read().splitlines()] + except urllib.error.HTTPError as error: + if error.code == 404: + return False + raise + return any(row["vers"] == version for row in versions) + + +def unpublished_packages(metadata): + members = set(metadata["workspace_members"]) + packages = [] + for package in sorted(metadata["packages"], key=lambda item: item["name"]): + registries = package["publish"] + if package["id"] not in members or ( + registries is not None and "crates-io" not in registries + ): + continue + name, version = package["name"], package["version"] + if is_published(name, version): + print(f"Skip {name} {version}: already published", flush=True) + else: + print(f"Publish {name} {version}", flush=True) + packages.append(name) + return packages + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--plan", action="store_true", help="list packages without publishing") + parser.add_argument("--dry-run", action="store_true", help="verify packages without uploading") + args = parser.parse_args() + if not (args.plan or args.dry_run) and not os.environ.get("CARGO_REGISTRY_TOKEN"): + parser.error("CARGO_REGISTRY_TOKEN must be set for publishing") + metadata = json.loads(subprocess.check_output( + ["cargo", "metadata", "--no-deps", "--format-version", "1", "--locked"], + text=True, + )) + packages = unpublished_packages(metadata) + if args.plan or not packages: + return + command = ["cargo", "publish", "--registry", "crates-io", "--locked", "--all-features"] + for name in packages: + command.extend(["--package", name]) + if args.dry_run: + command.append("--dry-run") + # Multi-package publishing verifies against a temporary local registry, + # then uploads and waits for dependencies to appear before their users. + subprocess.run(command, check=True) + + +if __name__ == "__main__": + main() diff --git a/scripts/test_publish_crates.py b/scripts/test_publish_crates.py new file mode 100644 index 0000000..2557f95 --- /dev/null +++ b/scripts/test_publish_crates.py @@ -0,0 +1,48 @@ +import io +import unittest +import urllib.error +from contextlib import redirect_stdout +from unittest.mock import MagicMock, patch + +import publish_crates + + +class PublishCratesTests(unittest.TestCase): + def test_existing_and_private_versions_are_excluded_on_retry(self): + packages = [ + {"id": "net", "name": "federation-net", "version": "0.3.1", "publish": None}, + {"id": "dht", "name": "music-dht", "version": "0.6.0", "publish": None}, + {"id": "lib", "name": "furumi-library", "version": "0.3.0", "publish": None}, + {"id": "demo", "name": "demo", "version": "0.1.0", "publish": []}, + {"id": "internal", "name": "internal", "version": "0.1.0", "publish": ["private"]}, + {"id": "external", "name": "external", "version": "0.1.0", "publish": None}, + ] + metadata = {"packages": packages, "workspace_members": [p["id"] for p in packages[:-1]]} + for published, expected in [ + ({"federation-net"}, ["furumi-library", "music-dht"]), + ({"federation-net", "music-dht"}, ["furumi-library"]), + ]: + with self.subTest(published=published), redirect_stdout(io.StringIO()): + with patch.object(publish_crates, "is_published", side_effect=lambda name, _: name in published): + self.assertEqual(publish_crates.unpublished_packages(metadata), expected) + + def test_registry_errors_do_not_look_like_unpublished_versions(self): + for status in (403, 429, 500): + error = urllib.error.HTTPError("https://index.crates.io/test", status, "error", {}, None) + with self.subTest(status=status), patch.object(publish_crates.urllib.request, "urlopen", side_effect=error): + with self.assertRaises(urllib.error.HTTPError): + publish_crates.is_published("music-dht", "0.6.0") + + def test_missing_crate_and_existing_version(self): + error = urllib.error.HTTPError("https://index.crates.io/test", 404, "missing", {}, None) + with patch.object(publish_crates.urllib.request, "urlopen", side_effect=error): + self.assertFalse(publish_crates.is_published("new-crate", "0.1.0")) + response = MagicMock() + response.__enter__.return_value.read.return_value = b'{"vers":"0.6.0","yanked":false}\n' + with patch.object(publish_crates.urllib.request, "urlopen", return_value=response): + self.assertTrue(publish_crates.is_published("music-dht", "0.6.0")) + self.assertFalse(publish_crates.is_published("music-dht", "0.7.0")) + + +if __name__ == "__main__": + unittest.main()