lastversion

repository·master·Indexed 19 days ago

https://github.com/dvershinin/lastversion

A command-line utility and Python library designed to find the latest stable version of a project from sources like GitHub, GitLab, and PyPI. It handles inconsistent version tagging, filters pre-releases, and provides functionality to download or extract the latest releases, install RPM or AppImage packages, and compare semantic versions for automated build systems.

Tokens
17.8K
Snippets
71
Records
84
Agent score
63%

What's inside lastversion

  1. Overview of lastversion

    master

    lastversion is a lightweight command-line tool designed to query the latest version number and related information (such as download links) for various software projects. It is primarily intended for use in automation scripts, such as continuous integration (CI) or automated update processes.

    It supports retrieving version information from:

    • GitHub
    • GitLab
    • BitBucket
    • PyPI
    • Mercurial
    • SourceForge
    • Wikipedia
    • Any website that publishes software via RSS/ATOM feeds.
  2. Filter releases in multi-project repositories

    master

    In repositories that host multiple components with different version lines, use --only or --exclude to target specific components based on their release tags.

    • --only REGEX: Only consider releases containing this text.
    • --exclude REGEX: Only consider releases NOT containing this text.
    • Regex Tilde: Prepend a tilde ~ to the regex for advanced matching (e.g., ~-po.-).
    # Only consider releases tagged with 'chart'
    lastversion --only chart https://github.com/lastversion-test-repos/autoscaler
    
    # Exclude releases tagged with 'chart'
    lastversion --exclude chart https://github.com/lastversion-test-repos/autoscaler
  3. Use the lastversion hosted API

    master
    If you prefer a no-install solution, you can access lastversion via a hosted API on RapidAPI. This allows you to fetch version, assets, or full release details via JSON requests from any environment (CI/CD, serverless, or frontend) without managing the library or API tokens yourself.
  4. Use lastversion to find the latest software release

    master

    The core functionality of lastversion is to find the latest version of a software project using a repository URL or a repository identifier (owner/name). It supports various platforms including GitHub, GitLab, BitBucket, PyPI, and even Wikipedia-based OS version lookups.

    Basic Usage Patterns:

    • By URL: lastversion https://github.com/owner/repo
    • By Identifier: lastversion owner/repo
    • By Name (Search API): lastversion project-name (e.g., lastversion linux or lastversion wordpress)
    • Special Value self: lastversion self finds the latest version of lastversion itself.
    lastversion https://github.com/gperftools/gperftools
    # or
    lastversion gperftools/gperftools
  5. Use lastversion in shell scripts

    master

    The lastversion command is designed for scripting, providing useful exit codes and comparison logic.

    Version Comparison: Use the -gt VER flag to output the latest version only if it is newer than the provided version. This behaves like a 'greater than' comparison.

    # Returns the newer version between 1.2.3 and 1.2.4
    lastversion 1.2.3 -gt 1.2.4

    Checking for Updates: You can use the exit status to trigger workflows (like builds) when a newer version is detected.

    CURRENTLY_BUILT_VER=1.2.3
    LASTVER=$(lastversion repo/owner -gt ${CURRENTLY_BUILT_VER})
    if [[ $? -eq 0 ]]; then
      # A newer version was found, trigger build...
    fi

    Exit Codes:

    • 0: Success (a version was found/returned).
    • 1: Repository does not exist or has no releases.
    • 2: No version was found that is newer than the version specified with -gt.
    • 3: All results were filtered out by the --filter regex.
    LASTVER=$(lastversion repo/owner -gt ${CURRENTLY_BUILT_VER})
    if [[ $? -eq 0 ]]; then
      echo "New version detected: $LASTVER"
    fi
  6. Install lastversion

    master

    You can install lastversion using pip for most systems, or via yum for RPM-based distributions like CentOS, RHEL, Fedora, or Amazon Linux.

    pip install lastversion

    Using yum (RPM-based systems)

    For CentOS/RHEL 7, 8, 9 (including AlmaLinux and Rocky Linux), Amazon Linux 2, Amazon Linux 2023, or Fedora:

    sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
    sudo yum -y install lastversion
    pip install lastversion
  7. Install RPM packages automatically

    master

    On systems using yum or dnf (like CentOS, RHEL, or Amazon Linux 2), you can use lastversion to find and install the latest .rpm asset for a project.

    Command: sudo lastversion install <package_name>

    Example: sudo lastversion install mailspring finds the latest .rpm for MailSpring and passes it to the system package manager.

    Automation: You can automate updates via cron. For example, to check for updates daily and install them automatically: @daily /usr/bin/lastversion install mailspring -y 2>/dev/null

    sudo lastversion install mailspring
  8. Prepare RPM .spec files for GitHub projects

    master

    To allow lastversion to automatically detect GitHub releases and update your .spec file with the correct Version:, lastversion_tag, and lastversion_dir macros, you must define specific globals in your spec file header.

    If your package Name: matches the GitHub repository name, you only need to define %global upstream_github <repository owner>. If they differ, you must also define %global upstream_name <github_repo_name>.

    Ensure your URL: and Source0: tags use these macros so lastversion can correctly resolve the archive path. Finally, use the %{lastversion_dir} macro in your %prep section to handle varying directory names in upstream tarballs.

    %global upstream_github google
    %global upstream_name brotli
    
    Name:           my-brotli-package
    URL:            https://github.com/%{upstream_github}/%{upstream_name}
    Source0:        %{url}/archive/%{lastversion_tag}/%{upstream_name}-%{lastversion_tag}.tar.gz
    
    %prep
    %autosetup -n %{lastversion_dir}
  9. Filter assets by regex or presence

    master

    By default, lastversion filters assets based on the host OS (e.g., it won't suggest .exe files on Linux). You can override this behavior using --filter or --having-asset.

    • --filter REGEX: Overrides OS-based filtering. Use a regular expression to match specific asset types. To disable all filtering and show all assets, use a regex that matches everything.
    • --having-asset [ASSET]: Only considers releases that contain an asset matching the provided regular expression.

    Examples:

    • Find Windows assets on Linux: lastversion --assets --filter win REPO
    • Find macOS .dmg files: lastversion telegramdesktop/tdesktop --having-asset "\.dmg$"
    lastversion --assets --filter win REPO
  10. Upload lastversion to PyPI or Test PyPI

    master

    Once the source distribution has been created using python setup.py sdist, you can use twine to upload the package to PyPI.

    Use the --repository-url flag to target Test PyPI for verification before publishing to the production PyPI repository.

    # Upload to Test PyPI
    twine upload --repository-url https://test.pypi.org/legacy/ dist/*
    
    # Upload to the real PyPI
    twine upload dist/*
  11. Download or extract the latest release

    master

    Use the download or extract commands to fetch files from the latest release.

    • Download source: lastversion download <repo> (downloads the source archive by default).
    • Download with custom filename: Use -o or --download (works for sources).
    • Extract directly: lastversion extract <repo> fetches and extracts the latest release's file into the current directory.
    • Pipe to other tools: You can use --format assets to get a list of URLs for tools like wget.

    To force downloading assets instead of source, use the --assets flag.

    # Download the most recent Mautic source release
    lastversion download mautic/mautic
    
    # Download and rename source
    lastversion download mautic/mautic -o mautic.tar.gz
    
    # Extract directly
    lastversion extract wordpress
    
    # Pipe asset URLs to wget
    wget $(lastversion --assets mautic/mautic)