From 05975e50c6dab10a73d6cb15fd1d79290843b84b Mon Sep 17 00:00:00 2001 From: Ajimaru Date: Wed, 2 Dec 2026 16:51:22 +0100 Subject: [PATCH] chore: update release workflow and README for improved clarity and stability --- .github/workflows/release.yaml | 265 +++++++++++++-------------------- README.md | 13 +- 2 files changed, 109 insertions(+), 169 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 644d1a5..65b9811 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,183 +1,122 @@ name: Release +# A pushed tag builds the plugin and attaches it to a draft release, which is +# published by hand. Every plugin repo uses this workflow; only env differs. on: push: - tags: - - "v*" - # Bare numeric tags (0.2.0) are accepted too; the version guard below - # normalizes either form before comparing against pyproject.toml. - - "[0-9]*" + tags: ["v*", "[0-9]*"] -permissions: - contents: write # required to create a GitHub Release - -jobs: - # Build the wheel and verify it imports against both OctoPrint generations: - # 1.x (serial-only fallback path) and 2.x (connector framework path). - smoke: - name: Smoke-test (OctoPrint ${{ matrix.label }}) - # Pinned: this job runs Python 3.9 (the oldest supported version), which - # actions/setup-python no longer provides for ubuntu-latest (26.04). - runs-on: ubuntu-24.04 - strategy: - fail-fast: false - matrix: - include: - # Both generations are pinned explicitly and both gate the release: - # a failure in either leg blocks it. - - label: "1.x" - octoprint: "OctoPrint>=1.11,<2" - pre: "" - blocking: true - connectors: "False" - # Stable 2.x (2.0.0 shipped 2026-11-16). OctoPrint's circular import - # (octoprint.printer <-> octoprint.filemanager) is still present in - # 2.0.1; the plugin sidesteps it, and the smoke test below checks - # that the connector framework really survives a fresh import. - - label: "2.x" - octoprint: "OctoPrint>=2,<3" - pre: "" - blocking: true - connectors: "True" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false - steps: - - name: Checkout - uses: actions/checkout@v7 - - - name: Set up Python - uses: actions/setup-python@v7 - with: - python-version: "3.9" - - - name: Install build tooling - run: python -m pip install --upgrade pip build +permissions: + contents: write - - name: Build wheel - run: python -m build --wheel - - - name: Smoke-test the built wheel - # Non-blocking legs (matrix.blocking == false) report failures without - # failing the job, so the release's `needs: smoke` still succeeds. - continue-on-error: ${{ !matrix.blocking }} - run: | - python -m venv /tmp/smoke - /tmp/smoke/bin/pip install --upgrade pip - # OctoPrint provides the runtime deps (pyserial, octoprint.*) that the - # plugin imports; install the matrix version so the import check is - # meaningful for that generation. - /tmp/smoke/bin/pip install ${{ matrix.pre }} "${{ matrix.octoprint }}" - /tmp/smoke/bin/pip install dist/*.whl - /tmp/smoke/bin/python -c "import octoprint_autoconnectplus; print('import OK')" - # ConnectedPrinter is None on 1.x by design; on 2.x a None means the - # circular-import workaround failed and connector support is gone. - /tmp/smoke/bin/python -c "import octoprint_autoconnectplus as p; found = p.ConnectedPrinter is not None; print('connector framework', found); assert found == ${{ matrix.connectors }}" - /tmp/smoke/bin/python -c "from importlib.metadata import version; print('installed version', version('OctoPrint-AutoConnectPlus'))" +env: + # setup.py imports octoprint_setuptools, so those builds need OctoPrint installed. + BUILD_ARGS: "" + # Extra copy of the plugin zip under an old name that installed versions still + # download on update; empty once they all use the tag's source archive. + LEGACY_ZIP: "" +jobs: release: - name: Build and release - # Pinned for Python 3.9, same reason as the smoke job above. - runs-on: ubuntu-24.04 - needs: smoke # only publish once both OctoPrint generations pass - + name: Build & draft release + runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v7 + - uses: actions/checkout@v7 - - name: Set up Python - uses: actions/setup-python@v7 + - uses: actions/setup-python@v7 with: - python-version: "3.9" + python-version: "3.13" - - name: Resolve versions - id: ver - run: | - tag="${GITHUB_REF_NAME#v}" - # Normalize PEP 440: a git tag like v0.1.0-rc1 maps to 0.1.0rc1. - norm_tag="$(echo "$tag" | sed -E 's/-(a|b|c|rc|alpha|beta|dev|post)/\1/I')" - # Read the version straight from pyproject.toml. Avoid tomllib (only - # in the stdlib on Python 3.11+; this job runs on 3.9). The version is - # a simple top-level `version = "..."` line, so grep it out. - pkg="$(grep -E '^version[[:space:]]*=' pyproject.toml | head -1 | sed -E 's/.*=[[:space:]]*["'"'"']([^"'"'"']+)["'"'"'].*/\1/')" - if [ -z "$pkg" ]; then - echo "::error::Could not parse version from pyproject.toml" - exit 1 - fi - { - echo "tag=$tag" - echo "norm_tag=$norm_tag" - echo "pkg=$pkg" - } >> "$GITHUB_OUTPUT" - # Mark RC/alpha/beta/dev tags as prereleases. - if echo "$pkg" | grep -qiE '(a|b|c|rc|alpha|beta|dev)[0-9]*$'; then - echo "prerelease=true" >> "$GITHUB_OUTPUT" - else - echo "prerelease=false" >> "$GITHUB_OUTPUT" - fi - - - name: Verify tag matches pyproject version + - name: Install build tools run: | - if [ "${{ steps.ver.outputs.norm_tag }}" != "${{ steps.ver.outputs.pkg }}" ]; then - echo "::error::Tag ${{ steps.ver.outputs.tag }} (normalized ${{ steps.ver.outputs.norm_tag }}) does not match pyproject version ${{ steps.ver.outputs.pkg }}" - exit 1 - fi - echo "OK: tag matches pyproject version ${{ steps.ver.outputs.pkg }}" - - - name: Install build tooling - run: python -m pip install --upgrade pip build + python -m pip install --upgrade pip build packaging setuptools wheel + python -m pip install "OctoPrint>=2,<3" - name: Build sdist and wheel - run: python -m build - - - name: Build versionless source archive run: | - # Stable, version-independent filename so a single URL can always - # point at the newest release (see the rolling "latest" release below). - git archive --format=zip --prefix=OctoPrint-AutoConnectPlus/ \ - -o dist/OctoPrint-AutoConnectPlus-latest.zip "$GITHUB_REF_NAME" - - - name: Create GitHub Release (draft) + # The variable holds several arguments; split it on purpose. + # shellcheck disable=SC2086 + python -m build $BUILD_ARGS + + - name: Check version and stage files + id: stage + env: + TAG: ${{ github.ref_name }} + REPO: ${{ github.event.repository.name }} + run: | + python - <<'PY' + import os + import shutil + import sys + import tarfile + import zipfile + from pathlib import Path, PurePosixPath + + from packaging.version import InvalidVersion, Version + + + def fail(message): + print(f"::error::{message}") + sys.exit(1) + + + tag, repo, legacy = os.environ["TAG"], os.environ["REPO"], os.environ["LEGACY_ZIP"] + wheels, sdists = sorted(Path("dist").glob("*.whl")), sorted(Path("dist").glob("*.tar.gz")) + if len(wheels) != 1 or len(sdists) != 1: + fail(f"expected one wheel and one sdist, found {[p.name for p in wheels + sdists]}") + + with zipfile.ZipFile(wheels[0]) as whl: + meta = next(n for n in whl.namelist() if n.endswith(".dist-info/METADATA")) + lines = whl.read(meta).decode("utf-8").splitlines() + version = next(line.split(":", 1)[1].strip() for line in lines if line.startswith("Version:")) + + # v0.1.0-rc1 and 0.1.0rc1 name the same version. + try: + tag_version = Version(tag[1:] if tag[0] in "vV" else tag) + except InvalidVersion: + fail(f"tag {tag} is not a version") + if Version(version) != tag_version: + fail(f"tag {tag} does not match the package version {version}") + + # The sdist as a zip: OctoPrint's plugin manager installs it from a URL. + out = Path("release") + out.mkdir() + plugin_zip = out / f"{repo}-{version}.zip" + with tarfile.open(sdists[0]) as tar, zipfile.ZipFile(plugin_zip, "w", zipfile.ZIP_DEFLATED) as zf: + for member in tar.getmembers(): + path = PurePosixPath(member.name) + if member.isfile() and not path.is_absolute() and ".." not in path.parts: + info = zipfile.ZipInfo(str(path)) + info.external_attr = (member.mode & 0o777) << 16 + zf.writestr(info, tar.extractfile(member).read()) + with zipfile.ZipFile(plugin_zip) as zf: + parts = [PurePosixPath(n).parts for n in zf.namelist()] + if not any(len(p) == 3 and p[1].startswith("octoprint_") and p[2] == "__init__.py" for p in parts): + fail(f"{plugin_zip.name} does not contain the plugin package") + + for name in (f"{repo}-latest.zip", legacy): + if name: + shutil.copyfile(plugin_zip, out / name) + for path in wheels + sdists: + shutil.copy2(path, out) + + # a, b, rc and dev versions are published as pre-releases. + prerelease = str(tag_version.is_prerelease).lower() + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh: + fh.write(f"prerelease={prerelease}\n") + print(f"{tag}: version {version}, pre-release {prerelease}") + for path in sorted(out.iterdir()): + print(f" {path.name}: {path.stat().st_size} bytes") + PY + + - name: Create draft release uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 with: - name: ${{ github.ref_name }} - tag_name: ${{ github.ref_name }} - prerelease: ${{ steps.ver.outputs.prerelease }} - # Notes are grouped by PR label; the categories live in - # .github/release.yml. - generate_release_notes: true - # Always a draft: a release is published by hand once the notes and - # the attached artifacts have been eyeballed. Pushing a tag must - # never publish on its own. The rolling "latest" release below is - # NOT a draft on purpose -- see the comment there. draft: true - files: | - dist/*.whl - dist/*.tar.gz - dist/OctoPrint-AutoConnectPlus-latest.zip - - # Maintain a rolling "latest" release whose source-zip URL never changes: - # .../releases/download/latest/OctoPrint-AutoConnectPlus-latest.zip - # Unlike GitHub's /releases/latest, this is updated on EVERY tag push, - # so it tracks prereleases (rc/beta) too. - - name: Update rolling "latest" release - uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 - with: - name: Latest - tag_name: latest - # Deliberately NOT a draft, unlike the versioned release above: a - # draft's assets are not downloadable, which would break the stable - # URL below until someone published by hand. - draft: false - # Always a prerelease: GitHub's /releases/latest API (which the - # Software Update plugin's github_release check relies on) skips - # prereleases, so the rolling pointer with its non-PEP440 tag - # "latest" never shadows the real newest version there. - prerelease: true - body: | - Rolling pointer to the most recent release (**${{ github.ref_name }}**), - including prereleases. The asset URL below is stable across versions: - - ``` - https://github.com/${{ github.repository }}/releases/download/latest/OctoPrint-AutoConnectPlus-latest.zip - ``` - files: | - dist/OctoPrint-AutoConnectPlus-latest.zip + prerelease: ${{ steps.stage.outputs.prerelease }} + generate_release_notes: true + files: release/* diff --git a/README.md b/README.md index 2412277..20f493b 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,15 @@ plugins can compete to reconnect the same printer. Install via the OctoPrint Plugin Manager using a URL. -**Latest release** (recommended) — always points at the newest release, which may be a -prerelease (e.g. an `-rc`) until the first stable version is out: +**Latest release** (recommended) — always points at the newest stable release: ```text -https://github.com/ajimaru/OctoPrint-AutoConnectPlus/releases/download/latest/OctoPrint-AutoConnectPlus-latest.zip +https://github.com/Ajimaru/OctoPrint-AutoConnectPlus/releases/latest/download/OctoPrint-AutoConnectPlus-latest.zip ``` +Pre-releases and older versions are on the +[releases page](https://github.com/Ajimaru/OctoPrint-AutoConnectPlus/releases). + ## Configuration First set up and connect your printer once via OctoPrint's normal **connection @@ -147,9 +149,8 @@ existing languages. **Releases:** bump `version` in [`pyproject.toml`](pyproject.toml) (single source of truth — the plugin reads it from package metadata at runtime), then push a matching -tag such as `v0.2.0`. The release workflow verifies tag and version match, smoke-tests -the wheel against OctoPrint 1.x and 2.x, publishes the GitHub release and updates the -rolling `latest` release behind the stable install URL above. +tag such as `v0.2.0`. The release workflow checks that tag and version match and +creates a draft release with the wheel, sdist and plugin zip; publish it by hand. ## Credits