GitHub/Forgejo action to detect OS and runtime versions with semantic versioning outputs https://github.com/tcpipuk/detect-versions
Find a file
Tom Foster d0e72af7f3
All checks were successful
Test OS Detection Action / Test on fedora-latest (push) Successful in 3s
Test OS Detection Action / Test on fedora-rawhide (push) Successful in 3s
Test OS Detection Action / Test on ubuntu-latest (push) Successful in 3s
Test OS Detection Action / Test on ubuntu-previous (push) Successful in 3s
Test OS Detection Action / Test on ubuntu-rolling (push) Successful in 3s
feat(action): optimise metadata for GitHub Marketplace compatibility
Shorten description to 100 characters to meet GitHub Marketplace
requirements. Change icon from 'monitor' to 'search' to better
represent the detection and discovery functionality of the action.
2025-09-22 14:27:40 +01:00
.forgejo/workflows ci(workflow): streamline test workflow by removing redundant jobs 2025-09-22 13:49:24 +01:00
.markdownlint.yaml feat(action): implement Forgejo action to detect OS and runtime versions 2025-09-22 13:33:57 +01:00
.pre-commit-config.yaml feat(action): implement Forgejo action to detect OS and runtime versions 2025-09-22 13:33:57 +01:00
action.yml feat(action): optimise metadata for GitHub Marketplace compatibility 2025-09-22 14:27:40 +01:00
LICENSE feat(action): implement Forgejo action to detect OS and runtime versions 2025-09-22 13:33:57 +01:00
README.md docs(readme): update contributing section and remove unrelated actions 2025-09-22 14:14:15 +01:00

Detect OS and Runtime Versions Action

Detects your runner's operating system and installed tool versions, providing detailed outputs for conditional workflow steps.

Features

Works across Linux, macOS, and Windows runners using multiple fallback detection methods. The action identifies your OS distribution and architecture, then checks for installed development tools. Each tool provides semantic versioning components (major, minor, patch) so you can conditionally install updates only when needed.

Usage

Basic example

steps:
  - uses: https://code.forgejo.org/actions/checkout@v5

  - name: Detect OS and tools
    id: detect
    uses: https://git.tomfos.tr/actions/detect-versions@v1

  - name: Show detection results
    run: |
      echo "OS: ${{ steps.detect.outputs.name }}"
      echo "Version: ${{ steps.detect.outputs.version }}"
      echo "Architecture: ${{ steps.detect.outputs.arch }}"
      echo "Node.js: ${{ steps.detect.outputs.node_version }}"

Conditional tool installation

steps:
  - name: Detect OS and tools
    id: detect
    uses: https://git.tomfos.tr/actions/detect-versions@v1

  - name: Setup Node.js if missing or outdated
    if: steps.detect.outputs.node_major == '' || steps.detect.outputs.node_major < '20'
    uses: https://github.com/actions/setup-node@v5
    with:
      node-version: 22

Smart cache keys

steps:
  - name: Detect OS and tools
    id: detect
    uses: https://git.tomfos.tr/actions/detect-versions@v1

  - name: Cache dependencies
    uses: actions/cache@v3
    with:
      path: ~/.cache
      key: deps-${{ steps.detect.outputs.slug }}-${{ steps.detect.outputs.arch }}-${{ hashFiles('**/package-lock.json') }}
      restore-keys: |
        deps-${{ steps.detect.outputs.slug }}-${{ steps.detect.outputs.arch }}-
        deps-${{ steps.detect.outputs.slug }}-

Outputs

Operating system outputs

Output Description Example Values
name Operating system name Ubuntu, Debian, CentOS, macOS, Windows
version OS version number 22.04, 11, 13.2, 2022
slug Combined OS identifier Ubuntu-22.04, macOS-13, Windows-2022
arch System architecture x64, arm64, arm

Tool version outputs

Each tool provides {tool}_version (full version), {tool}_major, {tool}_minor, and {tool}_patch outputs:

  • cmake - CMake build system (e.g. 3.28.1)
  • docker - Docker container platform (e.g. 24.0.7)
  • git - Git version control (e.g. 2.43.0)
  • go - Go programming language (e.g. 1.21.5)
  • java - Java runtime (e.g. 21.0.1 or 1.8.0_392)
  • node - Node.js JavaScript runtime (e.g. 20.11.1)
  • python - Python interpreter (e.g. 3.11.5)
  • rust - Rust programming language (e.g. 1.75.0)

Returns empty strings for tools that aren't installed.

Supported platforms

Supports Linux distributions (Ubuntu, Debian, CentOS, RHEL, Fedora), macOS 11+, and Windows Server 2019/2022. Uses multiple detection methods starting with the most reliable - lsb_release on Linux, sw_vers on macOS, and systeminfo on Windows, with appropriate fallbacks.

Example outputs by platform

Output Ubuntu macOS Windows
name Ubuntu macOS Windows
version 22.04 13.2 2022
slug Ubuntu-22.04 macOS-13.2 Windows-2022
arch x64 x64 x64

Contributing

Issues and pull requests can be submitted via the GitHub mirror at https://github.com/tcpipuk/detect-versions

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.