from pathlib import Path


LEGACY_WORKFLOW = Path(".gitea/workflows/release.yml")
CI_WORKFLOW = Path(".gitea/workflows/ci.yml")
STALE_MANIFEST = Path("release/manifest.json")


def test_independent_release_workflow_is_removed():
    assert not LEGACY_WORKFLOW.exists()


def test_stale_static_release_manifest_is_removed():
    assert not STALE_MANIFEST.exists()


def test_ci_publishes_a_draft_before_exposing_assets():
    text = CI_WORKFLOW.read_text()
    release = text[text.index("  release-candidate:") :]
    create_draft = release.index('"draft":true')
    upload_asset = release.index("/assets?name=")
    publish = release.index('"draft":false')

    assert create_draft < upload_asset < publish
    assert '"prerelease":true' in release
    assert 'TARGET="${{ github.sha }}"' in release
    assert "curl --fail-with-body" in release
    assert "|| true" not in release
