Streamlining Versioning on Self-Hosted Runners: A Boost for Software Productivity Metrics

In the world of continuous integration and delivery, managing semantic versioning is crucial for maintaining clear release cycles and tracking changes. A recent discussion on GitHub Community, initiated by Rod-at-DOH, highlighted a common challenge: how to effectively iterate over all repository tags and releases from a GitHub self-hosted runner to calculate the next semantic version. This process is a cornerstone of efficient software productivity metrics, enabling teams to automate and streamline their release management.

An illustration depicting a self-hosted runner processing version tags from a GitHub Actions workflow for automated release management.
An illustration depicting a self-hosted runner processing version tags from a GitHub Actions workflow for automated release management.

The Challenge: Calculating Next Semantic Versions on Self-Hosted Runners

Rod-at-DOH's query centered on the ability of a self-hosted runner to access and process all tags and releases to determine the subsequent semantic version number within a GitHub Action. This is a vital step for automated release pipelines, ensuring consistency and accuracy without manual intervention.

A dashboard displaying software productivity metrics, with Git tags and version numbers indicating efficient release management and development.
A dashboard displaying software productivity metrics, with Git tags and version numbers indicating efficient release management and development.

Solutions for Efficient Versioning on Self-Hosted Runners

The community provided several robust solutions, leveraging the unique advantages of self-hosted runners, particularly their direct access to the underlying file system and Git binaries.

1. The Git Native Approach (Recommended for Control)

As Radi410 explained, the most reliable method involves using Git directly. This avoids API rate limits and leverages the runner's local environment. The crucial step is to ensure your actions/checkout step fetches the entire history, not just the latest commit, by setting fetch-depth: 0.

steps:
  - name: Checkout code
    uses: actions/checkout@v4
    with:
      fetch-depth: 0 # This fetches all tags and history

  - name: List and Calculate Version
    run: |
      # Get all tags, sorted by version number (highest first)
      tags=$(git tag --list 'v*' --sort=-v:refname)
      # Get the latest tag
      latest_tag=$(echo "$tags" | head -n 1)
      echo "The latest version is: $latest_tag"
      # Logic to calculate your next version (e.g., incrementing patch)
      # You can use a bash script or a Python utility here.

This method provides granular control and is highly efficient, especially for self-hosted runners which often have persistent storage, as noted by Radi410 regarding Windows runners.

2. Leveraging GitHub CLI (For API-Driven Tag Retrieval)

If fetching the entire Git history is undesirable due to disk space concerns, the GitHub CLI (gh) offers an excellent alternative. It's usually pre-installed or easily added to runners and interacts with the GitHub API to fetch release information.

# This fetches the 10 most recent releases via API
gh release list --limit 10

This approach is suitable when you only need recent tags or releases and prefer not to clone the full repository history.

3. Utilizing Pre-built Marketplace Actions (For Simplicity and Robustness)

For those who prefer not to write custom scripting or regex for semantic version parsing, pre-built GitHub Marketplace actions offer a streamlined solution. Radi410 specifically recommended paulhatch/semantic-version for its robustness in handling regex and sorting automatically.

- name: Get Next Version
  id: tagger
  uses: paulhatch/semantic-version@v5.4.0
  with:
    tag_prefix: "v"
    major_pattern: "(MAJOR)"
    minor_pattern: "(MINOR)"
    version_format: "${major}.${minor}.${patch}"

While some "purists" might shy away from external dependencies, this action can significantly boost software productivity metrics by simplifying complex versioning logic into a reusable component.

Key Takeaways for Enhanced Software Productivity Metrics

Mohul2005 succinctly summarized that while a self-hosted runner doesn’t store tags or releases itself, it can fetch and iterate over them during a workflow using Git for tags and the GitHub API/CLI for releases. The flexibility and direct access afforded by self-hosted runners make them ideal environments for implementing sophisticated versioning strategies. By adopting these methods, development teams can significantly improve their release automation, contributing directly to better software productivity metrics and more predictable project management.

Track, Analyze and Optimize Your Software DeveEx!

Effortlessly implement gamification, pre-generated performance reviews and retrospective, work quality analytics, alerts on top of your code repository activity

 Install GitHub App to Start
devActivity Screenshot