From b936dbac6e64f4a5915149365306c81482744ecc Mon Sep 17 00:00:00 2001 From: Ajimaru Date: Wed, 2 Dec 2026 16:51:43 +0100 Subject: [PATCH 1/2] chore: remove obsolete release workflow configuration --- .github/workflows/release.yml | 155 ---------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 5e913ac..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,155 +0,0 @@ -name: Release - -on: - push: - tags: ["v*", "[0-9]*"] - -permissions: - contents: write - -jobs: - release: - name: Build & release - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v7 - - - name: Set up Python - uses: actions/setup-python@v7 - with: - python-version: "3.12" - cache: pip - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install build - - - name: Build sdist and wheel - run: python -m build - - - name: Validate paths (prevent directory traversal) - run: | - for f in dist/*; do - rel="$(realpath --relative-to="$(pwd)" "$f")" - case "$rel" in - .*) echo "Suspicious path: $f ($rel)"; exit 1 ;; - esac - done - - - name: Determine prerelease - id: prerelease - run: | - TAG="${{ github.ref_name }}" - TAG_LOWER="$(printf '%s' "$TAG" | tr '[:upper:]' '[:lower:]')" - # Prerelease = a/b/rc/dev segment in the VERSION part of the tag - # (PEP 440 style, digit or separator before it, e.g. 0.2.2rc1 or - # 0.2.2.dev6). The match must end at the tag end or at the local - # part ("+hash"), so a commit hash that happens to end in e.g. - # "b1" can never flip the detection. - if echo "$TAG_LOWER" | grep -qE '(^|[-.0-9])(a|b|rc|dev)([.-]?[0-9]+)?($|\+)'; then - echo "is_prerelease=true" >> "$GITHUB_OUTPUT" - else - echo "is_prerelease=false" >> "$GITHUB_OUTPUT" - fi - - - name: Stage release artifacts - shell: bash - run: | - set -euo pipefail - mkdir -p release_zips - - # Keep the wheel's original, PEP 427-compliant filename - # ({name}-{version}-{pytag}-{abitag}-{platformtag}.whl). pip rejects - # any renamed wheel ("wrong number of parts"), so it must not be - # aliased — both the OctoPrint plugin manager and pip parse the name. - cp dist/*.whl dist/*.tar.gz release_zips/ - - # Also publish a source .zip (versioned + a stable -latest.zip). A zip - # has no strict filename parser, so the OctoPrint plugin manager can - # install it directly from a fixed "…-latest.zip" URL. Build it from - # the sdist tarball rather than the working tree so it matches the - # released source exactly. - version="${GITHUB_REF_NAME#v}" - zip_versioned="release_zips/OctoPrint-LogMonitor-${version}.zip" - zip_latest="release_zips/OctoPrint-LogMonitor-latest.zip" - - shopt -s nullglob - sdist_candidates=(dist/*"${version}".tar.gz) - if (( ${#sdist_candidates[@]} != 1 )); then - echo "Expected exactly one sdist tarball matching version ${version}, found ${#sdist_candidates[@]}" >&2 - ls -la dist >&2 || true - exit 1 - fi - sdist="${sdist_candidates[0]}" - - python - "$sdist" "$zip_versioned" <<'PY' - import sys - import tarfile - import zipfile - from pathlib import Path, PurePosixPath - - tar_path = Path(sys.argv[1]) - zip_path = Path(sys.argv[2]) - zip_path.parent.mkdir(parents=True, exist_ok=True) - - with tarfile.open(tar_path, "r:gz") as tf, zipfile.ZipFile( - zip_path, "w", compression=zipfile.ZIP_DEFLATED - ) as zf: - for member in tf.getmembers(): - if not member.isfile(): - continue - - # Defensive: never let a tar member become a path-traversal - # entry in the zip. Tar archives always use POSIX paths. - member_path = PurePosixPath(member.name) - if ( - member_path.is_absolute() - or ".." in member_path.parts - or ":" in member.name - or member.name.startswith("\\") - ): - continue - - extracted = tf.extractfile(member) - if extracted is None: - continue - - zi = zipfile.ZipInfo(str(member_path)) - zi.external_attr = (member.mode & 0o777) << 16 - zf.writestr(zi, extracted.read()) - PY - - cp -f "$zip_versioned" "$zip_latest" - - - name: Upload artifacts - uses: actions/upload-artifact@v7 - with: - name: dist - path: release_zips/* - - - name: Create GitHub release (draft) - uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 - with: - files: | - release_zips/* - # 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. - draft: true - prerelease: ${{ steps.prerelease.outputs.is_prerelease }} - - # Optional: Publish to PyPI - # - # 1) Create a repository secret named PYPI_API_TOKEN - # 2) Uncomment the step below - # - # - name: Publish to PyPI - # uses: pypa/gh-action-pypi-publish@release/v1 - # with: - # password: ${{ secrets.PYPI_API_TOKEN }} From ff40afed9cf7edd134ad7ce47bdeaabc681672e2 Mon Sep 17 00:00:00 2001 From: Ajimaru Date: Wed, 2 Dec 2026 16:51:49 +0100 Subject: [PATCH 2/2] chore: add release workflow for automated plugin builds and draft releases --- .github/workflows/release.yaml | 122 +++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..65b9811 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +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*", "[0-9]*"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +permissions: + contents: write + +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 & draft release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-python@v7 + with: + python-version: "3.13" + + - name: Install build tools + run: | + python -m pip install --upgrade pip build packaging setuptools wheel + python -m pip install "OctoPrint>=2,<3" + + - name: Build sdist and wheel + run: | + # 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: + draft: true + prerelease: ${{ steps.stage.outputs.prerelease }} + generate_release_notes: true + files: release/*