diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-10-08 05:01:59 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-10-08 05:01:59 +0200 |
| commit | e1f5e40da0dd3f0613e61191a4d655da07381595 (patch) | |
| tree | d19f776566cf9673bb93db05eff66dbb724f4258 | |
| parent | d059ca1fc0d2e67d542dbaf823c280b3a24675a8 (diff) | |
| download | ele-e1f5e40da0dd3f0613e61191a4d655da07381595.tar.gz ele-e1f5e40da0dd3f0613e61191a4d655da07381595.zip | |
Remove GitHub release automation and prepare v0.3.0v0.3.0
| -rw-r--r-- | .github/workflows/ci.yml.disabled | 58 | ||||
| -rw-r--r-- | .github/workflows/release.yml | 241 | ||||
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | scripts/release.py | 155 | ||||
| -rw-r--r-- | scripts/test_release.py | 163 |
6 files changed, 3 insertions, 620 deletions
diff --git a/.github/workflows/ci.yml.disabled b/.github/workflows/ci.yml.disabled deleted file mode 100644 index ad4403e..0000000 --- a/.github/workflows/ci.yml.disabled +++ /dev/null @@ -1,58 +0,0 @@ -name: CI - -on: - push: - pull_request: - workflow_dispatch: - workflow_call: - -permissions: - contents: read - -jobs: - test: - name: Test (${{ matrix.os }}, Rust ${{ matrix.rust }}) - runs-on: ${{ matrix.os }} - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - rust: [stable] - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - persist-credentials: false - - name: Install Rust - run: rustup toolchain install ${{ matrix.rust }} --profile minimal - - name: Test default dependencies - run: cargo +${{ matrix.rust }} test --locked - - name: Test arbitrary-precision JSON compatibility - run: cargo +${{ matrix.rust }} test --locked --features serde_json/arbitrary_precision - - name: Test release build - run: cargo +${{ matrix.rust }} test --release --locked - - quality: - runs-on: ubuntu-latest - timeout-minutes: 20 - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - persist-credentials: false - - name: Install Rust tools - run: rustup toolchain install stable --profile minimal --component rustfmt --component clippy - - name: Test release automation - run: python3 -B -m unittest discover -s scripts -p 'test_*.py' - - name: Check formatting - run: cargo +stable fmt --all -- --check - - name: Check lints - run: cargo +stable clippy --all-targets --locked -- -D warnings - - name: Check feature compatibility lints - run: cargo +stable clippy --all-targets --locked --features serde_json/arbitrary_precision -- -D warnings - - name: Verify package - run: cargo +stable package --locked - - name: Test packaged crate - shell: bash - run: | - package=$(cargo +stable metadata --no-deps --format-version 1 | python3 -c 'import json, sys; p = json.load(sys.stdin)["packages"][0]; print(p["name"] + "-" + p["version"])') - cargo +stable test --locked --manifest-path "target/package/$package/Cargo.toml" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 7f58703..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,241 +0,0 @@ -name: release - -on: - workflow_dispatch: - inputs: - version: - description: Version impact (the first release is 0.1.0 or X.0.0) - required: true - default: patch - type: choice - options: [minor, patch] - dry_run: - description: Build and test artifacts without pushing or publishing - required: true - default: true - type: boolean - -concurrency: - group: release-${{ github.ref_name }} - cancel-in-progress: false - -permissions: - contents: read - -defaults: - run: - shell: bash - -env: - RELEASE_RUST: stable - -jobs: - prepare: - runs-on: ubuntu-24.04 - timeout-minutes: 15 - outputs: - version: ${{ steps.version.outputs.version }} - tag: ${{ steps.version.outputs.tag }} - commit: ${{ steps.version.outputs.commit }} - base: ${{ steps.version.outputs.base }} - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - fetch-depth: 0 - persist-credentials: false - - name: Require a release branch - env: - REF_TYPE: ${{ github.ref_type }} - RELEASE_BRANCH: ${{ github.ref_name }} - run: | - test "$REF_TYPE" = branch - python3 -B -c 'import sys; sys.path.insert(0, "scripts"); from release import branch_major; branch_major(sys.argv[1])' "$RELEASE_BRANCH" - - name: Install Rust - run: rustup toolchain install "$RELEASE_RUST" --profile minimal - - name: Select release toolchain - run: rustup override set "$RELEASE_RUST" - - name: Test release automation - run: python3 -B -m unittest discover -s scripts -p 'test_*.py' - - name: Prepare version and source bundle - id: version - env: - RELEASE_BRANCH: ${{ github.ref_name }} - IMPACT: ${{ inputs.version }} - run: | - python3 -B scripts/release.py prepare --branch "$RELEASE_BRANCH" --impact "$IMPACT" \ - --bundle target/release-source.bundle --output "$GITHUB_OUTPUT" - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 - with: - name: release-source - path: target/release-source.bundle - if-no-files-found: error - retention-days: 7 - overwrite: true - - build: - needs: prepare - runs-on: ${{ matrix.os }} - timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - include: - - os: ubuntu-24.04 - target: x86_64-unknown-linux-musl - binary: ele - - os: macos-15 - target: aarch64-apple-darwin - binary: ele - - os: windows-latest - target: x86_64-pc-windows-msvc - binary: ele.exe - env: - TARGET: ${{ matrix.target }} - BINARY: ${{ matrix.binary }} - VERSION: ${{ needs.prepare.outputs.version }} - RELEASE_COMMIT: ${{ needs.prepare.outputs.commit }} - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - persist-credentials: false - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 - with: - name: release-source - path: target/release-input - - name: Check out versioned source - run: | - git fetch target/release-input/release-source.bundle HEAD - test "$(git rev-parse FETCH_HEAD)" = "$RELEASE_COMMIT" - git checkout --detach "$RELEASE_COMMIT" - - name: Install Rust - run: rustup toolchain install "$RELEASE_RUST" --profile minimal --target "$TARGET" - - name: Select release toolchain - run: rustup override set "$RELEASE_RUST" - - name: Set macOS deployment target - if: runner.os == 'macOS' - run: echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "$GITHUB_ENV" - - name: Test release target - run: | - cargo test --locked --target "$TARGET" - cargo test --locked --target "$TARGET" --features serde_json/arbitrary_precision - cargo test --release --locked --target "$TARGET" - - name: Build and check CLI - run: | - cargo build --release --locked --target "$TARGET" - binary="target/$TARGET/release/$BINARY" - test "$("$binary" --version)" = "ele $VERSION" - printf '{"n":1}\n{"n":2}\n' | "$binary" 'n > 1' > target/smoke.jsonl - printf '{"n":2}\n' > target/expected.jsonl - cmp target/expected.jsonl target/smoke.jsonl - - name: Verify static Linux executable - if: runner.os == 'Linux' - run: | - readelf -l "target/$TARGET/release/ele" > target/elf-headers - if grep -q INTERP target/elf-headers; then - echo 'The Linux executable requires a dynamic loader.' >&2 - exit 1 - fi - - name: Archive CLI - if: runner.os != 'Windows' - run: | - mkdir -p target/release-dist - COPYFILE_DISABLE=1 tar -czf "target/release-dist/ele-v$VERSION-$TARGET.tar.gz" \ - -C "target/$TARGET/release" ele -C "$GITHUB_WORKSPACE" LICENSE README.md - - name: Archive Windows CLI - if: runner.os == 'Windows' - run: | - mkdir -p target/release-dist - python -m zipfile -c "target/release-dist/ele-v$VERSION-$TARGET.zip" \ - "target/$TARGET/release/$BINARY" LICENSE README.md - - name: Verify library package - if: runner.os == 'Linux' - run: | - cargo package --locked - cargo test --locked --manifest-path "target/package/ele-$VERSION/Cargo.toml" - cp "target/package/ele-$VERSION.crate" target/release-dist/ - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 - with: - name: release-assets-${{ matrix.target }} - path: target/release-dist/* - if-no-files-found: error - retention-days: 7 - compression-level: 0 - overwrite: true - - publish: - needs: [prepare, build] - runs-on: ubuntu-24.04 - timeout-minutes: 15 - permissions: - contents: write - env: - RELEASE_BRANCH: ${{ github.ref_name }} - VERSION: ${{ needs.prepare.outputs.version }} - TAG: ${{ needs.prepare.outputs.tag }} - BASE: ${{ needs.prepare.outputs.base }} - RELEASE_COMMIT: ${{ needs.prepare.outputs.commit }} - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - fetch-depth: 0 - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 - with: - name: release-source - path: target/release-input - - name: Check out tested source - run: | - git fetch target/release-input/release-source.bundle HEAD - test "$(git rev-parse FETCH_HEAD)" = "$RELEASE_COMMIT" - git checkout --detach "$RELEASE_COMMIT" - - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 - with: - pattern: release-assets-* - merge-multiple: true - path: target/release-dist - - name: Verify asset set and generate checksums - run: | - test -f "target/release-dist/ele-v$VERSION-x86_64-unknown-linux-musl.tar.gz" - test -f "target/release-dist/ele-v$VERSION-aarch64-apple-darwin.tar.gz" - test -f "target/release-dist/ele-v$VERSION-x86_64-pc-windows-msvc.zip" - test -f "target/release-dist/ele-$VERSION.crate" - test "$(find target/release-dist -maxdepth 1 -type f | wc -l)" -eq 4 - cd target/release-dist - sha256sum *.tar.gz *.zip *.crate > SHA256SUMS - sha256sum --check SHA256SUMS - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 - with: - name: release-downloads - path: target/release-dist/* - if-no-files-found: error - retention-days: 7 - compression-level: 0 - overwrite: true - - name: Push tested release references - if: ${{ !inputs.dry_run }} - run: | - python3 -B scripts/release.py push --branch "$RELEASE_BRANCH" \ - --version "$VERSION" --base "$BASE" --commit "$RELEASE_COMMIT" - - name: Publish GitHub release - if: ${{ !inputs.dry_run }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - if draft=$(gh release view "$TAG" --json isDraft --jq '.isDraft'); then - if test "$draft" != true; then - echo 'The release is already public; refusing to replace its assets.' >&2 - exit 1 - fi - else - gh release create "$TAG" --verify-tag --draft --generate-notes --title "$TAG" --target "$RELEASE_COMMIT" - fi - gh release upload "$TAG" target/release-dist/* --clobber - # REST release-by-tag lookups exclude draft releases. - release_id=$(gh release view "$TAG" --json databaseId --jq '.databaseId') - gh api --method PATCH "repos/$GITHUB_REPOSITORY/releases/$release_id" \ - -F draft=false -f make_latest=legacy > /dev/null - - name: Record result - env: - DRY_RUN: ${{ inputs.dry_run }} - run: | - printf 'Version: `%s`\n\nCommit: `%s`\n\nDry run: `%s`\n\nDownload the `release-downloads` artifact for the CLI archives, Cargo source package, and SHA256SUMS.\n' \ - "$TAG" "$RELEASE_COMMIT" "$DRY_RUN" >> "$GITHUB_STEP_SUMMARY" @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "ele" -version = "0.1.1" +version = "0.3.0" dependencies = [ "regex", "serde_json", @@ -1,11 +1,11 @@ [package] name = "ele" -version = "0.1.1" +version = "0.3.0" edition = "2024" rust-version = "1.88" license = "MIT" description = "AIP-160-style filtering for Rust values and newline-delimited JSON" -repository = "https://github.com/tetsuo/ele" +repository = "https://git.onurgunduz.com/ele" documentation = "https://docs.rs/ele" readme = "README.md" keywords = ["aip-160", "filter", "json", "cli"] diff --git a/scripts/release.py b/scripts/release.py deleted file mode 100644 index 9ee1e80..0000000 --- a/scripts/release.py +++ /dev/null @@ -1,155 +0,0 @@ -"""Prepare versioned source bundles and publish tested Git references.""" - -import argparse -import copy -from pathlib import Path -import re -import subprocess -import tomllib - -VERSION = r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)" - - -def run(*args): - return subprocess.check_output(args, text=True).strip() - - -def branch_major(branch): - match = re.fullmatch(r"v(0|[1-9][0-9]*)\.x", branch) - if not match: - raise ValueError("release branch must be named vX.x, for example v0.x") - return int(match[1]) - - -def version_tuple(version): - match = re.fullmatch(VERSION, version) - if not match: - raise ValueError(f"expected a stable major.minor.patch version: {version}") - return tuple(map(int, match.groups())) - - -def next_version(branch, impact, tags): - major = branch_major(branch) - if impact not in ("patch", "minor"): - raise ValueError("impact must be patch or minor") - versions = [ - version_tuple(tag[1:]) for tag in tags - if re.fullmatch("v" + VERSION, tag) and version_tuple(tag[1:])[0] == major - ] - if not versions: - return f"{major}.{1 if major == 0 else 0}.0" - _, minor, patch = max(versions) - return f"{major}.{minor + 1}.0" if impact == "minor" else f"{major}.{minor}.{patch + 1}" - - -def require_ancestor(ancestor, commit): - subprocess.run(["git", "merge-base", "--is-ancestor", ancestor, commit], check=True) - - -def set_version(version): - manifest = Path("Cargo.toml") - text = manifest.read_text() - package = tomllib.loads(text)["package"] - if package["name"] != "ele": - raise ValueError("expected the ele package") - current = package["version"] - if version_tuple(current) > version_tuple(version): - raise ValueError(f"manifest version {current} exceeds the planned release {version}") - if current == version: - return - section = re.search(r"(?ms)^\[package\]\n.*?(?=^\[|\Z)", text) - if not section: - raise ValueError("expected an explicit [package] section") - body, count = re.subn(r'(?m)^version\s*=\s*"[^"]+"', f'version = "{version}"', section[0]) - if count != 1: - raise ValueError("expected one explicit package version") - expected_lock = copy.deepcopy(tomllib.loads(Path("Cargo.lock").read_text())) - packages = [p for p in expected_lock["package"] if p["name"] == "ele" and "source" not in p] - if len(packages) != 1 or packages[0]["version"] != current: - raise ValueError("manifest and lockfile versions must agree") - packages[0]["version"] = version - manifest.write_text(text[:section.start()] + body + text[section.end():]) - subprocess.run(["cargo", "update", "--workspace"], check=True) - if tomllib.loads(Path("Cargo.lock").read_text()) != expected_lock: - raise ValueError("version update changed dependencies; refusing to prepare a release") - - -def prepare(branch, impact, bundle): - branch_major(branch) - if run("git", "status", "--porcelain"): - raise ValueError("release preparation requires a clean working tree") - base = run("git", "rev-parse", "HEAD") - if any(re.fullmatch("v" + VERSION, tag) for tag in run("git", "tag", "--points-at", base).splitlines()): - raise ValueError("this commit already has a release tag; rerun a failed publish job to resume it") - tags = run("git", "tag", "--list").splitlines() - version = next_version(branch, impact, tags) - for tag in tags: - if re.fullmatch("v" + VERSION, tag) and version_tuple(tag[1:])[0] == branch_major(branch): - require_ancestor(tag, base) - set_version(version) - subprocess.run(["git", "add", "Cargo.toml", "Cargo.lock"], check=True) - if run("git", "diff", "--cached", "--name-only"): - subprocess.run([ - "git", "-c", "user.name=github-actions[bot]", - "-c", "user.email=41898282+github-actions[bot]@users.noreply.github.com", - "-c", "commit.gpgsign=false", "commit", "-m", f"Release v{version}", - ], check=True) - commit = run("git", "rev-parse", "HEAD") - bundle.parent.mkdir(parents=True, exist_ok=True) - subprocess.run(["git", "bundle", "create", str(bundle), "HEAD"], check=True) - return {"version": version, "tag": f"v{version}", "commit": commit, "base": base} - - -def push_refs(branch, version, base, commit): - if branch_major(branch) != version_tuple(version)[0]: - raise ValueError("release version does not belong to this branch") - require_ancestor(base, commit) - if run("git", "rev-parse", "HEAD") != commit: - raise ValueError("checkout does not match the tested release commit") - if tomllib.loads(Path("Cargo.toml").read_text())["package"]["version"] != version: - raise ValueError("manifest does not match the release version") - if run("git", "status", "--porcelain"): - raise ValueError("publishing requires a clean working tree") - tag = f"v{version}" - remote_tag = run("git", "ls-remote", "--tags", "origin", f"refs/tags/{tag}") - if remote_tag: - subprocess.run(["git", "fetch", "origin", f"refs/tags/{tag}"], check=True) - if run("git", "rev-parse", "FETCH_HEAD^{commit}") != commit: - raise ValueError("the remote tag belongs to a different commit") - return - remote_branch = run("git", "ls-remote", "--heads", "origin", f"refs/heads/{branch}") - if not remote_branch or remote_branch.split()[0] != base: - raise ValueError("release branch has moved; start a new workflow run from its current head") - subprocess.run(["git", "tag", tag, commit], check=True) - subprocess.run([ - "git", "push", "--atomic", "origin", - f"{commit}:refs/heads/{branch}", f"refs/tags/{tag}:refs/tags/{tag}", - ], check=True) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - commands = parser.add_subparsers(dest="command", required=True) - prepare_parser = commands.add_parser("prepare") - prepare_parser.add_argument("--branch", required=True) - prepare_parser.add_argument("--impact", choices=("patch", "minor"), required=True) - prepare_parser.add_argument("--bundle", type=Path, required=True) - prepare_parser.add_argument("--output", type=Path, required=True) - push_parser = commands.add_parser("push") - for name in ("branch", "version", "base", "commit"): - push_parser.add_argument(f"--{name}", required=True) - args = parser.parse_args() - try: - if args.command == "prepare": - outputs = prepare(args.branch, args.impact, args.bundle) - with args.output.open("a") as output: - for name, value in outputs.items(): - print(f"{name}={value}", file=output) - else: - push_refs(args.branch, args.version, args.base, args.commit) - except (ValueError, subprocess.CalledProcessError) as error: - parser.exit(1, f"release: {error}\n") - - -if __name__ == "__main__": - main() diff --git a/scripts/test_release.py b/scripts/test_release.py deleted file mode 100644 index 8718544..0000000 --- a/scripts/test_release.py +++ /dev/null @@ -1,163 +0,0 @@ -import os -from pathlib import Path -import subprocess -import tempfile -import tomllib -import unittest - -import release - -ROOT = Path(__file__).resolve().parent.parent - - -class VersionTests(unittest.TestCase): - def test_initial_versions_and_impacts(self): - self.assertEqual(release.next_version("v0.x", "patch", []), "0.1.0") - self.assertEqual(release.next_version("v1.x", "minor", []), "1.0.0") - tags = ["v0.9.9", "v0.10.2", "v0.10.10", "v1.3.0", "v0.11.0-rc.1", "other"] - self.assertEqual(release.next_version("v0.x", "patch", tags), "0.10.11") - self.assertEqual(release.next_version("v0.x", "minor", tags), "0.11.0") - self.assertEqual(release.next_version("v1.x", "patch", tags), "1.3.1") - - def test_invalid_inputs(self): - for branch in ["master", "v01.x", "v1.2.x", "v1.x\n", "v1.x;echo bad"]: - with self.subTest(branch=branch), self.assertRaises(ValueError): - release.next_version(branch, "patch", []) - with self.assertRaises(ValueError): - release.next_version("v0.x", "major", []) - for version in ["01.2.3", "1.2", "1.2.3-rc.1", "1.2.3+build"]: - with self.subTest(version=version), self.assertRaises(ValueError): - release.version_tuple(version) - - -class RepositoryTests(unittest.TestCase): - def setUp(self): - directory = ROOT / "target" / "release-script-tests" - directory.mkdir(parents=True, exist_ok=True) - self.temporary = tempfile.TemporaryDirectory(dir=directory) - self.addCleanup(self.temporary.cleanup) - self.previous = Path.cwd() - self.addCleanup(os.chdir, self.previous) - self.root = Path(self.temporary.name) - self.repo = self.root / "repo" - self.repo.mkdir() - os.chdir(self.repo) - release.run("git", "init", "-b", "v0.x") - release.run("git", "config", "user.name", "Release tests") - release.run("git", "config", "user.email", "release-tests@example.invalid") - release.run("git", "config", "commit.gpgsign", "false") - Path(".gitignore").write_text("target/\n") - Path("Cargo.toml").write_text( - '[package]\nname = "ele"\nversion = "0.1.0"\nedition = "2024"\n' - ) - Path("src").mkdir() - Path("src/lib.rs").write_text("pub fn example() {}\n") - release.run("cargo", "generate-lockfile", "--offline") - self.commit("Initial package") - self.remote = self.root / "origin.git" - release.run("git", "init", "--bare", "-b", "v0.x", str(self.remote)) - release.run("git", "remote", "add", "origin", str(self.remote)) - release.run("git", "push", "origin", "HEAD:refs/heads/v0.x") - - def commit(self, message): - release.run("git", "add", ".") - release.run("git", "commit", "-m", message) - return release.run("git", "rev-parse", "HEAD") - - def prepare(self, impact="patch"): - return release.prepare("v0.x", impact, Path("target/source.bundle")) - - def publish(self, result): - release.push_refs("v0.x", result["version"], result["base"], result["commit"]) - - def patch_source(self): - release.run("git", "tag", "v0.1.0") - release.run("git", "push", "origin", "v0.1.0") - Path("src/lib.rs").write_text("pub fn example() -> bool { true }\n") - self.commit("Change package") - release.run("git", "push", "origin", "HEAD:refs/heads/v0.x") - - def test_initial_prepare_has_no_remote_side_effects(self): - before = release.run("git", "ls-remote", "origin") - result = self.prepare() - self.assertEqual(result["version"], "0.1.0") - self.assertEqual(result["base"], result["commit"]) - self.assertEqual(release.run("git", "tag", "--list"), "") - self.assertEqual(release.run("git", "ls-remote", "origin"), before) - release.run("git", "bundle", "verify", "target/source.bundle") - self.assertEqual(release.run("git", "status", "--porcelain"), "") - - def test_patch_updates_manifest_lock_and_bundle_and_publishes_atomically(self): - self.patch_source() - before = release.run("git", "ls-remote", "origin") - result = self.prepare() - self.assertEqual(result["version"], "0.1.1") - self.assertNotEqual(result["base"], result["commit"]) - self.assertEqual(release.run("git", "ls-remote", "origin"), before) - self.assertEqual(tomllib.loads(Path("Cargo.toml").read_text())["package"]["version"], "0.1.1") - self.assertEqual(tomllib.loads(Path("Cargo.lock").read_text())["package"][0]["version"], "0.1.1") - release.run("cargo", "check", "--locked", "--offline") - clone = self.root / "from-bundle" - release.run("git", "clone", "target/source.bundle", str(clone)) - self.assertEqual(release.run("git", "-C", str(clone), "rev-parse", "HEAD"), result["commit"]) - self.publish(result) - refs = release.run("git", "ls-remote", "origin") - self.assertIn(result["commit"] + "\trefs/heads/v0.x", refs) - self.assertIn(result["commit"] + "\trefs/tags/v0.1.1", refs) - self.publish(result) - self.assertEqual(release.run("git", "ls-remote", "origin"), refs) - - def test_already_tagged_dirty_and_downgraded_versions_fail(self): - Path("untracked").write_text("not committed") - with self.assertRaises(ValueError): - self.prepare() - Path("untracked").unlink() - release.run("git", "tag", "v0.1.0") - with self.assertRaises(ValueError): - self.prepare() - release.run("git", "tag", "-d", "v0.1.0") - with self.assertRaises(ValueError): - release.set_version("0.0.9") - - def test_moved_branch_fails_without_a_tag(self): - result = self.prepare() - Path("new-file").write_text("new branch head") - advanced = self.commit("Advance branch") - release.run("git", "push", "origin", "HEAD:refs/heads/v0.x") - release.run("git", "checkout", "--detach", result["commit"]) - with self.assertRaises(ValueError): - self.publish(result) - self.assertEqual(release.run("git", "ls-remote", "--tags", "origin"), "") - self.assertIn(advanced, release.run("git", "ls-remote", "--heads", "origin")) - - def test_conflicting_remote_tag_fails(self): - self.patch_source() - result = self.prepare() - release.run("git", "tag", result["tag"], result["base"]) - release.run("git", "push", "origin", result["tag"]) - with self.assertRaises(ValueError): - self.publish(result) - - def test_unmerged_release_tags_fail(self): - base = release.run("git", "rev-parse", "HEAD") - Path("other-change").write_text("another release branch") - self.commit("Other branch") - release.run("git", "tag", "v0.2.0") - release.run("git", "checkout", "--detach", base) - with self.assertRaises(subprocess.CalledProcessError): - self.prepare() - - def test_atomic_push_does_not_advance_branch_when_tag_is_rejected(self): - self.patch_source() - result = self.prepare() - hook = self.remote / "hooks" / "update" - hook.write_text('#!/bin/sh\ncase "$1" in refs/tags/*) exit 1;; esac\n') - hook.chmod(0o755) - with self.assertRaises(subprocess.CalledProcessError): - self.publish(result) - self.assertIn(result["base"], release.run("git", "ls-remote", "--heads", "origin")) - self.assertEqual(release.run("git", "ls-remote", "--tags", "origin", result["tag"]), "") - - -if __name__ == "__main__": - unittest.main() |
